#include <mpi.h>
#include <h5cpp/all>
#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);
constexpr int nrows = 10;
{
auto fd =
h5::create(
"collective.h5", H5F_ACC_TRUNC, h5::default_fcpl,
h5::current_dims{nrows, world_size},
h5::offset{0, rank},
h5::count{nrows, 1},
}
{
auto fd =
h5::open(
"collective.h5", H5F_ACC_RDWR,
std::cout <<
"rank " << rank <<
" of " << world_size
<< " read " << data.size() << " elements, first = " << data[0] << "\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
std::enable_if_t<!std::is_same_v< T, char ** >, void > read(const h5::ds_t &ds, T *ptr, args_t &&... args)
Read elements from an open HDF5 dataset into caller-allocated memory.
Definition H5Dread.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