33 namespace experimental {
35 MultiSimulation::MultiSimulation(
int argc,
const char** argv)
36 : argc_(argc), argv_(argv) {
38 argv_copy_ = (
char**)malloc((argc_ + 1) *
sizeof(
char*));
39 for (
int i = 0; i < argc_; ++i) {
40 size_t length = strlen(argv_[i]) + 1;
41 argv_copy_[i] = (
char*)malloc(length);
42 memcpy(argv_copy_[i], argv_[i], length);
44 argv_copy_[argc_] =
nullptr;
47 MultiSimulation::MultiSimulation(
int argc,
const char** argv, TimeSeries* real)
48 : MultiSimulation(argc, argv) {
54 MultiSimulation::~MultiSimulation() {
55 for (
int i = 0; i < argc_; ++i) {
61 int MultiSimulation::Execute(
const TSimulate& simulate_call) {
62 int worldsize, provided, myrank;
63 MPI_Init_thread(&argc_, &argv_copy_, MPI_THREAD_MULTIPLE, &provided);
64 if (provided < MPI_THREAD_MULTIPLE) {
66 "The threading support level is lesser than that demanded.");
67 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
69 MPI_Comm_size(MPI_COMM_WORLD, &worldsize);
70 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
72 ROOT::EnableThreadSafety();
77 Simulation simulation(argc_, argv_);
78 Param default_params = *(simulation.GetParam());
81 MultiSimulationManager pem(
82 worldsize, &default_params, [&](Param* params, TimeSeries* result) {
83 return simulate_call(argc_, argv_, result, params);
88 omp_set_num_threads(2);
90 Worker w(myrank, [&](Param* params, TimeSeries* result) {
91 return simulate_call(argc_, argv_, result, params);