2018-07-17 06:43:35 -05:00
|
|
|
#include "openmc/simulation.h"
|
|
|
|
|
|
2018-08-20 14:40:32 -05:00
|
|
|
#include "openmc/capi.h"
|
2018-07-17 06:43:35 -05:00
|
|
|
#include "openmc/message_passing.h"
|
2018-08-24 12:35:21 -05:00
|
|
|
#include "openmc/settings.h"
|
2018-09-07 17:26:57 -04:00
|
|
|
#include "openmc/tallies/tally_filter.h"
|
2018-04-12 07:45:47 -05:00
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
2018-09-07 17:26:57 -04:00
|
|
|
int openmc_run()
|
|
|
|
|
{
|
2018-04-12 07:45:47 -05:00
|
|
|
openmc_simulation_init();
|
|
|
|
|
|
|
|
|
|
int err = 0;
|
|
|
|
|
int status = 0;
|
|
|
|
|
while (status == 0 && err == 0) {
|
|
|
|
|
err = openmc_next_batch(&status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openmc_simulation_finalize();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2018-09-07 17:26:57 -04:00
|
|
|
|
|
|
|
|
namespace openmc {
|
|
|
|
|
|
2018-08-23 21:38:23 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
// Global variables
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
2018-07-17 06:43:35 -05:00
|
|
|
std::vector<int64_t> work_index;
|
|
|
|
|
|
2018-08-23 21:38:23 -05:00
|
|
|
//==============================================================================
|
|
|
|
|
// Functions
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
|
|
void openmc_simulation_init_c()
|
2018-09-07 17:26:57 -04:00
|
|
|
{
|
2018-08-23 21:38:23 -05:00
|
|
|
// Determine how much work each process should do
|
|
|
|
|
calculate_work();
|
2018-09-10 16:19:25 -04:00
|
|
|
|
|
|
|
|
// Allocate array for matching filter bins
|
2018-09-07 17:26:57 -04:00
|
|
|
#pragma omp parallel
|
|
|
|
|
{
|
|
|
|
|
filter_matches.resize(n_filters);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 06:43:35 -05:00
|
|
|
void calculate_work()
|
|
|
|
|
{
|
|
|
|
|
// Determine minimum amount of particles to simulate on each processor
|
2018-08-24 12:35:21 -05:00
|
|
|
int64_t min_work = settings::n_particles / mpi::n_procs;
|
2018-07-17 06:43:35 -05:00
|
|
|
|
|
|
|
|
// Determine number of processors that have one extra particle
|
2018-08-24 12:35:21 -05:00
|
|
|
int64_t remainder = settings::n_particles % mpi::n_procs;
|
2018-07-17 06:43:35 -05:00
|
|
|
|
|
|
|
|
int64_t i_bank = 0;
|
|
|
|
|
work_index.reserve(mpi::n_procs);
|
|
|
|
|
work_index.push_back(0);
|
|
|
|
|
for (int i = 0; i < mpi::n_procs; ++i) {
|
|
|
|
|
// Number of particles for rank i
|
|
|
|
|
int64_t work_i = i < remainder ? min_work + 1 : min_work;
|
|
|
|
|
|
|
|
|
|
// Set number of particles
|
|
|
|
|
if (mpi::rank == i) openmc_work = work_i;
|
|
|
|
|
|
|
|
|
|
// Set index into source bank for rank i
|
|
|
|
|
i_bank += work_i;
|
|
|
|
|
work_index.push_back(i_bank);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-07 17:26:57 -04:00
|
|
|
extern "C" void
|
|
|
|
|
openmc_simulation_finalize_c()
|
|
|
|
|
{
|
|
|
|
|
#pragma omp parallel
|
|
|
|
|
{
|
|
|
|
|
filter_matches.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace openmc
|