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
+30
View File
@@ -132,6 +132,36 @@ double Hdf5Reader::readDouble(std::string path) {
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) {
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);
H5Pset_create_intermediate_group(lcpl, 1);
int mpi_rank = MpiCommunication::mpiRank();
int mpi_rank = MpiCommunication::mpi_rank;
std::string out{data};
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
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);
#ifdef debug_level3
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 << "\nweight of first serialized particle: " << storage_queue[0].weight();
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());
}
#endif
+7 -1
View File
@@ -33,7 +33,8 @@ void Restart::restart(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver,
RandomNumbers* random_numbers,
std::vector<particle::SerializedParticle>& storage_queue) {
std::vector<particle::SerializedParticle>& storage_queue,
int& injectionGroupOffset) {
if(!do_restart_) {
return;
@@ -60,6 +61,11 @@ void Restart::restart(
// 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)
DEBUG_LEVEL_1("Reloading particles.");
#endif
+14 -3
View File
@@ -78,7 +78,8 @@ void SimulationOutput::writeSimulationData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
PoissonSolver* poisson_solver,
std::mt19937* engine,
std::vector<particle::SerializedParticle>& storage_queue) {
std::vector<particle::SerializedParticle>& storage_queue,
int injectionGroupOffset) {
if (MpiCommunication::mpi_rank == 0) {
#ifdef debug_level2
@@ -125,7 +126,7 @@ void SimulationOutput::writeSimulationData(
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
// otherwise the intervall used the same as for the other outputs
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)) {
@@ -219,7 +220,7 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver,
}
void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
bool overwrite_last) {
bool overwrite_last, int injectionGroupOffset) {
std::string path_base = "/RestartInfo/SyncPeriod_" +
std::to_string(cpu_sync) +
"/CPU_";
@@ -231,6 +232,16 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
DEBUG_LEVEL_3("Write restart info.");
#endif
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");
}
+13 -12
View File
@@ -99,7 +99,7 @@ void Simulation::init(Parameter& parameter) {
Restart restarter = generator::buildRestart(parameter);
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
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
@@ -151,14 +151,14 @@ void Simulation::start() {
// beta decay
const int injection_stride =
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"
" 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
int group_size = MpiCommunication::mpiSize() / injection_stride;
group_size = group < (MpiCommunication::mpiSize() - group_size * injection_stride) ?
int group_size = MpiCommunication::mpi_size / injection_stride;
group_size = group < (MpiCommunication::mpi_size - group_size * injection_stride) ?
group_size + 1 : group_size;
// number of timesteps to be simulated
@@ -169,7 +169,7 @@ void Simulation::start() {
// time_resolution_events/Activity
const double time_resolution_events =
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.
// the physical number of particles is correct)
@@ -182,7 +182,7 @@ void Simulation::start() {
#ifdef debug
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 << " (injection stride: " << injection_stride << ")";
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
// drawn from the density
const double density_weight_factor =
1./(MpiCommunication::mpiSize()*particles_per_bin);
1./(MpiCommunication::mpi_size*particles_per_bin);
#ifdef debug
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
processDensityEvents(particles_per_bin, density_weight_factor);
if(group == (timestep % injection_stride)) {
if(group == ((timestep + injectionGroupOffset) % injection_stride)) {
#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));
#endif
processEvents(events_of_cycle, beta_particle_weight);
@@ -312,8 +312,9 @@ void Simulation::start() {
SimulationTimer::eventStartPoint(std::string("Output"));
// only write inactive queue, obvi not correct if written between timesteps
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(),
random_->engine(), storage_queue_[inactive_storage]);
SimulationTimer::eventStopPoint(std::string("Output"));
random_->engine(), storage_queue_[inactive_storage],
(timestep + injectionGroupOffset + 1) % injection_stride);
SimulationTimer::eventStopPoint(std::string("Output"));
SimulationTimer::eventStartPoint("Reset");
if(reset) {