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) {
42 unsigned n_batches = world_size;
43 unsigned current_batch = world_rank;
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) {
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];
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.
void runSimulation(Simulation *simulation)
Collect the different options for simulation.
unsigned getNumberOfThreads() const
void setThreadInfo(const ThreadInfo &thread_info)
Sets the batch and thread information to be used.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
const SimulationOptions & getOptions() const
void runSimulation()
Run a simulation, possibly averaged over parameter distributions.
virtual std::vector< double > rawResults() const =0
virtual void setRawResults(const std::vector< double > &raw_data)=0
Information to run simulation with dedicated number of threads.