27 void MPISimulation::runSimulation(
Simulation* simulation)
31 int world_size(0), world_rank(0);
32 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
33 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
35 if (world_size == 1) {
41 unsigned n_threads = sim_options.getNumberOfThreads();
42 unsigned n_batches = world_size;
43 unsigned current_batch = world_rank;
45 info.n_threads = n_threads;
46 info.n_batches = n_batches;
47 info.current_batch = current_batch;
51 if (world_rank != 0) {
52 std::vector<double> raw = simulation->rawResults();
53 MPI_Send(&raw[0], raw.size(), MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
55 if (world_rank == 0) {
56 auto sum_of_raw = simulation->rawResults();
57 size_t total_size = sum_of_raw.size();
58 for (
int i = 1; i < world_size; ++i) {
59 std::vector<double> raw(total_size);
60 MPI_Recv(&raw[0], total_size, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &st);
61 for (
size_t i_raw = 0; i_raw < total_size; ++i_raw)
62 sum_of_raw[i_raw] += raw[i_raw];
64 simulation->setRawResults(sum_of_raw);
75 void MPISimulation::runSimulation(
Simulation* )
77 throw std::runtime_error(
78 "MPISimulation::runSimulation() -> Error! Can't run MPI simulation. "
79 "The package was compiled without MPI support (compile with -DBORNAGAIN_MPI=ON)");
Defines class MPISimulation.
Defines class Simulation.
Collect the different options for simulation.
void setThreadInfo(const ThreadInfo &thread_info)
Sets the batch and thread information to be used.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
void runSimulation()
Run a simulation, possibly averaged over parameter distributions.
Information to run simulation with dedicated number of threads.