Added "Population Calculation" Mode, where Particles are not logged and different communication rate between CPUs can be set to calculate equilibrium population densities in the beginning.
This commit is contained in:
@@ -13,6 +13,8 @@ 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);
|
||||
@@ -25,7 +27,7 @@ Simulation::~Simulation() {
|
||||
}
|
||||
|
||||
void Simulation::init_pop_arrays() {
|
||||
vector<species> all_species = get_all_spieces_vector();
|
||||
vector<species> all_species = get_all_species_vector();
|
||||
number_pop_species = all_species.size();
|
||||
|
||||
pop_species = new species[number_pop_species];
|
||||
@@ -114,29 +116,45 @@ void Simulation::create_out_dir(std::string dirname) {
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
long int decays_this_cpu = numberTotalDecays/mpi_size;
|
||||
int overflow = numberTotalDecays%mpi_size;
|
||||
do_cycle(popCalcDecays, popCalcStep, false);
|
||||
cout<<"Population calculation done.\n";
|
||||
do_cycle(numberTotalDecays, simulationStepWidth, true);
|
||||
};
|
||||
|
||||
int num_cycles = decays_this_cpu/simulationStepWidth; // Must be same for all CPUs else deadlock!
|
||||
int num_remaining = decays_this_cpu%simulationStepWidth;
|
||||
void Simulation::do_cycle(long int number_total, long int step_size, bool logging) {
|
||||
if (step_size <1) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::do_cycle: invalid step_size. \n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
long int decays_this_cpu = number_total/mpi_size;
|
||||
int overflow = number_total%mpi_size;
|
||||
|
||||
int num_cycles = decays_this_cpu/step_size; // Must be same for all CPUs else deadlock!
|
||||
int num_remaining = decays_this_cpu%step_size;
|
||||
if (mpi_rank < overflow) { // Split overflows equaly to left over CPUs.
|
||||
num_remaining += 1;
|
||||
}
|
||||
for (int i = 0; i<(num_cycles-1); i++) {
|
||||
do_decays(simulationStepWidth);
|
||||
do_decays(step_size, logging);
|
||||
}
|
||||
if (num_cycles == 0) { // Rather unrealistic case.. maybe find a more elegant solution later.
|
||||
do_decays(num_remaining);
|
||||
do_decays(num_remaining, logging);
|
||||
} else {
|
||||
do_decays(simulationStepWidth + num_remaining);
|
||||
do_decays(step_size + num_remaining, logging);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Simulation::do_decays(int number_decays) {
|
||||
looper.do_loops(number_decays);
|
||||
void Simulation::do_decays(const long int &number_decays, const bool &logging) {
|
||||
if (logging) {
|
||||
looper.do_loops(number_decays);
|
||||
} else {
|
||||
looper.do_logging_off_loops(number_decays);
|
||||
}
|
||||
number_local_decays += number_decays;
|
||||
sync_cpus();
|
||||
do_statusUpdate();
|
||||
|
||||
}
|
||||
|
||||
void Simulation::sync_cpus() {
|
||||
@@ -146,7 +164,6 @@ void Simulation::sync_cpus() {
|
||||
}
|
||||
|
||||
void Simulation::sync_populations() {
|
||||
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
Population_Base *population;
|
||||
double *global_delta_cumulated_time_s;
|
||||
@@ -189,7 +206,7 @@ void Simulation::sync_populations() {
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (mpi_rank == 0) {
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<numberTotalDecays<<endl;
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<(numberTotalDecays+popCalcDecays)<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user