9#define H5CHECK_Set DNDS_assert_info(herr >= 0, "H5 setting err")
10#define H5CHECK_Close DNDS_assert_info(herr >= 0, "H5 closing err")
11#define H5CHECK_Iter DNDS_assert_info(herr >= 0, "H5 iteration err")
15 static bool processPath(std::vector<std::string> &pth)
17 bool ifAbs = pth.empty() || pth[0].empty();
19 std::remove_if(pth.begin(), pth.end(), [](
const std::string &
v)
20 { return v.empty(); }),
26 static std::string constructPath(std::vector<std::string> &pth)
29 for (
auto &name : pth)
30 ret.append(std::string(
"/") + name);
43 static hid_t GetGroupOfFileIfExist(hid_t file_id,
bool read,
const std::string &groupName,
bool coll_on_meta)
49 bool isAbs = processPath(pth);
54 group_id = H5Gopen(file_id,
"/", H5P_DEFAULT);
57 for (
int i = 0; i < pth.size(); i++)
59 std::vector<std::string> pth_parent;
60 for (
int j = 0; j <= i; j++)
61 pth_parent.push_back(pth[j]);
62 auto parentGroupName = constructPath(pth_parent);
63 hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
66 herr = H5Pset_all_coll_metadata_ops(lapl_id,
true),
H5CHECK_Set;
67 htri_t group_exists = H5Lexists(file_id, parentGroupName.c_str(), lapl_id);
72 if (i == pth.size() - 1)
74 hid_t gapl_id = H5Pcreate(H5P_GROUP_ACCESS);
77 herr = H5Pset_all_coll_metadata_ops(gapl_id,
true),
H5CHECK_Set;
78 group_id = H5Gopen(file_id, parentGroupName.c_str(), gapl_id);
87 DNDS_assert_info(!read,
"file is read only, cannot create new group: " + groupName);
90 hid_t gapl_id = H5Pcreate(H5P_GROUP_ACCESS);
93 herr = H5Pset_all_coll_metadata_ops(gapl_id,
true),
H5CHECK_Set;
94 group_id = H5Gcreate(file_id, parentGroupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, gapl_id);
98 if (i < pth.size() - 1)
114 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
115 herr = H5Pset_fapl_mpio(plist_id, commDup, MPI_INFO_NULL),
H5CHECK_Set;
116 herr = H5Pset_all_coll_metadata_ops(plist_id,
true),
H5CHECK_Set;
117 herr = H5Pset_coll_metadata_write(plist_id,
true),
H5CHECK_Set;
119 h5file = H5Fopen(fName.c_str(), H5F_ACC_RDONLY, plist_id);
121 h5file = H5Fcreate(fName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
122 DNDS_assert_info(H5I_INVALID_HID != h5file, fmt::format(
" attempted to {} file [{}]", read ?
"read" :
"write", fName));
135 if (H5I_INVALID_HID != h5file)
136 H5Fclose(h5file), h5file = H5I_INVALID_HID;
142 bool isAbs = processPath(pth);
143 std::vector<std::string> newPath = cPathSplit;
145 newPath = std::move(pth);
147 for (
auto &name : pth)
148 newPath.push_back(name);
149 std::string nP = constructPath(cPathSplit);
150 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, nP, collectiveMetadataRW);
156 bool isAbs = processPath(pth);
158 cPathSplit = std::move(pth);
160 for (
auto &name : pth)
161 cPathSplit.push_back(name);
162 cP = constructPath(cPathSplit);
189 static herr_t link_iterate_cb(hid_t group_id,
const char *name,
const H5L_info_t *info,
void *op_data)
192 auto *data =
static_cast<TraverseData *
>(op_data);
193 bool coll_on_meta = data->coll_on_meta;
194 std::string full_name = data->current_path +
"/" + name;
197 if (info->type == H5L_TYPE_HARD)
199 data->contents.groups.push_back(name);
204 hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
206 herr = H5Pset_all_coll_metadata_ops(lapl_id,
true),
H5CHECK_Set;
209 if (H5Oget_info_by_name(group_id, name, &obj_info, H5P_DEFAULT, lapl_id) >= 0)
211 log() <<
"name is " << name <<
", \n"
212 << obj_info.type <<
"\n"
213 << obj_info.mtime <<
"\n"
214 << obj_info.rc <<
"\n"
215 << obj_info.fileno <<
"\n"
217 switch (obj_info.type)
221 data->contents.groups.push_back(name);
225 case H5O_TYPE_DATASET:
227 data->contents.datasets.push_back(name);
238 log() <<
"Error getting object info for: " << full_name << std::endl;
239 H5Eprint2(H5E_DEFAULT, stderr);
252 static herr_t attribute_iterate_cb(hid_t obj_id,
const char *attr_name,
const H5A_info_t *info,
void *op_data)
254 TraverseData *data =
static_cast<TraverseData *
>(op_data);
255 data->contents.attributes.push_back(attr_name);
263 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
267 herr = H5Aiterate(group_id, H5_INDEX_NAME, H5_ITER_INC, NULL, attribute_iterate_cb, &data),
H5CHECK_Iter;
268 herr = H5Literate(group_id, H5_INDEX_NAME, H5_ITER_INC, NULL, link_iterate_cb, &data),
H5CHECK_Iter;
270 std::set<std::string> ret;
273 for (
auto &
v : contents.
groups)
280 template <
typename T>
283 hid_t h5file,
bool reading,
const std::string &cP,
287 if constexpr (std::is_same_v<T, int>)
288 T_H5TYPE = H5T_NATIVE_INT;
289 else if constexpr (std::is_same_v<T, index>)
291 else if constexpr (std::is_same_v<T, rowsize>)
293 else if constexpr (std::is_same_v<T, real>)
295 else if constexpr (std::is_same_v<T, std::string>)
298 static_assert(std::is_same_v<T, real>);
302 if constexpr (!std::is_same_v<T, std::string>)
305 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
306 hsize_t attr_size = 1;
307 hid_t attr_space = H5Screate(H5S_SCALAR);
308 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
310 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
311 hid_t attr_id = H5Acreate(group_id, name.c_str(), T_H5TYPE, attr_space, H5P_DEFAULT, aapl_id);
312 herr = H5Awrite(attr_id, T_H5TYPE, &vV),
H5CHECK_Set;
315 H5Sclose(attr_space);
320 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
323 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
325 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
326 hid_t scalar_space = H5Screate(H5S_SCALAR);
327 hid_t string_type = H5Tcreate(H5T_STRING,
v.length());
328 herr = H5Tset_strpad(string_type, H5T_STR_NULLPAD),
H5CHECK_Set;
329 hid_t type_attr_id = H5Acreate(group_id, name.c_str(), string_type, scalar_space, H5P_DEFAULT, aapl_id);
331 herr = H5Awrite(type_attr_id, string_type,
v.data()),
H5CHECK_Set;
343 WriteAttributeScalar<int>(name,
v, h5file, reading, cP, collectiveMetadataRW);
347 WriteAttributeScalar<index>(name,
v, h5file, reading, cP, collectiveMetadataRW);
351 WriteAttributeScalar<real>(name,
v, h5file, reading, cP, collectiveMetadataRW);
355 hid_t file_dataType, hid_t mem_dataType, hid_t dxpl_id, hid_t dapl_id, int64_t chunksize,
int deflateLevel,
356 const void *buf,
int dim2 = -1)
360 fmt::format(
"{},{},{}", nGlobal,
nLocal, nOffset));
361 int rank = dim2 >= 0 ? 2 : 1;
362 std::array<hsize_t, 2> ranksFull{hsize_t(nGlobal), hsize_t(dim2)};
363 std::array<hsize_t, 2> ranksFullUnlim{chunksize > 0 ? H5S_UNLIMITED : hsize_t(nGlobal), hsize_t(dim2)};
364 std::array<hsize_t, 2> offset{hsize_t(nOffset), 0};
365 std::array<hsize_t, 2> siz{hsize_t(
nLocal), hsize_t(dim2)};
366 hid_t memSpace = H5Screate_simple(rank, siz.data(), NULL);
367 hid_t fileSpace = H5Screate_simple(rank, ranksFull.data(), ranksFullUnlim.data());
368 std::array<hsize_t, 2> chunk_dims{hsize_t(chunksize > 0 ? chunksize : 0), dim2 >= 0 ? hsize_t(dim2) : 0};
369 hid_t dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
370 if (chunk_dims[0] > 0)
371 herr = H5Pset_chunk(dcpl_id, dim2 > 0 ? 2 : 1, chunk_dims.data()),
H5CHECK_Set;
372#ifdef H5_HAVE_FILTER_DEFLATE
373 if (deflateLevel > 0)
374 herr = H5Pset_deflate(dcpl_id, deflateLevel),
H5CHECK_Set;
377 hid_t dset_id = H5Dcreate(loc, name, file_dataType, fileSpace, H5P_DEFAULT, dcpl_id, dapl_id);
379 herr = H5Sclose(fileSpace);
380 fileSpace = H5Dget_space(dset_id);
381 herr |= H5Sselect_hyperslab(fileSpace, H5S_SELECT_SET, offset.data(), NULL, siz.data(), NULL);
382 herr |= H5Dwrite(dset_id, mem_dataType, memSpace, fileSpace, dxpl_id, buf);
383 herr |= H5Dclose(dset_id);
384 herr |= H5Pclose(dcpl_id);
385 herr |= H5Sclose(fileSpace);
386 herr |= H5Sclose(memSpace);
388 "h5 error " + fmt::format(
389 "nGlobal {}, nOffset {}, nLocal {}, name {}",
390 nGlobal, nOffset,
nLocal, name));
393 template <
typename T = index>
395 static void WriteDataVector(
const std::string &name,
const T *
v,
size_t size, ArrayGlobalOffset offset, int64_t chunksize,
int deflateLevel,
396 hid_t h5file,
bool reading,
const std::string &cP,
const MPIInfo &mpi, MPI_Comm commDup,
397 bool coll_on_meta,
bool coll_on_data)
399 hid_t T_H5TYPE = H5T_NATIVE_INT;
400 if constexpr (std::is_same_v<T, index>)
402 else if constexpr (std::is_same_v<T, rowsize>)
404 else if constexpr (std::is_same_v<T, real>)
406 else if constexpr (std::is_same_v<T, uint8_t>)
407 T_H5TYPE = H5T_NATIVE_UINT8;
409 static_assert(std::is_same_v<T, uint8_t>);
412 hid_t dxpl_id = H5Pcreate(H5P_DATASET_XFER);
414 if (((offset.isDist() || offset == ArrayGlobalOffset_Parts) && (coll_on_data)) || deflateLevel > 0)
415 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE),
H5CHECK_Set;
417 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT),
H5CHECK_Set;
420 hid_t dapl_id = H5Pcreate(H5P_DATASET_ACCESS);
422 herr = H5Pset_all_coll_metadata_ops(dapl_id,
true),
H5CHECK_Set;
424 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
425 if (offset == ArrayGlobalOffset_One)
426 H5_WriteDataset(group_id, name.c_str(), size, 0,
mpi.rank == 0 ? size : 0,
427 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
429 else if (offset == ArrayGlobalOffset_Parts)
431 uint64_t sizeU{size}, sizeOff{0}, sizeGlobal{0};
432 MPI::Scan(&sizeU, &sizeOff, 1, MPI_UINT64_T, MPI_SUM, commDup);
433 sizeGlobal = sizeOff;
434 MPI::Bcast(&sizeGlobal, 1, MPI_UINT64_T,
mpi.size - 1, commDup);
437 H5_WriteDataset(group_id, name.c_str(), sizeGlobal, sizeOff, size,
438 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
441 std::array<index, 2> offsetC = {
index(sizeOff),
index(sizeGlobal)};
442 H5_WriteDataset(group_id, (name +
"::rank_offsets").c_str(),
mpi.size + 1,
mpi.rank, (
mpi.rank ==
mpi.size - 1) ? 2 : 1,
446 else if (offset.isDist())
449 H5_WriteDataset(group_id, name.c_str(), offset.size(), offset.offset(), size,
450 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
453 std::array<index, 2> offsetC = {offset.offset(), offset.size()};
454 H5_WriteDataset(group_id, (name +
"::rank_offsets").c_str(),
mpi.size + 1,
mpi.rank, (
mpi.rank ==
mpi.size - 1) ? 2 : 1,
468 WriteDataVector<index>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
472 WriteDataVector<rowsize>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
476 WriteDataVector<real>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
480 WriteAttributeScalar<std::string>(name,
v, h5file, reading, cP, collectiveMetadataRW);
491 WriteDataVector<index>(name,
v->data(),
v->size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
504 WriteDataVector<rowsize>(name,
v->data(),
v->size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
509 template <
typename T>
512 hid_t h5file,
bool reading,
const std::string &cP,
516 if constexpr (std::is_same_v<T, int>)
517 T_H5TYPE = H5T_NATIVE_INT;
518 else if constexpr (std::is_same_v<T, index>)
520 else if constexpr (std::is_same_v<T, rowsize>)
522 else if constexpr (std::is_same_v<T, real>)
524 else if constexpr (std::is_same_v<T, std::string>)
527 static_assert(std::is_same_v<T, real>);
531 if constexpr (!std::is_same_v<T, std::string>)
534 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
535 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
536 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
538 hid_t attr_id = H5Aopen(group_id, name.c_str(), aapl_id);
539 DNDS_assert_info(attr_id >= 0, fmt::format(
"attempting to open attribute [{}/{}] failed", cP, name));
540 hid_t attr_space = H5Aget_space(attr_id);
541 int ndims = H5Sget_simple_extent_ndims(attr_space);
542 DNDS_assert_info(ndims == 0, fmt::format(
"attempting to read attribute [{}/{}] which is not scalar", cP, name));
552 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
553 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
556 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
559 hid_t attr_id = H5Aopen(group_id, name.c_str(), aapl_id);
560 DNDS_assert_info(attr_id >= 0, fmt::format(
"attempting to open attribute [{}/{}] failed", cP, name));
561 hid_t attr_space = H5Aget_space(attr_id);
562 int ndims = H5Sget_simple_extent_ndims(attr_space);
563 DNDS_assert_info(ndims == 0, fmt::format(
"attempting to read attribute [{}/{}] which is not scalar", cP, name));
564 hid_t dtype_id = H5Aget_type(attr_id);
565 bool is_varlen = H5Tis_variable_str(dtype_id);
570 char *attr_value =
nullptr;
571 herr = H5Aread(attr_id, dtype_id, &attr_value),
H5CHECK_Set;
574 H5free_memory(attr_value);
579 size_t size = H5Tget_size(dtype_id);
580 std::vector<char> buffer(size + 1,
'\0');
581 herr = H5Aread(attr_id, dtype_id, buffer.data()),
H5CHECK_Set;
596 ReadAttributeScalar<int>(name,
v, h5file, reading, cP, collectiveMetadataRW);
600 ReadAttributeScalar<index>(name,
v, h5file, reading, cP, collectiveMetadataRW);
604 ReadAttributeScalar<real>(name,
v, h5file, reading, cP, collectiveMetadataRW);
629 hid_t mem_dataType, hid_t dxpl_id, hid_t dapl_id,
630 void *buf,
int &dim2)
633 hid_t dset_id = H5Dopen(loc, name, dapl_id);
634 DNDS_assert_info(dset_id >= 0, fmt::format(
"dataset [{}] open failed", name));
635 hid_t fileSpace = H5Dget_space(dset_id);
636 DNDS_assert_info(fileSpace >= 0, fmt::format(
"dataset [{}] filespace open failed", name));
637 int ndims = H5Sget_simple_extent_ndims(fileSpace);
638 DNDS_assert_info(ndims == 1 || ndims == 2, fmt::format(
"dataset [{}] not having 1 or 2 dims!", name));
639 std::array<hsize_t, 2> sizes;
640 ndims = H5Sget_simple_extent_dims(fileSpace, sizes.data(),
nullptr);
649 int rank = dim2 >= 0 ? 2 : 1;
650 std::array<hsize_t, 2> offset{hsize_t(nOffset), 0};
651 std::array<hsize_t, 2> siz{hsize_t(
nLocal), hsize_t(dim2)};
652 hid_t memSpace = H5Screate_simple(rank, siz.data(), NULL);
654 herr = H5Sselect_hyperslab(fileSpace, H5S_SELECT_SET, offset.data(), NULL, siz.data(), NULL),
H5CHECK_Set;
655 herr = H5Dread(dset_id, mem_dataType, memSpace, fileSpace, dxpl_id, buf),
H5CHECK_Set;
662 template <
typename T = index>
664 static void ReadDataVector(
const std::string &name, T *
v,
size_t &size, ArrayGlobalOffset &offset,
665 hid_t h5file,
bool reading,
const std::string &cP,
const MPIInfo &mpi,
666 bool coll_on_meta,
bool coll_on_data)
668 hid_t T_H5TYPE = H5T_NATIVE_INT;
669 if constexpr (std::is_same_v<T, index>)
671 else if constexpr (std::is_same_v<T, rowsize>)
673 else if constexpr (std::is_same_v<T, real>)
675 else if constexpr (std::is_same_v<T, uint8_t>)
676 T_H5TYPE = H5T_NATIVE_UINT8;
678 static_assert(std::is_same_v<T, uint8_t>);
681 hid_t dxpl_id = H5Pcreate(H5P_DATASET_XFER);
682 if ((offset.isDist() || offset == ArrayGlobalOffset_One) && coll_on_data)
683 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE),
H5CHECK_Set;
685 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT),
H5CHECK_Set;
688 hid_t dapl_id = H5Pcreate(H5P_DATASET_ACCESS);
691 herr = H5Pset_all_coll_metadata_ops(dapl_id, offset.isDist() || offset == ArrayGlobalOffset_One),
H5CHECK_Set;
694 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
696 if (offset == ArrayGlobalOffset_Unknown)
700 hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
703 herr = H5Pset_all_coll_metadata_ops(lapl_id, offset.isDist() || offset == ArrayGlobalOffset_One),
H5CHECK_Set;
704 htri_t exists_single = H5Lexists(group_id, name.c_str(), lapl_id);
705 htri_t exists_rank_offsets = H5Lexists(group_id, (name +
"::rank_offsets").c_str(), lapl_id);
708 if (exists_single > 0)
710 if (exists_rank_offsets > 0)
712 index nGlobal_offsets{-1};
713 int dim2_offsets{-1};
714 H5_ReadDataset(group_id, (name +
"::rank_offsets").c_str(), nGlobal_offsets, -1, -1,
DNDS_H5T_INDEX(), dxpl_id, dapl_id,
nullptr, dim2_offsets);
716 if (nGlobal_offsets ==
mpi.size + 1)
718 std::array<index, 2>
offsets = {-1, -1};
719 H5_ReadDataset(group_id, (name +
"::rank_offsets").c_str(), nGlobal_offsets,
mpi.rank, 2,
DNDS_H5T_INDEX(), dxpl_id, dapl_id,
offsets.data(), dim2_offsets);
722 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
725 offset = ArrayGlobalOffset{nGlobal,
offsets[0]};
731 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
736 DNDS_assert_info(
false,
"no valid determination; arrays of ArrayGlobalOffset_One need to be explicitly designated" +
737 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
742 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
746 if (offset == ArrayGlobalOffset_One)
752 H5_ReadDataset(group_id, name.c_str(), nGlobal, 0, size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
758 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
780 else if (offset == ArrayGlobalOffset_EvenSplit)
789 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
793 offset = ArrayGlobalOffset{
index(size), start};
797 DNDS_assert_info(offset.isDist(),
"EvenSplit second pass must have a resolved offset");
798 H5_ReadDataset(group_id, name.c_str(), nGlobal, offset.offset(), size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
802 else if (offset.isDist())
807 size = offset.size();
815 H5_ReadDataset(group_id, name.c_str(), nGlobal, offset.offset(), size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
832 ReadDataVector<index>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
834 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
835 ReadDataVector<index>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
841 ReadDataVector<rowsize>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
843 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
844 ReadDataVector<rowsize>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
850 ReadDataVector<real>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
852 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
853 ReadDataVector<real>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
857 ReadAttributeScalar<std::string>(name,
v, h5file, reading, cP, collectiveMetadataRW);
864 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
865 htri_t exists_ref = H5Aexists(group_id, (name +
"::ref").c_str());
873 refPath = cP +
"/" + name;
882 v = std::make_shared<tValue>();
887 ReadDataVector<index>(refPath,
nullptr, size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
889 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
890 ReadDataVector<index>(refPath, size == 0 ? &dummy :
v->data(), size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
898 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
899 htri_t exists_ref = H5Aexists(group_id, (name +
"::ref").c_str());
907 refPath = cP +
"/" + name;
916 v = std::make_shared<tValue>();
921 ReadDataVector<rowsize>(refPath,
nullptr, size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
923 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
924 ReadDataVector<rowsize>(refPath, size == 0 ? &dummy :
v->data(), size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
929 WriteDataVector<uint8_t>(name, data, size, offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
933 size_t size_size_t{0};
936 ReadDataVector<uint8_t>(name,
nullptr, size_size_t, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
938 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
942 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
944 ReadDataVector<uint8_t>(name, data, size_size_t, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
HDF5 native type mappings for DNDS index, rowsize, and real types.
std::vector< int64_t > offsets
Per-cell cumulative offset into connectivity.
MPI-parallel HDF5 serializer implementing the SerializerBase interface.
Describes one rank's window into a globally-distributed dataset.
void dedupRegister(const ssp< T > &v, const std::string &path)
Register a shared pointer after writing its data.
bool dedupLookup(const ssp< T > &v, std::string &outPath)
Check if a shared pointer was already written; if so return its path.
std::map< std::string, void * > pth_2_ssp
Reverse map for read-side dedup: path -> raw pointer to the ssp local variable.
void dedupClear()
Clear all dedup state (call on CloseFile).
void WriteIndex(const std::string &name, index v) override
Write a scalar index under name.
void ReadRealVector(const std::string &name, std::vector< real > &v, ArrayGlobalOffset &offset) override
std::string GetCurrentPath() override
String form of the current path.
void WriteSharedIndexVector(const std::string &name, const ssp< host_device_vector< index > > &v, ArrayGlobalOffset offset) override
Write a shared index vector; deduplicated across multiple writes that share the same shared_ptr.
void ReadSharedRowsizeVector(const std::string &name, ssp< host_device_vector< rowsize > > &v, ArrayGlobalOffset &offset) override
void ReadIndexVector(const std::string &name, std::vector< index > &v, ArrayGlobalOffset &offset) override
void ReadIndex(const std::string &name, index &v) override
Read a scalar index into v.
void WriteInt(const std::string &name, int v) override
Write a scalar int under name at the current path.
void WriteUint8Array(const std::string &name, const uint8_t *data, index size, ArrayGlobalOffset offset) override
Write a raw byte buffer under name. offset.isDist() = true means the caller provides the exact per-ra...
std::set< std::string > ListCurrentPath() override
Names of direct children of the current path.
void ReadInt(const std::string &name, int &v) override
Read a scalar int into v.
void OpenFile(const std::string &fName, bool read) override
Open a backing file (H5 file or JSON file depending on subclass).
void WriteRealVector(const std::string &name, const std::vector< real > &v, ArrayGlobalOffset offset) override
Write a real vector (collective for H5).
void GoToPath(const std::string &p) override
Navigate to an existing path. Supports / -separated segments.
void WriteReal(const std::string &name, real v) override
Write a scalar real under name.
void ReadReal(const std::string &name, real &v) override
Read a scalar real into v.
void ReadRowsizeVector(const std::string &name, std::vector< rowsize > &v, ArrayGlobalOffset &offset) override
void CloseFile() override
Close the backing file, flushing buffers.
void WriteString(const std::string &name, const std::string &v) override
Write a UTF-8 string under name.
void CreatePath(const std::string &p) override
Create a sub-path (H5 group / JSON object) at the current location.
void ReadString(const std::string &name, std::string &v) override
Read a UTF-8 string into v.
void WriteSharedRowsizeVector(const std::string &name, const ssp< host_device_vector< rowsize > > &v, ArrayGlobalOffset offset) override
Write a shared rowsize vector; deduplicated across multiple writes.
void WriteRowsizeVector(const std::string &name, const std::vector< rowsize > &v, ArrayGlobalOffset offset) override
Write a rowsize vector (collective for H5).
void CloseFileNonVirtual()
void ReadSharedIndexVector(const std::string &name, ssp< host_device_vector< index > > &v, ArrayGlobalOffset &offset) override
void WriteIndexVector(const std::string &name, const std::vector< index > &v, ArrayGlobalOffset offset) override
Write an index vector (collective for H5). offset carries the distribution mode (ArrayGlobalOffset_Pa...
void ReadUint8Array(const std::string &name, uint8_t *data, index &size, ArrayGlobalOffset &offset) override
Two-pass byte array read.
Host + optional device vector of trivially copyable T.
MPI_int Bcast(void *buf, MPI_int num, MPI_Datatype type, MPI_int source_rank, MPI_Comm comm)
dumb wrapper
MPI_int Scan(const void *sendbuf, void *recvbuf, MPI_int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
Wrapper over MPI_Scan (inclusive prefix reduction).
void AllreduceOneIndex(index &v, MPI_Op op, const MPIInfo &mpi)
Single-scalar Allreduce helper for indices (in-place, count = 1).
void WriteAttributeScalar(const std::string &name, const T &v, hid_t h5file, bool reading, const std::string &cP, bool coll_on_meta)
void ReadAttributeScalar(const std::string &name, T &v, hid_t h5file, bool reading, const std::string &cP, bool coll_on_meta)
hid_t DNDS_H5T_REAL()
HDF5 native datatype matching DNDS real (currently H5T_NATIVE_DOUBLE).
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
std::pair< index, index > EvenSplitRange(int rank, int nRanks, index nGlobal)
Split a global range [0, nGlobal) evenly among nRanks workers.
std::vector< std::string > splitSString(const std::string &str, char delim)
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
hid_t DNDS_H5T_ROWSIZE()
HDF5 native datatype matching DNDS rowsize (currently H5T_NATIVE_INT32).
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
hid_t DNDS_H5T_INDEX()
HDF5 native datatype matching DNDS index (currently H5T_NATIVE_INT64).
std::ostream & log()
Return the current DNDSR log stream (either std::cout or the installed file).
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
std::vector< std::string > attributes
std::vector< std::string > groups
std::vector< std::string > datasets
std::string get_indent() const
Eigen::Matrix< real, 5, 1 > v