Electrons are explicitly stored between timesteps
and can be dumped using MPI-IO. Restarts read particles from earlier output.
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#ifndef MPI_PARTICLE_FORMAT_H
|
||||
#define MPI_PARTICLE_FORMAT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "mpi.h"
|
||||
/* File format (as in ACRONYM):
|
||||
*
|
||||
* mpi_io_header
|
||||
* <padding>
|
||||
* cpu_header[n_cpus]
|
||||
* <padding>
|
||||
* data_of_cpu_1 <padding>
|
||||
* data_of_cpu_2 <padding>
|
||||
* ...
|
||||
*/
|
||||
|
||||
/* file header*/
|
||||
struct mpi_io_header_t {
|
||||
std::uint64_t magic;
|
||||
std::uint64_t cpu_header_offset;
|
||||
std::uint32_t num_cpus;
|
||||
double dt;
|
||||
|
||||
bool verify() {
|
||||
// Sanity Check if file is the right format
|
||||
if(magic != ((std::uint64_t)'KA'<<32) + 'RL') {
|
||||
return false;
|
||||
}
|
||||
if(dt < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/* per-CPU header */
|
||||
struct cpu_header_t {
|
||||
std::uint64_t num_particles;
|
||||
std::uint64_t file_offset;
|
||||
};
|
||||
|
||||
// seems to work only if alignment is a power of 2
|
||||
static std::uint64_t pad_to_blocksize(std::uint64_t size, std::uint64_t alignment) {
|
||||
size &= ~(alignment - 1);
|
||||
size += alignment;
|
||||
return size;
|
||||
}
|
||||
|
||||
#ifdef MPI_VERSION
|
||||
|
||||
#ifndef MPI_UINT32_T
|
||||
#define MPI_UNIT32_T MPI_UNSIGNED
|
||||
#endif
|
||||
|
||||
#ifndef MPI_UINT64_T
|
||||
#define MPI_UNIT64_T MPI_UNSIGNED_LONG_LONG
|
||||
#endif
|
||||
|
||||
/* Custom MPI data types for the header structs */
|
||||
static MPI_Datatype build_file_header_type() {
|
||||
int status;
|
||||
MPI_Datatype type;
|
||||
int blocklengths[4];
|
||||
MPI_Aint disps[4];
|
||||
MPI_Datatype types[4];
|
||||
|
||||
disps[0] = offsetof(mpi_io_header_t, magic);
|
||||
types[0] = MPI_UINT64_T;
|
||||
blocklengths[0] = 1;
|
||||
|
||||
disps[1] = offsetof(mpi_io_header_t, cpu_header_offset);
|
||||
types[1] = MPI_UINT64_T;
|
||||
blocklengths[1] = 1;
|
||||
|
||||
disps[2] = offsetof(mpi_io_header_t, num_cpus);
|
||||
types[2] = MPI_UINT32_T;
|
||||
blocklengths[2] = 1;
|
||||
|
||||
disps[3] = offsetof(mpi_io_header_t, dt);
|
||||
types[3] = MPI_DOUBLE;
|
||||
blocklengths[3] = 1;
|
||||
|
||||
status = MPI_Type_create_struct(4, blocklengths, disps, types, &type);
|
||||
status |= MPI_Type_commit(&type);
|
||||
|
||||
if(status) {
|
||||
fprintf(stderr, "Creation of the data type \"file_header\" failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static MPI_Datatype build_cpu_header_type() {
|
||||
int status;
|
||||
MPI_Datatype type;
|
||||
int blocklengths[2];
|
||||
MPI_Aint disps[2];
|
||||
MPI_Datatype types[2];
|
||||
|
||||
disps[0] = offsetof(cpu_header_t, num_particles);
|
||||
types[0] = MPI_UINT64_T;
|
||||
blocklengths[0] = 1;
|
||||
|
||||
disps[1] = offsetof(cpu_header_t, file_offset);
|
||||
types[1] = MPI_UINT64_T;
|
||||
blocklengths[1] = 1;
|
||||
|
||||
status = MPI_Type_create_struct(2, blocklengths, disps, types, &type);
|
||||
status |= MPI_Type_commit(&type);
|
||||
|
||||
if(status) {
|
||||
fprintf(stderr, "Creation of the data type \"cpu_header\" failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
#endif /* MPI_VERSION */
|
||||
|
||||
#endif /* MPI_PARTICLE_FORMAT_H */
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef MPI_PARTICLE_READER_H
|
||||
#define MPI_PARTICLE_READER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
}
|
||||
|
||||
class MpiParticleReader {
|
||||
public:
|
||||
MpiParticleReader(std::string directory, std::string filename, int restart_at);
|
||||
MpiParticleReader(std::string absolute_filename);
|
||||
MpiParticleReader(std::string abs_filename_without_extension, int restart_at);
|
||||
|
||||
void readParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||
|
||||
private:
|
||||
std::string absolute_filename_;
|
||||
};
|
||||
|
||||
#endif /* MPI_PARTICLE_READER_H */
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MPI_PARTICLE_WRITER_H
|
||||
#define MPI_PARTICLE_WRITER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
}
|
||||
|
||||
class MpiParticleWriter {
|
||||
public:
|
||||
MpiParticleWriter(std::string directory = "./output",
|
||||
std::string filename = "output",
|
||||
int fs_blocksize = 4096);
|
||||
|
||||
void output_particles(std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync, double dt);
|
||||
|
||||
private:
|
||||
std::string directory_;
|
||||
std::string filename_;
|
||||
void createFolder(std::string directory);
|
||||
int fs_blocksize_;
|
||||
};
|
||||
|
||||
#endif /* MPI_PARTICLE_WRITER_H */
|
||||
+14
-3
@@ -4,14 +4,20 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "IO/hdf5_reader.h"
|
||||
#include "IO/mpi_particle_reader.h"
|
||||
|
||||
namespace species {
|
||||
class TrackedSpecie;
|
||||
enum class ImplementedSpecies;
|
||||
}; // namespace species
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
};
|
||||
|
||||
class DynamicDensityField;
|
||||
class PoissonSolver;
|
||||
class RandomNumbers;
|
||||
@@ -23,11 +29,14 @@ class RandomNumbers;
|
||||
// here after the potential is loaded; would need the electric field class to be included
|
||||
class Restart {
|
||||
public:
|
||||
Restart(bool do_restart, std::string absolute_filename,
|
||||
std::string restart_identifier);
|
||||
// Restart(bool do_restart, std::string absolute_filename,
|
||||
// std::string restart_identifier);
|
||||
Restart(bool do_restart, std::string absolute_filename_without_extension,
|
||||
std::string restart_identifier, int particle_restart_at);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
void restartTimer(species::TrackedSpecie* reference_specie);
|
||||
@@ -36,9 +45,11 @@ class Restart {
|
||||
// only load in the potential and calc the electric field
|
||||
void restartPoissonSolver(PoissonSolver* solver);
|
||||
void restartRandomNumbers(RandomNumbers* random);
|
||||
void restartParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||
|
||||
bool do_restart_;
|
||||
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
||||
Hdf5Reader reader_;
|
||||
MpiParticleReader particle_reader_;
|
||||
};
|
||||
#endif /* RESTART_H */
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include "IO/hdf5_writer.h"
|
||||
#include "IO/mpi_particle_writer.h"
|
||||
|
||||
class DynamicDensityField;
|
||||
class CurrentBorder;
|
||||
@@ -30,13 +31,15 @@ struct OutputTask {
|
||||
class SimulationOutput {
|
||||
public:
|
||||
SimulationOutput(const std::string& output_folder,
|
||||
const std::string& output_filename);
|
||||
const std::string& output_filename,
|
||||
int fs_blocksize=4096);
|
||||
|
||||
void addDensityFieldOutput(OutputTask task);
|
||||
void addCurrentBorderOutput(OutputTask task);
|
||||
void addDeletionLoggerOutput(OutputTask task);
|
||||
void setPotentialOutput(OutputTask task);
|
||||
void setRestartInfoOutput(OutputTask task);
|
||||
void setParticleOutput(OutputTask task);
|
||||
|
||||
void writeMetaData(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
@@ -45,7 +48,8 @@ class SimulationOutput {
|
||||
void writeSimulationData(
|
||||
int cpu_sync,
|
||||
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);
|
||||
|
||||
private:
|
||||
std::vector<OutputTask> tasks_density_fields_;
|
||||
@@ -53,8 +57,10 @@ class SimulationOutput {
|
||||
std::vector<OutputTask> tasks_deletion_logger_;
|
||||
OutputTask task_potential_;
|
||||
OutputTask task_rng_;
|
||||
OutputTask task_particles_;
|
||||
|
||||
Hdf5Writer writer;
|
||||
MpiParticleWriter particle_writer;
|
||||
|
||||
void writeSimulationData(DynamicDensityField* density_field,
|
||||
std::string species_path,
|
||||
@@ -109,6 +115,9 @@ class SimulationOutput {
|
||||
void writeRestartData(std::mt19937* engine, int cpu_sync,
|
||||
bool overwrite_last);
|
||||
void writeRandomEngineState(std::mt19937* engine, std::string path);
|
||||
|
||||
void writeParticles(std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync, double dt);
|
||||
};
|
||||
|
||||
#endif /* SIMULATION_OUTPUT_H */
|
||||
|
||||
@@ -5,8 +5,35 @@
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/species.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class MpiParticleReader;
|
||||
|
||||
namespace particle {
|
||||
|
||||
class SerializedParticle {
|
||||
public:
|
||||
SerializedParticle(double time_birth, double weight,
|
||||
blitz::TinyVector<double, 3> cart_pos,
|
||||
blitz::TinyVector<double, 3> cart_vel,
|
||||
std::string spec_name);
|
||||
SerializedParticle() {};
|
||||
|
||||
double timeBirth();
|
||||
double weight();
|
||||
blitz::TinyVector<double, 3> cartesianPosition();
|
||||
blitz::TinyVector<double, 3> cartesianVelocity();
|
||||
std::string specieName();
|
||||
|
||||
private:
|
||||
double time_birth_;
|
||||
blitz::TinyVector<double, 3> cartesian_position_;
|
||||
blitz::TinyVector<double, 3> cartesian_velocity_;
|
||||
// has to be null terminated
|
||||
std::array<char, 16> specie_name_;
|
||||
double weight_;
|
||||
};
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
// Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
@@ -18,6 +45,9 @@ class Particle {
|
||||
const double time_birth,
|
||||
const double weight);
|
||||
|
||||
Particle(particle::SerializedParticle sparticle, std::map<std::string,
|
||||
std::shared_ptr<species::TrackedSpecie>>& tracked_species);
|
||||
|
||||
void position(const Coordinate& new_position);
|
||||
CartesianCoordinate cartesianPosition() const;
|
||||
CylinderCoordinate cylinderPosition() const;
|
||||
@@ -52,9 +82,11 @@ class Particle {
|
||||
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
||||
int indexNextInteraction() { return index_next_interaction_; };
|
||||
|
||||
void deposited();
|
||||
void deposited(bool truthValue=true);
|
||||
bool wasDeposited();
|
||||
|
||||
particle::SerializedParticle serialize();
|
||||
|
||||
private:
|
||||
double weight_;
|
||||
bool deposited_ = false;
|
||||
|
||||
@@ -90,7 +90,7 @@ class Simulation {
|
||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||
|
||||
std::vector<particle::Particle> queue_;
|
||||
std::vector<particle::Particle> storage_queue_[2];
|
||||
std::vector<particle::SerializedParticle> storage_queue_[2];
|
||||
|
||||
int active_storage = 0;
|
||||
int inactive_storage = 1;
|
||||
|
||||
Reference in New Issue
Block a user