// // 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("DECAYS"); const long int Simulation::simulationStepWidth = load_parameter("STEP"); const long int Simulation::popCalcDecays = load_parameter("POP_DECAYS"); const long int Simulation::popCalcStep = load_parameter("POP_STEP"); 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(); } void Simulation::init_pop_arrays() { // Init C-arrays used for MPI-Allgather commands depending on Populations sizes Population_Manager *populations = looper.get_populations(); int number_pop_species = 0; vector all_species = get_all_species_vector(); for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { if (populations->find(*itr)->access_container() != nullptr) { number_pop_species += 1 ; } } 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_Base *population; int i = 0; for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { if (populations->find(*itr)->access_container() != nullptr) { pop_species[i] = *itr; population = populations->find(*itr); pop_array_lengths[i] = population->access_container()->data_size; 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])->access_container(); 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; jcum_times_s[j] - global_cum_time_s[i][j]; local_delta_offset[j] = container->offsets[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; jcum_times_s[j] = global_cum_time_s[i][j]; container->offsets[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() { // Push current number of decays to std::cout if (mpi_rank == 0) { cout<<"Status: "< all_species = get_all_species_vector(); Termination_Stats local_stats, global_stats; int local_array[7], global_array[7]; for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { if (terminators->exists(*itr)) { local_stats = terminators->find(*itr)->get_stats(); local_stats.to_array(local_array); MPI_Allreduce(local_array, global_array, 7, MPI_INT, MPI_SUM, MPI_COMM_WORLD); global_stats.from_array(global_array); if (mpi_rank == 0) { std::cout<<"# "<<*itr<<"\n"; std::cout<<"n_total\t"<