Skip to content

Commit

Permalink
Update update_grid.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Nov 19, 2024
1 parent 10fa884 commit a8852ab
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions update_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@
namespace {
std::vector<HeatingCoolingRates> heatingcoolingrates_thisrankcells;

void write_to_estimators_file(FILE *estimators_file, const int mgi, const int timestep, const int titer,
void write_to_estimators_file(FILE *estimators_file, const int nonemptymgi, const int timestep, const int titer,
const HeatingCoolingRates &heatingcoolingrates) {
// return; disable for better performance (if estimators files are not needed)

if (grid::get_numpropcells(mgi) < 1) {
// modelgrid cells that are not represented in the simulation grid
fprintf(estimators_file, "timestep %d modelgridindex %d EMPTYCELL\n\n", timestep, mgi);
fflush(estimators_file);
return;
}

const auto nonemptymgi = grid::get_nonemptymgi_of_mgi(mgi);
const int mgi = grid::get_mgi_of_nonemptymgi(nonemptymgi);

const auto sys_time_start_write_estimators = std::time(nullptr);

Expand Down Expand Up @@ -1118,30 +1110,30 @@ void update_grid(FILE *estimators_file, const int nts, const int nts_prev, const
heatingcoolingrates_thisrankcells.resize(ndo);
std::ranges::fill(heatingcoolingrates_thisrankcells, HeatingCoolingRates{});
#ifdef _OPENMP
#pragma omp parallel
#endif
{
// Updating cell information
#ifdef _OPENMP
#pragma omp for schedule(dynamic)
#pragma omp parallel for schedule(dynamic)
#endif

for (int mgi = nstart; mgi < nstart + ndo; mgi++) {
auto &heatingcoolingrates = heatingcoolingrates_thisrankcells.at(mgi - nstart);
if (grid::get_numpropcells(mgi) > 0) {
update_grid_cell(mgi, nts, nts_prev, titer, tratmid, deltat, heatingcoolingrates);
}
for (int mgi = nstart; mgi < nstart + ndo; mgi++) {
auto &heatingcoolingrates = heatingcoolingrates_thisrankcells.at(mgi - nstart);
const auto nonemptymgi = (grid::get_numpropcells(mgi) > 0) ? grid::get_nonemptymgi_of_mgi(mgi) : -1;
if (nonemptymgi >= 0) {
update_grid_cell(mgi, nts, nts_prev, titer, tratmid, deltat, heatingcoolingrates);
}

// maybe want to add omp ordered here if the modelgrid cells should be output in order
// maybe want to add omp ordered here if the modelgrid cells should be output in order
#ifdef _OPENMP
#pragma omp critical(estimators_file)
#endif
{
write_to_estimators_file(estimators_file, mgi, nts, titer, heatingcoolingrates);
{
if (nonemptymgi >= 0) {
write_to_estimators_file(estimators_file, nonemptymgi, nts, titer, heatingcoolingrates);
} else {
// modelgrid cells that are not represented in the simulation grid
fprintf(estimators_file, "timestep %d modelgridindex %d EMPTYCELL\n\n", nts, mgi);
fflush(estimators_file);
}
} // end parallel for loop over all modelgrid cells

} // end OpenMP parallel section
}
} // end parallel for loop over all modelgrid cells

// Now after all the relevant tasks of update_grid have been finished activate
// the use of the cellcache for all OpenMP tasks, in what follows (update_packets)
Expand Down

0 comments on commit a8852ab

Please sign in to comment.