Skip to content

Commit

Permalink
rename "load_balance" to "is_load_balance"
Browse files Browse the repository at this point in the history
  • Loading branch information
cguzman95 committed Nov 19, 2024
1 parent e91e7fa commit ab647e3
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/camp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ typedef struct {

#ifdef CAMP_USE_GPU
int iters_load_balance; // Iterations to calculate the average load balance
int last_short_gpu; // Flag to indicate that solving on the GPU takes less
// time than the CPU
int load_balance; // Flag to balance the load between CPU and GPU. 0 to fixed
// load balance during run time, while 1 to automatic load
// balance
int last_short_gpu; // Flag to indicate that solving on the GPU takes less
// time than the CPU
int is_load_balance; // Flag to balance the load between CPU and GPU. 0 to
// fixed load balance during run time, while 1 to
// automatic load balance
#ifdef DEBUG_SOLVER_FAILURES
int *flags; // Error flags from solving failures
#endif
Expand Down
18 changes: 9 additions & 9 deletions src/camp_core.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,11 @@ end function spec_state_id
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!> Initialize the solver
subroutine solver_initialize(this, load_gpu, is_reset_jac, load_balance)
subroutine solver_initialize(this, load_gpu, is_reset_jac, is_load_balance)
class(camp_core_t), intent(inout) :: this
integer, intent(in), optional :: load_gpu, is_reset_jac, load_balance
integer, intent(in), optional :: load_gpu, is_reset_jac, is_load_balance
type(string_t), allocatable :: spec_names(:)
integer :: i_spec, n_gas_spec, load_gpu1, is_reset_jac1, load_balance1
integer :: i_spec, n_gas_spec, load_gpu1, is_reset_jac1, is_load_balance1
call assert_msg(662920365, .not.this%solver_is_initialized, &
"Attempting to initialize the solver twice.")

Expand All @@ -1172,9 +1172,9 @@ subroutine solver_initialize(this, load_gpu, is_reset_jac, load_balance)
if (present(is_reset_jac)) then
is_reset_jac1=is_reset_jac
end if
load_balance1=1
if (present(load_balance)) then
load_balance1=load_balance
is_load_balance1=1
if (present(is_load_balance)) then
is_load_balance1=is_load_balance
end if

! Set up either two solvers (gas and aerosol) or one solver (combined)
Expand All @@ -1201,7 +1201,7 @@ subroutine solver_initialize(this, load_gpu, is_reset_jac, load_balance)
GAS_RXN, & ! Reaction phase
this%n_cells, & ! # of cells computed simultaneosly
spec_names, & ! Species names
load_gpu1, is_reset_jac1, load_balance1 &
load_gpu1, is_reset_jac1, is_load_balance1 &
)
call this%solver_data_aero%initialize( &
this%var_type, & ! State array variable types
Expand All @@ -1213,7 +1213,7 @@ subroutine solver_initialize(this, load_gpu, is_reset_jac, load_balance)
AERO_RXN, & ! Reaction phase
this%n_cells, & ! # of cells computed simultaneosly
spec_names, & ! Species names
load_gpu1, is_reset_jac1, load_balance1 &
load_gpu1, is_reset_jac1, is_load_balance1 &
)
else

Expand All @@ -1236,7 +1236,7 @@ subroutine solver_initialize(this, load_gpu, is_reset_jac, load_balance)
GAS_AERO_RXN, & ! Reaction phase
this%n_cells, & ! # of cells computed simultaneosly
spec_names, & ! Species names
load_gpu1, is_reset_jac1, load_balance1 &
load_gpu1, is_reset_jac1, is_load_balance1 &
)
end if

Expand Down
8 changes: 4 additions & 4 deletions src/camp_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
re-initialized. It may accelerate solving. Enable reset when the inputs are
very different between each other or to compare with the GPU version. Avoid
reset when the inputs are similar like CAMP-MONARCH.
* \param load_balance Flag to balance the load between CPU and GPU. 0 to fixed
load balance during run time, while 1 to automatic load balance
* \param is_load_balance Flag to balance the load between CPU and GPU. 0 to
fixed load balance during run time, while 1 to automatic load balance
* \return Pointer to the new SolverData object
*/
void *solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn,
Expand All @@ -108,7 +108,7 @@ void *solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn,
int n_aero_rep_float_param, int n_aero_rep_env_param,
int n_sub_model, int n_sub_model_int_param,
int n_sub_model_float_param, int n_sub_model_env_param,
int load_gpu, int is_reset_jac, int load_balance) {
int load_gpu, int is_reset_jac, int is_load_balance) {
// Create the SolverData object
SolverData *sd = (SolverData *)malloc(sizeof(SolverData));
if (sd == NULL) {
Expand Down Expand Up @@ -137,7 +137,7 @@ void *solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn,

sd->load_gpu = (double)load_gpu;
sd->is_reset_jac = is_reset_jac;
sd->load_balance = load_balance;
sd->is_load_balance = is_load_balance;
sd->model_data.n_cells = n_cells;

// Add the variable types to the solver data
Expand Down
2 changes: 1 addition & 1 deletion src/camp_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void *solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn,
int n_aero_rep_float_param, int n_aero_rep_env_param,
int n_sub_model, int n_sub_model_int_param,
int n_sub_model_float_param, int n_sub_model_env_param,
int load_gpu, int is_reset_jac, int load_balance);
int load_gpu, int is_reset_jac, int is_load_balance);
void solver_set_spec_name(void *solver_data, char *spec_name,
int size_spec_name, int i);
void solver_initialize(void *solver_data, double *abs_tol, double rel_tol);
Expand Down
10 changes: 5 additions & 5 deletions src/camp_solver_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type(c_ptr) function solver_new(n_state_var, n_cells, var_type, &
n_aero_rep_int_param, n_aero_rep_float_param, &
n_aero_rep_env_param, n_sub_model, n_sub_model_int_param,&
n_sub_model_float_param, n_sub_model_env_param,&
load_gpu, is_reset_jac, load_balance) bind (c)
load_gpu, is_reset_jac, is_load_balance) bind (c)
use iso_c_binding
!> Number of variables on the state array per grid cell
!! (including const, PSSA, etc.)
Expand Down Expand Up @@ -93,7 +93,7 @@ type(c_ptr) function solver_new(n_state_var, n_cells, var_type, &
integer(kind=c_int), value :: n_sub_model_env_param
integer(kind=c_int), value :: load_gpu
integer(kind=c_int), value :: is_reset_jac
integer(kind=c_int), value :: load_balance
integer(kind=c_int), value :: is_load_balance
end function solver_new

!> Set specie name
Expand Down Expand Up @@ -451,7 +451,7 @@ end function constructor
!> Initialize the solver
subroutine initialize(this, var_type, abs_tol, mechanisms, aero_phases, &
aero_reps, sub_models, rxn_phase, n_cells,&
spec_names, load_gpu, is_reset_jac, load_balance)
spec_names, load_gpu, is_reset_jac, is_load_balance)

!> Solver data
class(camp_solver_data_t), intent(inout) :: this
Expand All @@ -470,7 +470,7 @@ subroutine initialize(this, var_type, abs_tol, mechanisms, aero_phases, &
type(aero_rep_data_ptr), pointer, intent(in) :: aero_reps(:)
!> Sub models to include
type(sub_model_data_ptr), pointer, intent(in) :: sub_models(:)
integer, intent(in) :: load_gpu, is_reset_jac, load_balance
integer, intent(in) :: load_gpu, is_reset_jac, is_load_balance
!> Reactions phase to solve -- gas, aerosol, or both (default)
!! Use parameters in camp_rxn_data to specify phase:
!! GAS_RXN, AERO_RXN, GAS_AERO_RXN
Expand Down Expand Up @@ -654,7 +654,7 @@ subroutine initialize(this, var_type, abs_tol, mechanisms, aero_phases, &
n_sub_model_int_param, & ! # of sub model int params
n_sub_model_float_param, & ! # of sub model real params
n_sub_model_env_param, & ! # of sub model env params
load_gpu, is_reset_jac, load_balance &
load_gpu, is_reset_jac, is_load_balance &
)

! Add all the condensed reaction data to the solver data block for
Expand Down
12 changes: 6 additions & 6 deletions src/cuda/cvode_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int cudaCVode(void *cvode_mem, double t_final, N_Vector yout, SolverData *sd,
cudaStream_t stream; // Variable for asynchronous execution of the GPU
cudaStreamCreate(&stream);
#ifdef LOAD_BALANCE
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
cudaEventRecord(sd->startGPU, stream); // Start GPU timer
}
#endif
Expand All @@ -64,7 +64,7 @@ int cudaCVode(void *cvode_mem, double t_final, N_Vector yout, SolverData *sd,
cvodeRun(t_initial, mGPU, n_cells, md->n_per_cell_dep_var,
stream); // Asynchronous
#ifdef LOAD_BALANCE
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
cudaEventRecord(sd->stopGPU, stream); // End GPU timer
}
#endif
Expand All @@ -75,7 +75,7 @@ int cudaCVode(void *cvode_mem, double t_final, N_Vector yout, SolverData *sd,
#endif
#ifdef LOAD_BALANCE
double startTime;
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
startTime = MPI_Wtime();
}
#endif
Expand Down Expand Up @@ -142,15 +142,15 @@ int cudaCVode(void *cvode_mem, double t_final, N_Vector yout, SolverData *sd,
md->rxn_env_data = rxn_env_data;
#ifdef LOAD_BALANCE
double timeCPU;
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
timeCPU = (MPI_Wtime() - startTime);
}
#endif
#ifdef TRACE_CPUGPU
nvtxRangePop(); // End of profiling trace
#endif
#ifdef LOAD_BALANCE
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
// Start synchronization timer between CPU and GPU
cudaEventRecord(sd->startGPUSync, stream);
}
Expand All @@ -170,7 +170,7 @@ int cudaCVode(void *cvode_mem, double t_final, N_Vector yout, SolverData *sd,
#ifdef LOAD_BALANCE
// Balance load between CPU and GPU, changing the number of cells solved on
// both architectures. Method explained on C. Guzman PhD Thesis - Chapter 6
if (sd->load_balance == 1) {
if (sd->is_load_balance == 1) {
cudaEventRecord(sd->stopGPUSync, stream); // End synchronization timer
cudaEventSynchronize(sd->stopGPUSync);
cudaEventSynchronize(sd->stopGPU);
Expand Down
4 changes: 2 additions & 2 deletions test/monarch/TestMonarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
def run_testMonarch():
conf = TestMonarch()
conf.timeSteps = 10 # Minimum value of 1
conf.loads_gpu = [100] # e.g. 100: GPU-Only 1-99: CPU+GPU
conf.load_balance = 0 # 0: Fixed, 1: Automatic in runtime
conf.loads_gpu = [100] # e.g. Percentage; 0: CPU only, 100: GPU only
conf.is_load_balance = 1 # 0: Fixed, 1: Automatic in runtime
conf.cells = [100] # Minimum value of 1
conf.mpiProcessesCaseBase = 1 # Minimum value of 1
conf.caseBase = "CPU" # CPU or GPU
Expand Down
6 changes: 3 additions & 3 deletions test/monarch/camp_monarch_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ module camp_monarch_interface


function constructor(camp_config_file, output_file_title, &
starting_id, ending_id, n_cells, load_gpu, load_balance) result (this)
starting_id, ending_id, n_cells, load_gpu, is_load_balance) result (this)
type(camp_monarch_interface_t), pointer :: this
character(len=:), allocatable, optional :: camp_config_file
character(len=*), intent(in):: output_file_title
integer :: starting_id
integer :: ending_id
integer :: n_cells
integer, intent(in) :: load_gpu, load_balance
integer, intent(in) :: load_gpu, is_load_balance
type(camp_solver_data_t), pointer :: camp_solver_data
character, allocatable :: buffer(:)
integer(kind=i_kind) :: pos, pack_size, size
Expand Down Expand Up @@ -224,7 +224,7 @@ function constructor(camp_config_file, output_file_title, &
! use values from previous cell.
!By default is_reset_jac is set to 0 because it accelerates MONARCH case
! (and probably more cases).
call this%camp_core%solver_initialize(load_gpu, is_reset_jac, load_balance)
call this%camp_core%solver_initialize(load_gpu, is_reset_jac, is_load_balance)
this%camp_state => this%camp_core%new_state()
allocate(this%offset_photo_rates_cells(this%n_cells))
this%offset_photo_rates_cells(:) = 0.
Expand Down
2 changes: 1 addition & 1 deletion test/monarch/mainMonarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def run(conf):
exec_str += "extrae/trace_f.sh "
if conf.profileValgrind is not None:
exec_str += "valgrind --tool=cachegrind "
path_exec = "../../build/binned_gpu"
path_exec = "../../build/mock_monarch"
exec_str += path_exec
print("exec_str:", exec_str)
print(
Expand Down
6 changes: 3 additions & 3 deletions test/monarch/mock_monarch.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ program mock_monarch_t
type(json_core) :: json
character(len=:), allocatable :: export_path
character(len=128) :: i_str
integer :: id, n_cells_monarch, load_gpu, load_balance
integer :: id, n_cells_monarch, load_gpu, is_load_balance

call camp_mpi_init()
I_W=1
Expand All @@ -73,7 +73,7 @@ program mock_monarch_t
else
n_cells = n_cells_monarch
end if
call jfile%get('load_balance',load_balance)
call jfile%get('is_load_balance',is_load_balance)
call jfile%get('timeSteps',NUM_TIME_STEP)
call jfile%get('timeStepsDt',TIME_STEP)
NUM_WE_CELLS = I_E-I_W+1
Expand All @@ -91,7 +91,7 @@ program mock_monarch_t
allocate(conv(NUM_WE_CELLS, NUM_SN_CELLS, NUM_VERT_CELLS))

camp_interface => camp_monarch_interface_t(camp_input_file, output_file_title, &
START_CAMP_ID, END_CAMP_ID, n_cells, load_gpu, load_balance)
START_CAMP_ID, END_CAMP_ID, n_cells, load_gpu, is_load_balance)
camp_interface%camp_state%state_var(:) = 0.0
species_conc(:,:,:,:) = 0.0
air_density(:,:,:) = 1.225
Expand Down

0 comments on commit ab647e3

Please sign in to comment.