Perform end of simulation broadcasts from C++

This commit is contained in:
Paul Romano 2018-04-26 22:26:29 -05:00
parent 3ba886cd6d
commit f2748f64a9
4 changed files with 66 additions and 35 deletions

View file

@ -4,6 +4,12 @@
#include "openmc/message_passing.h"
#include "openmc/settings.h"
#ifdef OPENMC_MPI
#include <mpi.h>
#endif
#include <algorithm>
// OPENMC_RUN encompasses all the main logic where iterations are performed
// over the batches, generations, and histories in a fixed source or k-eigenvalue
// calculation.
@ -98,4 +104,46 @@ void calculate_work()
}
}
#ifdef OPENMC_MPI
void broadcast_results() {
// Broadcast tally results so that each process has access to results
double* buffer;
if (n_tallies > 0) {
for (int i=1; i <= n_tallies; ++i) {
// Create a new datatype that consists of all values for a given filter
// bin and then use that to broadcast. This is done to minimize the
// chance of the 'count' argument of MPI_BCAST exceeding 2**31
int shape[3];
openmc_tally_results(i, &buffer, shape);
int n = shape[0];
int count_per_filter = shape[1] * shape[2];
MPI_Datatype result_block;
MPI_Type_contiguous(count_per_filter, MPI_DOUBLE, &result_block);
MPI_Type_commit(&result_block);
MPI_Bcast(buffer, n, result_block, 0, mpi::intracomm);
MPI_Type_free(&result_block);
}
}
// Also broadcast global tally results
openmc_global_tallies(&buffer);
MPI_Bcast(buffer, 4, MPI_DOUBLE, 0, mpi::intracomm);
// These guys are needed so that non-master processes can calculate the
// combined estimate of k-effective
double temp[] {simulation::k_col_abs, simulation::k_col_tra,
simulation::k_abs_tra};
MPI_Bcast(temp, 3, MPI_DOUBLE, 0, mpi::intracomm);
simulation::k_col_abs = temp[0];
simulation::k_col_tra = temp[1];
simulation::k_abs_tra = temp[2];
}
void broadcast_triggers()
{
MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
}
#endif
} // namespace openmc