// // simulation.cpp // mc_electron // // Created by Christian Reiling on 20.09.18. // Copyright © 2018 Christian Reiling. All rights reserved. // #include "simulation.hpp" #include using namespace std; const long int Simulation::seed = load_parameter("seed"); const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays"); const long int Simulation::simulationStepWidth = load_parameter("simulationStepWidth"); const long int Simulation::popCalcDecays = load_parameter("popCalcDecays"); const long int Simulation::popCalcStep = load_parameter("popCalcStep"); Simulation::Simulation() { MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); looper.init(calc_seed(), calc_ID_offset(), calc_outfile_path()); init_pop_arrays(); } Simulation::~Simulation() { deconstruct_pop_arrays(); } void Simulation::init_pop_arrays() { vector all_species = get_all_species_vector(); number_pop_species = all_species.size(); pop_species = new species[number_pop_species]; pop_array_lengths = new int[number_pop_species]; global_cum_time_s = new double *[number_pop_species]; global_offset = new double *[number_pop_species]; Population_Manager *populations = looper.get_populations(); Population_Base *population; for (int i = 0; ifind(pop_species[i]); pop_array_lengths[i] = population->get_array_length(); global_cum_time_s[i] = new double[pop_array_lengths[i]]; global_offset[i] = new double[pop_array_lengths[i]]; for (int j = 0; jfind(pop_species[i]); array_length = pop_array_lengths[i]; if (array_length == 0) { continue; } global_delta_cumulated_time_s = new double[array_length]; global_delta_offset = new double[array_length]; local_delta_cumulated_time_s = new double[array_length]; local_delta_offset = new double[array_length]; for (int j = 0; jget_cumulated_time_s_array()[j] - global_cum_time_s[i][j]; local_delta_offset[j] = population->get_offset_array()[j] - global_offset[i][j]; } MPI_Allreduce(local_delta_cumulated_time_s, global_delta_cumulated_time_s, array_length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(local_delta_offset, global_delta_offset, array_length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); for (int j = 0; jget_cumulated_time_s_array()[j] = global_cum_time_s[i][j]; population->get_offset_array()[j] = global_offset[i][j]; } delete[] global_delta_cumulated_time_s; delete[] global_delta_offset; delete[] local_delta_cumulated_time_s; delete[] local_delta_offset; } } void Simulation::do_statusUpdate() { if (mpi_rank == 0) { cout<<"Status: "<