Commit f1dcc606 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Alternative parallelization is now configurable and off by default.

parent 8b394515
......@@ -225,6 +225,7 @@ void Params::broadcast(int rank) {
mpi_env.broadcast(_slice_thickness, rank);
mpi_env.broadcast(_number_configurations, rank);
mpi_env.broadcast(_alternative_parallelization, rank);
mpi_env.broadcast(_fixed_slicing, rank);
mpi_env.broadcast(_fp_enabled, rank);
......
......@@ -409,6 +409,10 @@ namespace stemsalabim {
return _adf_average_configurations;
}
bool isAlternativeParallelization() const {
return _alternative_parallelization;
}
/*!
* When some fixed grid size is given, return true
*/
......@@ -626,6 +630,7 @@ namespace stemsalabim {
std::mt19937 _rgen{0};
unsigned _work_package_size{10};
unsigned _num_threads{1};
bool _alternative_parallelization{false};
// Settings related to ADF mode
bool _adf_enabled{true};
......@@ -649,7 +654,7 @@ namespace stemsalabim {
// plasmon scattering
bool _plasmons_enabled{false};
bool _plasmons_simple{false};
bool _plasmons_plural{true};
bool _plasmons_plural{false};
float _plasmons_max_energy{10};
float _plasmons_energy_grid_density{10};
float _plasmons_mean_free_path{110};
......
......@@ -140,18 +140,8 @@ void Simulation::run() {
high_resolution_clock::time_point start_sim, t1;
start_sim = high_resolution_clock::now();
// decide on parallelization scheme
// When the number of MPI processors is much smaller than the number of configurations,
// parallelize on configuration level.
int number_configurations_total = prms.numberOfConfigurations() * prms.numberOfDefoci();
bool parallelize_configurations = false;
if(mpi_env.isMpi() && 3 * mpi_env.size() < number_configurations_total) {
parallelize_configurations = true;
} else if(mpi_env.isMpi() &&
mpi_env.size() <= number_configurations_total &&
number_configurations_total % mpi_env.size() == 0) {
parallelize_configurations = true;
}
// choose parallelization scheme
bool parallelize_configurations = prms.isAlternativeParallelization();
if(mpi_env.isMpi() && parallelize_configurations) {
printMaster(output::fmt("%d configurations are calculated in parallel with %d threads each.\n",
......@@ -323,29 +313,29 @@ seconds Simulation::calculatePixel(ScanPoint &point, double defocus) {
if(p.plasmonsEnabled()) {
// for now, single scattering only...
for(unsigned int energy_i = _gridman->energyLossGrid().size() - 1u; energy_i > 0; energy_i--) {
waves[energy_i] *= sqrt(plasmons.beta0());
tmpwave = waves[0];
tmpwave *= plasmons.scatteringFunction(energy_i - 1);
tmpwave *= sqrt(plasmons.beta1());
waves[energy_i] += tmpwave;
}
//
// // scattering
// for(unsigned int energy_i = _gridman->energyLossGrid().size() - 1u; energy_i > 0; energy_i--) {
//
// waves[energy_i] *= sqrt(plasmons.beta0());
//
// // plural scattering includes single scattering with energy_j = 0
// for(unsigned int energy_j = 0; energy_j < (p.plasmonsPluralScattering() ? energy_i : 1u); energy_j++) {
// tmpwave = waves[energy_j];
// tmpwave *= plasmons.scatteringFunction(energy_i - energy_j - 1);
// tmpwave *= sqrt(plasmons.beta1());
// waves[energy_i] += tmpwave;
// }
// tmpwave = waves[0];
// tmpwave *= plasmons.scatteringFunction(energy_i - 1);
// tmpwave *= sqrt(plasmons.beta1());
// waves[energy_i] += tmpwave;
// }
//
// scattering
for(unsigned int energy_i = _gridman->energyLossGrid().size() - 1u; energy_i > 0; energy_i--) {
waves[energy_i] *= sqrt(plasmons.beta0());
// plural scattering includes single scattering with energy_j = 0
for(unsigned int energy_j = 0; energy_j < (p.plasmonsPluralScattering() ? energy_i : 1u); energy_j++) {
tmpwave = waves[energy_j];
tmpwave *= plasmons.scatteringFunction(energy_i - energy_j - 1);
tmpwave *= sqrt(plasmons.beta1());
waves[energy_i] += tmpwave;
}
}
//
waves[0] *= sqrt(plasmons.beta0());
......
......@@ -51,6 +51,7 @@ void Params::initFromCLI(int argc, const char **argv) {
ValueFlag<string> output_file(parser, "output-file", "The output file path.", {'o', "output-file"});
ValueFlag<string> tmp_dir(parser, "tmp-dir", "The path to the temporary directory.", {"tmp-dir"});
Flag stored_potentials(parser, "stored-potentials", "Work with stored potentials", {"stored-potentials"});
Flag altern_para(parser, "alternative-parallelization", "Parallelize over configurations", {"alternative-parallelization"});
try {
......@@ -102,6 +103,11 @@ void Params::initFromCLI(int argc, const char **argv) {
_tmp_dir = get(tmp_dir);
}
if(altern_para) {
_cli_options.push_back(altern_para.Name());
_alternative_parallelization = get(altern_para);
}
_uuid = sole::uuid4().str();
}
......
......@@ -54,6 +54,8 @@ void Params::initFromCLI(int argc, const char **argv) {
ValueFlag<string> output_file(parser, "output-file", "The output file path.", {'o', "output-file"});
ValueFlag<string> crystal_file(parser, "crystal-file", "The crystal file path.", {'c', "crystal-file"});
ValueFlag<string> tmp_dir(parser, "tmp-dir", "The path to the temporary directory.", {"tmp-dir"});
Flag altern_para(parser, "alternative-parallelization", "Parallelize over configurations", {"alternative-parallelization"});
try {
parser.ParseCLI(argc, argv);
......@@ -104,6 +106,11 @@ void Params::initFromCLI(int argc, const char **argv) {
_crystal_file = get(crystal_file);
}
if(altern_para) {
_cli_options.push_back(altern_para.Name());
_alternative_parallelization = get(altern_para);
}
_uuid = sole::uuid4().str();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment