ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Mpiio Namespace Reference

Classes

struct  write_buffers
 

Enumerations

enum  MPIIOOutputFields : unsigned int {
  MPIIO_OUT_NON = 0u , MPIIO_OUT_POS = 1u , MPIIO_OUT_VEL = 2u , MPIIO_OUT_TYP = 4u ,
  MPIIO_OUT_BND = 8u
}
 Constants which indicate what to output. More...
 

Functions

static bool fatal_error (char const *msg, std::string const &fn="", std::string const &extra="")
 Fatal error handler.
 
static bool fatal_error (char const *msg, std::string const &fn, MPI_File *fp, int errnum)
 Fatal error handler that closes an open file and queries the message associated with an MPI error code.
 
template<typename T >
static void mpiio_dump_array (const std::string &fn, T const *arr, std::size_t len, std::size_t pref, MPI_Datatype MPI_T)
 Dump data arr of size len starting from prefix pref of type T using MPI_T as MPI datatype.
 
static unsigned long mpi_calculate_file_offset (unsigned long n_items)
 Calculate the file offset on the local node.
 
static void dump_info (std::string const &fn, unsigned fields, BondedInteractionsMap const &bonded_ias)
 Dump the fields and bond information.
 
void mpi_mpiio_common_write (std::string const &prefix, unsigned fields, BondedInteractionsMap const &bonded_ias, ParticleRange const &particles, write_buffers &buffers)
 Parallel binary output using MPI-IO.
 
static unsigned long get_num_elem (const std::string &fn, std::size_t elem_sz)
 Get the number of elements in a file by its file size and elem_sz.
 
template<typename T >
static void mpiio_read_array (const std::string &fn, T *arr, std::size_t len, std::size_t pref, MPI_Datatype MPI_T)
 Read a previously dumped array of size len starting from prefix pref of type T using MPI_T as MPI datatype.
 
static unsigned read_head (const std::string &fn, int rank)
 Read the header file and return the first value.
 
static std::tuple< unsigned long, unsigned long > read_prefs (const std::string &fn, int rank, int size, unsigned long nglobalpart)
 Read the pref file.
 
void mpi_mpiio_common_read (std::string const &prefix, unsigned fields, CellStructure &cell_structure)
 Parallel binary input using MPI-IO.
 

Enumeration Type Documentation

◆ MPIIOOutputFields

enum Mpiio::MPIIOOutputFields : unsigned int

Constants which indicate what to output.

To indicate the output of multiple fields, OR the corresponding values.

Enumerator
MPIIO_OUT_NON 
MPIIO_OUT_POS 
MPIIO_OUT_VEL 
MPIIO_OUT_TYP 
MPIIO_OUT_BND 

Definition at line 41 of file core/io/mpiio/mpiio.hpp.

Function Documentation

◆ dump_info()

static void Mpiio::dump_info ( std::string const &  fn,
unsigned  fields,
BondedInteractionsMap const &  bonded_ias 
)
static

Dump the fields and bond information.

To be called by the head node only.

Parameters
fnThe filename to write to
fieldsThe dumped fields
bonded_iasThe list of bonds

Definition at line 189 of file mpiio.cpp.

References BondedInteractionsMap::at(), BondedInteractionsMap::contains(), fatal_error(), BondedInteractionsMap::get_next_key(), number_of_partners(), and BondedInteractionsMap::size().

Referenced by mpi_mpiio_common_write().

◆ fatal_error() [1/2]

static bool Mpiio::fatal_error ( char const *  msg,
std::string const &  fn,
MPI_File *  fp,
int  errnum 
)
static

Fatal error handler that closes an open file and queries the message associated with an MPI error code.

On 1 MPI rank the error is recoverable and an exception is thrown. On more than 1 MPI rank the error is not recoverable.

Parameters
msgCustom error message
fnFile path
fpFile handle
errnumMPI error code

Definition at line 122 of file mpiio.cpp.

References fatal_error().

◆ fatal_error() [2/2]

static bool Mpiio::fatal_error ( char const *  msg,
std::string const &  fn = "",
std::string const &  extra = "" 
)
static

Fatal error handler.

On 1 MPI rank the error is recoverable and an exception is thrown. On more than 1 MPI rank the error is not recoverable.

Parameters
msgCustom error message
fnFile path
extraExtra context

Definition at line 92 of file mpiio.cpp.

References errexit().

Referenced by dump_info(), fatal_error(), get_num_elem(), mpi_mpiio_common_read(), mpiio_dump_array(), mpiio_read_array(), and read_head().

◆ get_num_elem()

static unsigned long Mpiio::get_num_elem ( const std::string &  fn,
std::size_t  elem_sz 
)
static

Get the number of elements in a file by its file size and elem_sz.

I.e. query the file size using stat(2) and divide it by elem_sz.

Parameters
fnThe filename
elem_szSize of a single element
Returns
The number of elements stored in the file

Definition at line 310 of file mpiio.cpp.

References fatal_error().

Referenced by mpi_mpiio_common_read().

◆ mpi_calculate_file_offset()

static unsigned long Mpiio::mpi_calculate_file_offset ( unsigned long  n_items)
static

Calculate the file offset on the local node.

Parameters
n_itemsNumber of items on the local node.
Returns
The number of items on all nodes with lower rank.

Definition at line 175 of file mpiio.cpp.

Referenced by mpi_mpiio_common_read(), and mpi_mpiio_common_write().

◆ mpi_mpiio_common_read()

void Mpiio::mpi_mpiio_common_read ( std::string const &  prefix,
unsigned  fields,
CellStructure cell_structure 
)

Parallel binary input using MPI-IO.

To be called by all MPI processes. Aborts ESPResSo if an error occurs. On 1 MPI rank, the error is converted to a runtime error and can be recovered.

Parameters
prefixFilepath prefix.
fieldsSpecifier for which fields to read.
cell_structureBonds to serialize.

Definition at line 406 of file mpiio.cpp.

References CellStructure::add_particle(), fatal_error(), get_num_elem(), mpi_calculate_file_offset(), MPIIO_OUT_BND, MPIIO_OUT_POS, MPIIO_OUT_TYP, MPIIO_OUT_VEL, read_head(), read_prefs(), and CellStructure::remove_all_particles().

Referenced by ScriptInterface::MPIIO::MPIIOScript::do_call_method().

◆ mpi_mpiio_common_write()

void Mpiio::mpi_mpiio_common_write ( std::string const &  prefix,
unsigned  fields,
BondedInteractionsMap const &  bonded_ias,
ParticleRange const &  particles,
write_buffers buffers 
)

Parallel binary output using MPI-IO.

To be called by all MPI processes. Aborts ESPResSo if an error occurs. On 1 MPI rank, the error is converted to a runtime error and can be recovered by removing any file that may have already been written.

Parameters
prefixFilepath prefix.
fieldsSpecifier for which fields to dump.
bonded_iasBonds to serialize.
particlesRange of particles to serialize.
buffersWrite buffers.

Definition at line 214 of file mpiio.cpp.

References dump_info(), Mpiio::write_buffers::id, mpi_calculate_file_offset(), MPIIO_OUT_BND, MPIIO_OUT_POS, MPIIO_OUT_TYP, MPIIO_OUT_VEL, Mpiio::write_buffers::pos, ParticleRange::size(), Mpiio::write_buffers::type, and Mpiio::write_buffers::vel.

Referenced by ScriptInterface::MPIIO::MPIIOScript::do_call_method().

◆ mpiio_dump_array()

template<typename T >
static void Mpiio::mpiio_dump_array ( const std::string &  fn,
T const *  arr,
std::size_t  len,
std::size_t  pref,
MPI_Datatype  MPI_T 
)
static

Dump data arr of size len starting from prefix pref of type T using MPI_T as MPI datatype.

Beware, that T and MPI_T have to match!

Parameters
fnThe file name to write to (must not already exist!)
arrThe array to dump
lenThe number of elements to dump
prefThe prefix for this process
MPI_TThe MPI datatype corresponding to the template parameter T

Definition at line 148 of file mpiio.cpp.

References fatal_error().

◆ mpiio_read_array()

template<typename T >
static void Mpiio::mpiio_read_array ( const std::string &  fn,
T *  arr,
std::size_t  len,
std::size_t  pref,
MPI_Datatype  MPI_T 
)
static

Read a previously dumped array of size len starting from prefix pref of type T using MPI_T as MPI datatype.

Beware, that T and MPI_T have to match!

Parameters
fnThe file name to read from
arrThe array to populate
lenThe number of elements to read
prefThe prefix for this process
MPI_TThe MPI datatype corresponding to the template parameter T

Definition at line 334 of file mpiio.cpp.

References fatal_error().

◆ read_head()

static unsigned Mpiio::read_head ( const std::string &  fn,
int  rank 
)
static

Read the header file and return the first value.

To be called by all processes.

Parameters
fnFilename of the head file
rankThe rank of the current process in MPI_COMM_WORLD

Definition at line 361 of file mpiio.cpp.

References fatal_error().

Referenced by mpi_mpiio_common_read().

◆ read_prefs()

static std::tuple< unsigned long, unsigned long > Mpiio::read_prefs ( const std::string &  fn,
int  rank,
int  size,
unsigned long  nglobalpart 
)
static

Read the pref file.

Needs to be called by all processes.

Parameters
fnThe file name of the prefs file
rankThe rank of the current process in MPI_COMM_WORLD
sizeThe size of MPI_COMM_WORLD
nglobalpartThe global amount of particles
Returns
The prefix and the local number of particles.

Definition at line 388 of file mpiio.cpp.

Referenced by mpi_mpiio_common_read().