Added new restart info

This commit is contained in:
2025-08-21 14:00:24 +02:00
parent 285d165615
commit bea8751f1d
10 changed files with 73 additions and 22 deletions
+1
View File
@@ -15,6 +15,7 @@ class Hdf5Reader {
blitz::Array<double, 2> readD2Double(std::string path); blitz::Array<double, 2> readD2Double(std::string path);
blitz::Array<double, 1> readD1Double(std::string path); blitz::Array<double, 1> readD1Double(std::string path);
double readDouble(std::string path); double readDouble(std::string path);
int readInt(std::string path);
blitz::Array<long int, 5> readD5LongInt(std::string path); blitz::Array<long int, 5> readD5LongInt(std::string path);
blitz::Array<long int, 4> readD4LongInt(std::string path); blitz::Array<long int, 4> readD4LongInt(std::string path);
+2 -1
View File
@@ -36,7 +36,8 @@ class Restart {
void restart(std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species, void restart(std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver, RandomNumbers* random_numbers, PoissonSolver* poisson_solver, RandomNumbers* random_numbers,
std::vector<particle::SerializedParticle>& storage_queue); std::vector<particle::SerializedParticle>& storage_queue,
int& injectionGroupOffset);
private: private:
void restartTimer(species::TrackedSpecie* reference_specie); void restartTimer(species::TrackedSpecie* reference_specie);
+3 -2
View File
@@ -49,7 +49,8 @@ class SimulationOutput {
int cpu_sync, int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species, std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver, std::mt19937* engine, PoissonSolver* poisson_solver, std::mt19937* engine,
std::vector<particle::SerializedParticle>& storage_queue); std::vector<particle::SerializedParticle>& storage_queue,
int injectionGroupOffset);
private: private:
std::vector<OutputTask> tasks_density_fields_; std::vector<OutputTask> tasks_density_fields_;
@@ -113,7 +114,7 @@ class SimulationOutput {
std::string path_to_field); std::string path_to_field);
void writeRestartData(std::mt19937* engine, int cpu_sync, void writeRestartData(std::mt19937* engine, int cpu_sync,
bool overwrite_last); bool overwrite_last, int injectionGroupOffset);
void writeRandomEngineState(std::mt19937* engine, std::string path); void writeRandomEngineState(std::mt19937* engine, std::string path);
void writeParticles(std::vector<particle::SerializedParticle>& particles, void writeParticles(std::vector<particle::SerializedParticle>& particles,
+1
View File
@@ -96,6 +96,7 @@ class Simulation {
int inactive_storage = 1; int inactive_storage = 1;
int timestep = 0; int timestep = 0;
int injectionGroupOffset = 0;
}; };
#endif /* SIMULATION_H */ #endif /* SIMULATION_H */
+30
View File
@@ -132,6 +132,36 @@ double Hdf5Reader::readDouble(std::string path) {
return data; return data;
} }
int Hdf5Reader::readInt(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
// H5Eset_auto(H5E_DEFAULT, NULL, NULL);
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
if (dataset < 0) {
ERROR("The given dataset could not be opened");
}
// turn error report back onby hdf5 because of check H5Dopen2
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
const int ndims = H5Sget_simple_extent_ndims(dataspace);
hsize_t dims[ndims];
if (ndims != 1) {
ERROR("The given dataset is not one dimensional. It has dims: " + ndims);
}
H5Sget_simple_extent_dims(dataspace, dims, NULL);
int data;
H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
&data);
H5Sclose(dataspace);
H5Dclose(dataset);
H5Fclose(file);
return data;
}
blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) { blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) {
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
+2 -2
View File
@@ -517,7 +517,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE); hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
H5Pset_create_intermediate_group(lcpl, 1); H5Pset_create_intermediate_group(lcpl, 1);
int mpi_rank = MpiCommunication::mpiRank(); int mpi_rank = MpiCommunication::mpi_rank;
std::string out{data}; std::string out{data};
size_t stateStringSize = out.size(); size_t stateStringSize = out.size();
@@ -540,7 +540,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
// turn of error report by hdf5 because of check H5Dopen2 // turn of error report by hdf5 because of check H5Dopen2
H5Eset_auto(H5E_DEFAULT, NULL, NULL); H5Eset_auto(H5E_DEFAULT, NULL, NULL);
for(int i = 0; i < MpiCommunication::mpiSize(); ++i) { for(int i = 0; i < MpiCommunication::mpi_size; ++i) {
std::string path = path_base + std::to_string(i); std::string path = path_base + std::to_string(i);
#ifdef debug_level3 #ifdef debug_level3
DEBUG_LEVEL_3(path); DEBUG_LEVEL_3(path);
-1
View File
@@ -134,7 +134,6 @@ void MpiParticleReader::readParticles(
out << "\nvelocity of first serialized particle: " << storage_queue[0].cartesianVelocity(); out << "\nvelocity of first serialized particle: " << storage_queue[0].cartesianVelocity();
out << "\nweight of first serialized particle: " << storage_queue[0].weight(); out << "\nweight of first serialized particle: " << storage_queue[0].weight();
out << "\nspecname of first serialized particle: " << storage_queue[0].specieName(); out << "\nspecname of first serialized particle: " << storage_queue[0].specieName();
out << "\ntbirth of fisrt serialized particle: " << storage_queue[0].timeBirth();
DEBUG_LEVEL_1(out.str()); DEBUG_LEVEL_1(out.str());
} }
#endif #endif
+7 -1
View File
@@ -33,7 +33,8 @@ void Restart::restart(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species, std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver, PoissonSolver* poisson_solver,
RandomNumbers* random_numbers, RandomNumbers* random_numbers,
std::vector<particle::SerializedParticle>& storage_queue) { std::vector<particle::SerializedParticle>& storage_queue,
int& injectionGroupOffset) {
if(!do_restart_) { if(!do_restart_) {
return; return;
@@ -60,6 +61,11 @@ void Restart::restart(
// pair.second->positionDistributionFromDensity()->setMaximumDensity(); // pair.second->positionDistributionFromDensity()->setMaximumDensity();
} }
{
std::string path = "/RestartInfo/" + restart_identifier_ + "/InjectionGroupOffset";
injectionGroupOffset = reader_.readInt(path);
}
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3) #if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_1("Reloading particles."); DEBUG_LEVEL_1("Reloading particles.");
#endif #endif
+14 -3
View File
@@ -78,7 +78,8 @@ void SimulationOutput::writeSimulationData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species, std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver, PoissonSolver* poisson_solver,
std::mt19937* engine, std::mt19937* engine,
std::vector<particle::SerializedParticle>& storage_queue) { std::vector<particle::SerializedParticle>& storage_queue,
int injectionGroupOffset) {
if (MpiCommunication::mpi_rank == 0) { if (MpiCommunication::mpi_rank == 0) {
#ifdef debug_level2 #ifdef debug_level2
@@ -125,7 +126,7 @@ void SimulationOutput::writeSimulationData(
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output, // if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
// otherwise the intervall used the same as for the other outputs // otherwise the intervall used the same as for the other outputs
if((task_rng_.intervall > 0) && (cpu_sync%task_rng_.intervall == 0)) { if((task_rng_.intervall > 0) && (cpu_sync%task_rng_.intervall == 0)) {
writeRestartData(engine, cpu_sync, task_rng_.overwrite_last); writeRestartData(engine, cpu_sync, task_rng_.overwrite_last, injectionGroupOffset);
} }
if((task_particles_.intervall > 0) && (cpu_sync%task_particles_.intervall == 0)) { if((task_particles_.intervall > 0) && (cpu_sync%task_particles_.intervall == 0)) {
@@ -219,7 +220,7 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver,
} }
void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync, void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
bool overwrite_last) { bool overwrite_last, int injectionGroupOffset) {
std::string path_base = "/RestartInfo/SyncPeriod_" + std::string path_base = "/RestartInfo/SyncPeriod_" +
std::to_string(cpu_sync) + std::to_string(cpu_sync) +
"/CPU_"; "/CPU_";
@@ -231,6 +232,16 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
DEBUG_LEVEL_3("Write restart info."); DEBUG_LEVEL_3("Write restart info.");
#endif #endif
writeRandomEngineState(engine, path_base); writeRandomEngineState(engine, path_base);
if(MpiCommunication::mpi_rank == 0) {
std::string path = "/RestartInfo/SyncPeriod_" +
std::to_string(cpu_sync) +
"/InjectionGroupOffset";
if (overwrite_last) {
path = "/RestartInfo/LastSyncPeriod/InjectionGroupOffset";
}
writer.write(injectionGroupOffset, path);
}
// DEBUG_LEVEL_3("Done"); // DEBUG_LEVEL_3("Done");
} }
+13 -12
View File
@@ -99,7 +99,7 @@ void Simulation::init(Parameter& parameter) {
Restart restarter = generator::buildRestart(parameter); Restart restarter = generator::buildRestart(parameter);
restarter.restart(tracked_species_, poisson_solver_.get(), random_.get(), restarter.restart(tracked_species_, poisson_solver_.get(), random_.get(),
storage_queue_[active_storage]); storage_queue_[active_storage], injectionGroupOffset);
// poisson solver is restarted -> set the electric field from the potential // poisson solver is restarted -> set the electric field from the potential
electric_field_->updateDynamicField(poisson_solver_->staticElectricField()); electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
@@ -151,14 +151,14 @@ void Simulation::start() {
// beta decay // beta decay
const int injection_stride = const int injection_stride =
parameter_.intValue(json_path({"Simulation", "InjectionStride"}), 1); parameter_.intValue(json_path({"Simulation", "InjectionStride"}), 1);
int check = MpiCommunication::mpiSize() - injection_stride; int check = MpiCommunication::mpi_size - injection_stride;
ASSERT_NOTNEGATIVE(&check, "The injection stride has to be smaller or equal" ASSERT_NOTNEGATIVE(&check, "The injection stride has to be smaller or equal"
" to the number of processes!"); " to the number of processes!");
const int group = MpiCommunication::mpiRank() % injection_stride; const int group = MpiCommunication::mpi_rank % injection_stride;
// determine the number of processes that inject at the same timestep // determine the number of processes that inject at the same timestep
int group_size = MpiCommunication::mpiSize() / injection_stride; int group_size = MpiCommunication::mpi_size / injection_stride;
group_size = group < (MpiCommunication::mpiSize() - group_size * injection_stride) ? group_size = group < (MpiCommunication::mpi_size - group_size * injection_stride) ?
group_size + 1 : group_size; group_size + 1 : group_size;
// number of timesteps to be simulated // number of timesteps to be simulated
@@ -169,7 +169,7 @@ void Simulation::start() {
// time_resolution_events/Activity // time_resolution_events/Activity
const double time_resolution_events = const double time_resolution_events =
parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}), parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}),
MpiCommunication::mpiSize()); MpiCommunication::mpi_size);
// number of beta decay events per timestep and CPU (will get normalized s.t. // number of beta decay events per timestep and CPU (will get normalized s.t.
// the physical number of particles is correct) // the physical number of particles is correct)
@@ -182,7 +182,7 @@ void Simulation::start() {
#ifdef debug #ifdef debug
std::stringstream out; std::stringstream out;
out << "Rank " << MpiCommunication::mpiRank() << ": is part of group "; out << "Rank " << MpiCommunication::mpi_rank << ": is part of group ";
out << group << " with size " << group_size; out << group << " with size " << group_size;
out << " (injection stride: " << injection_stride << ")"; out << " (injection stride: " << injection_stride << ")";
out << "\n\tweight of beta particle: " << beta_particle_weight; out << "\n\tweight of beta particle: " << beta_particle_weight;
@@ -204,7 +204,7 @@ void Simulation::start() {
// calculate the scaling factor for the particle weight for particles // calculate the scaling factor for the particle weight for particles
// drawn from the density // drawn from the density
const double density_weight_factor = const double density_weight_factor =
1./(MpiCommunication::mpiSize()*particles_per_bin); 1./(MpiCommunication::mpi_size*particles_per_bin);
#ifdef debug #ifdef debug
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin)); DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
@@ -270,9 +270,9 @@ void Simulation::start() {
// process both density and beta events before a cpu synchronization // process both density and beta events before a cpu synchronization
processDensityEvents(particles_per_bin, density_weight_factor); processDensityEvents(particles_per_bin, density_weight_factor);
if(group == (timestep % injection_stride)) { if(group == ((timestep + injectionGroupOffset) % injection_stride)) {
#ifdef debug #ifdef debug
DEBUG_LEVEL_0(std::to_string(MpiCommunication::mpiRank()) + ": injection at " DEBUG_LEVEL_0(std::to_string(MpiCommunication::mpi_rank) + ": injection at "
"timestep " + std::to_string(timestep)); "timestep " + std::to_string(timestep));
#endif #endif
processEvents(events_of_cycle, beta_particle_weight); processEvents(events_of_cycle, beta_particle_weight);
@@ -312,8 +312,9 @@ void Simulation::start() {
SimulationTimer::eventStartPoint(std::string("Output")); SimulationTimer::eventStartPoint(std::string("Output"));
// only write inactive queue, obvi not correct if written between timesteps // only write inactive queue, obvi not correct if written between timesteps
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(), output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(),
random_->engine(), storage_queue_[inactive_storage]); random_->engine(), storage_queue_[inactive_storage],
SimulationTimer::eventStopPoint(std::string("Output")); (timestep + injectionGroupOffset + 1) % injection_stride);
SimulationTimer::eventStopPoint(std::string("Output"));
SimulationTimer::eventStartPoint("Reset"); SimulationTimer::eventStartPoint("Reset");
if(reset) { if(reset) {