58#include <boost/archive/binary_iarchive.hpp>
59#include <boost/archive/binary_oarchive.hpp>
60#include <boost/iostreams/device/array.hpp>
61#include <boost/iostreams/device/back_inserter.hpp>
62#include <boost/iostreams/stream.hpp>
83#pragma clang diagnostic push
84#pragma clang diagnostic ignored "-Wunreachable-code-return"
95 std::string
const &
extra =
"") {
96 std::stringstream what;
97 what <<
"MPI-IO Error: " <<
msg;
99 what <<
" \"" <<
fn <<
"\"";
102 what <<
" :" <<
extra;
107 throw std::runtime_error(what.str());
113#if defined(__clang__)
114#pragma clang diagnostic pop
154 std::size_t
len, std::size_t pref,
181 unsigned long offset = 0
ul;
205 bool success = (
fwrite(&fields,
sizeof(fields), 1u, f) == 1);
208 for (
int bond_id = 0; bond_id < bonded_ias.
get_next_key(); ++bond_id) {
223 auto const nlocalpart =
static_cast<unsigned long>(particles.
size());
242 auto id_it =
id.begin();
244 auto pos_it = pos.begin();
245 auto vel_it = vel.begin();
246 for (
auto const &p : particles) {
250 std::copy_n(std::begin(p.pos()), 3u,
pos_it);
254 std::copy_n(std::begin(p.v()), 3u,
vel_it);
267 auto const pref_offset =
static_cast<unsigned long>(rank);
282 std::vector<char> bonds;
286 namespace io = boost::iostreams;
287 io::stream_buffer<io::back_insert_device<std::vector<char>>>
os{
288 io::back_inserter(bonds)};
291 for (
auto const &p : particles) {
297 auto const bonds_size =
static_cast<unsigned long>(bonds.size());
324 return static_cast<unsigned long>(
st.st_size) /
elem_sz;
392static std::tuple<unsigned long, unsigned long>
395 auto const pref_offset =
static_cast<unsigned long>(rank);
396 unsigned long pref = 0
ul;
421 if (rank == 0 &&
nproc !=
static_cast<unsigned long>(size)) {
422 fatal_error(
"Trying to read a file with a different COMM "
423 "size than at point of writing.");
431 fatal_error(
"Requesting to read fields which were not dumped.");
447 auto id_it =
id.begin();
450 for (
auto &p : particles) {
460 auto pos_it = pos.begin();
464 for (
auto &p : particles) {
465 std::copy_n(
pos_it, 3u, std::begin(p.pos()));
478 for (
auto &p : particles) {
488 auto vel_it = vel.begin();
492 for (
auto &p : particles) {
493 std::copy_n(
vel_it, 3u, std::begin(p.v()));
501 auto const pref_offset =
static_cast<unsigned long>(rank);
513 boost::iostreams::array_source
src(
bond.data(),
bond.size());
514 boost::iostreams::stream<boost::iostreams::array_source>
ss(
src);
515 boost::archive::binary_iarchive
ia(
ss);
517 for (
auto &p : particles) {
522 for (
auto &p : particles) {
Data structures for bonded interactions.
int number_of_partners(Bonded_IA_Parameters const &iaparams)
Get the number of bonded partners for the specified bond.
container for bonded interactions.
bool contains(key_type const &key) const
mapped_type const & at(key_type const &key) const
auto get_next_key() const
Describes a cell structure / cell system.
Particle * add_particle(Particle &&p)
Add a particle.
void remove_all_particles()
Remove all particles from the cell system.
base_type::size_type size() const
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
void errexit()
exit ungracefully, core dump if switched on.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
static unsigned long mpi_calculate_file_offset(unsigned long n_items)
Calculate the file offset on the local node.
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 std::tuple< unsigned long, unsigned long > read_prefs(const std::string &fn, int rank, int size, unsigned long nglobalpart)
Read the pref file.
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.
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 dat...
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 read_head(const std::string &fn, int rank)
Read the header file and return the first value.
void mpi_mpiio_common_read(const std::string &prefix, unsigned fields, CellStructure &cell_structure)
Parallel binary input using MPI-IO.
static void dump_info(std::string const &fn, unsigned fields, BondedInteractionsMap const &bonded_ias)
Dump the fields and bond information.
static bool fatal_error(char const *msg, std::string const &fn="", std::string const &extra="")
Fatal error handler.