Skip to content

Commit

Permalink
Simplify update_grid loops
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Nov 20, 2024
1 parent 913a85f commit 75a8f66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ void setup_nstart_ndo() {
assert_always(fileout.is_open());
fileout << "#rank nstart ndo ndo_nonempty\n";
for (int r = 0; r < nprocesses; r++) {
assert_always(ranks_ndo_nonempty[r] <= ranks_ndo[r]);
fileout << r << " " << ranks_nstart[r] << " " << ranks_ndo[r] << " " << ranks_ndo_nonempty[r] << "\n";
}
}
Expand Down
23 changes: 12 additions & 11 deletions update_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1105,28 +1105,29 @@ void update_grid(FILE *estimators_file, const int nts, const int nts_prev, const
radfield::normalise_bf_estimators(nts, nts_prev, titer, deltat);
}

const int nstart = grid::get_nstart(my_rank);
const int ndo = grid::get_ndo(my_rank);
heatingcoolingrates_thisrankcells.resize(ndo);
const auto nstart_nonempty = grid::get_nstart_nonempty(my_rank);
const auto ndo_nonempty = grid::get_ndo_nonempty(my_rank);
heatingcoolingrates_thisrankcells.resize(ndo_nonempty);
std::ranges::fill(heatingcoolingrates_thisrankcells, HeatingCoolingRates{});

#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)
#endif
for (int mgi = nstart; mgi < nstart + ndo; mgi++) {
const auto nonemptymgi = (grid::get_numpropcells(mgi) > 0) ? grid::get_nonemptymgi_of_mgi(mgi) : -1;
if (nonemptymgi >= 0) {
update_grid_cell(nonemptymgi, nts, nts_prev, titer, tratmid, deltat,
heatingcoolingrates_thisrankcells.at(mgi - nstart));
}
for (int nonemptymgi = nstart_nonempty; nonemptymgi < (nstart_nonempty + ndo_nonempty); nonemptymgi++) {
update_grid_cell(nonemptymgi, nts, nts_prev, titer, tratmid, deltat,
heatingcoolingrates_thisrankcells.at(nonemptymgi - nstart_nonempty));
} // end parallel for loop over all modelgrid cells

// serial output of estimator data to this ranks estimator file cell by cell
for (int mgi = nstart; mgi < nstart + ndo; mgi++) {
const auto nstart = grid::get_nstart(my_rank);
const auto ndo = grid::get_ndo(my_rank);
for (int mgi = nstart; mgi < (nstart + ndo); mgi++) {
const auto nonemptymgi = (grid::get_numpropcells(mgi) > 0) ? grid::get_nonemptymgi_of_mgi(mgi) : -1;
if (nonemptymgi >= 0) {
assert_always(nonemptymgi >= nstart_nonempty);
assert_always(nonemptymgi < (nstart_nonempty + ndo_nonempty));
write_to_estimators_file(estimators_file, nonemptymgi, nts, titer,
heatingcoolingrates_thisrankcells.at(mgi - nstart));
heatingcoolingrates_thisrankcells.at(nonemptymgi - nstart_nonempty));
} else {
// modelgrid cells that are not represented in the simulation grid
fprintf(estimators_file, "timestep %d modelgridindex %d EMPTYCELL\n\n", nts, mgi);
Expand Down

0 comments on commit 75a8f66

Please sign in to comment.