Skip to content

Commit

Permalink
Reduce indentation in setup_photoion_luts()
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Aug 30, 2024
1 parent 1ee0c17 commit 3fb6d60
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
5 changes: 3 additions & 2 deletions input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,9 @@ void setup_phixs_list() {
#ifdef MPI_ON
MPI_Barrier(MPI_COMM_WORLD);
#endif

setup_photoion_luts();

for (int i = 0; i < globals::nbfcontinua; i++) {
const int element = nonconstallcont[i].element;
const int ion = nonconstallcont[i].ion;
Expand All @@ -1463,8 +1466,6 @@ void setup_phixs_list() {
}
globals::allcont = nonconstallcont;
nonconstallcont = nullptr;

setup_photoion_luts();
}

void read_atomicdata() {
Expand Down
71 changes: 34 additions & 37 deletions ratecoeff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,60 +851,57 @@ auto get_nlevels_important(const int modelgridindex, const int element, const in
} // anonymous namespace

void setup_photoion_luts() {
assert_always(globals::nbfcontinua > 0);
size_t mem_usage_photoionluts = 2 * TABLESIZE * globals::nbfcontinua * sizeof(double);

if (globals::nbfcontinua > 0) {
#ifdef MPI_ON
MPI_Win win = MPI_WIN_NULL;
MPI_Aint size =
(globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
int disp_unit = sizeof(double);
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &spontrecombcoeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &spontrecombcoeffs) == MPI_SUCCESS);
MPI_Win win = MPI_WIN_NULL;
MPI_Aint size =
(globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
int disp_unit = sizeof(double);
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &spontrecombcoeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &spontrecombcoeffs) == MPI_SUCCESS);
#else
spontrecombcoeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
spontrecombcoeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
#endif
assert_always(spontrecombcoeffs != nullptr);
assert_always(spontrecombcoeffs != nullptr);

if constexpr (USE_LUT_PHOTOION) {
if constexpr (USE_LUT_PHOTOION) {
#ifdef MPI_ON
size =
(globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &corrphotoioncoeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &corrphotoioncoeffs) == MPI_SUCCESS);
size = (globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &corrphotoioncoeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &corrphotoioncoeffs) == MPI_SUCCESS);
#else
corrphotoioncoeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
corrphotoioncoeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
#endif
assert_always(corrphotoioncoeffs != nullptr);
mem_usage_photoionluts += TABLESIZE * globals::nbfcontinua * sizeof(double);
}
assert_always(corrphotoioncoeffs != nullptr);
mem_usage_photoionluts += TABLESIZE * globals::nbfcontinua * sizeof(double);
}

if constexpr (USE_LUT_BFHEATING) {
if constexpr (USE_LUT_BFHEATING) {
#ifdef MPI_ON
size =
(globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node,
&globals::bfheating_coeff, &win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &globals::bfheating_coeff) == MPI_SUCCESS);
size = (globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node,
&globals::bfheating_coeff, &win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &globals::bfheating_coeff) == MPI_SUCCESS);
#else
globals::bfheating_coeff = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
globals::bfheating_coeff = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
#endif
assert_always(globals::bfheating_coeff != nullptr);
mem_usage_photoionluts += TABLESIZE * globals::nbfcontinua * sizeof(double);
}
assert_always(globals::bfheating_coeff != nullptr);
mem_usage_photoionluts += TABLESIZE * globals::nbfcontinua * sizeof(double);
}

#ifdef MPI_ON
size = (globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &bfcooling_coeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &bfcooling_coeffs) == MPI_SUCCESS);
size = (globals::rank_in_node == 0) ? TABLESIZE * globals::nbfcontinua * static_cast<MPI_Aint>(sizeof(double)) : 0;
assert_always(MPI_Win_allocate_shared(size, disp_unit, MPI_INFO_NULL, globals::mpi_comm_node, &bfcooling_coeffs,
&win) == MPI_SUCCESS);
assert_always(MPI_Win_shared_query(win, 0, &size, &disp_unit, &bfcooling_coeffs) == MPI_SUCCESS);
#else
bfcooling_coeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
bfcooling_coeffs = static_cast<double *>(malloc(TABLESIZE * globals::nbfcontinua * sizeof(double)));
#endif
assert_always(bfcooling_coeffs != nullptr);
}
assert_always(bfcooling_coeffs != nullptr);

printout(
"[info] mem_usage: lookup tables derived from photoionisation (spontrecombcoeff, bfcooling and "
Expand Down

0 comments on commit 3fb6d60

Please sign in to comment.