#include <mpi.h>
#include <h5cpp/all>
#include <array>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int rank = 0, world_size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
char path[32];
samples[i] = double(rank) + double(i) / n_samples;
{
ds["rank"] = rank;
ds["world_size"] = world_size;
ds[
"generator"] =
std::string(
"examples-mpi-file-per-rank");
}
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) {
std::cout <<
"wrote " << world_size <<
" files: output_000.h5 .. output_"
<<
std::string(world_size < 10 ?
"00" : world_size < 100 ?
"0" :
"")
<< (world_size - 1) << ".h5\n";
}
{
bool ok = back.size() == samples.
size();
ok = (back[i] == samples[i]);
std::cout <<
"rank " << rank <<
"/" << world_size
<< " " << (ok ? "✔ ok " : "✘ failed")
<< " wrote " << back.size() << " samples to " << path << "\n";
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
h5::at_t create(const hid_t &parent, const std::string &path, args_t &&... args)
Create a new attribute of element type T on a parent HDF5 object.
Definition H5Acreate.hpp:100
T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
Read an attribute by name and return its value as type T.
Definition H5Aread.hpp:76
h5::at_t open(const hid_t &parent, const std::string &path, const h5::acpl_t &acpl=h5::default_acpl)
Open an existing attribute by name on a parent HDF5 object.
Definition H5Aopen.hpp:56
h5::gr_t write(const LOC &parent, const std::string &path, const T &src)
Write a sparse matrix or vector as a CSC group.
Definition H5Dsparse.hpp:185