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);
197 static herr_t link_iterate_cb(hid_t group_id,
const char *name,
const H5L_info_t *info,
void *op_data)
200 auto *data =
static_cast<TraverseData *
>(op_data);
201 bool coll_on_meta = data->coll_on_meta;
202 std::string full_name = data->current_path +
"/" + name;
205 if (info->type == H5L_TYPE_HARD)
207 data->contents.groups.emplace_back(name);
212 hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
214 herr = H5Pset_all_coll_metadata_ops(lapl_id,
true),
H5CHECK_Set;
217 if (H5Oget_info_by_name(group_id, name, &obj_info, H5P_DEFAULT, lapl_id) >= 0)
219 log() <<
"name is " << name <<
", \n"
220 << obj_info.type <<
"\n"
221 << obj_info.mtime <<
"\n"
222 << obj_info.rc <<
"\n"
223 << obj_info.fileno <<
"\n"
225 switch (obj_info.type)
229 data->contents.groups.emplace_back(name);
233 case H5O_TYPE_DATASET:
235 data->contents.datasets.emplace_back(name);
246 log() <<
"Error getting object info for: " << full_name << std::endl;
247 H5Eprint2(H5E_DEFAULT, stderr);
260 static herr_t attribute_iterate_cb(hid_t obj_id,
const char *attr_name,
const H5A_info_t *info,
void *op_data)
262 auto *data =
static_cast<TraverseData *
>(op_data);
263 data->contents.attributes.emplace_back(attr_name);
271 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
275 herr = H5Aiterate(group_id, H5_INDEX_NAME, H5_ITER_INC,
nullptr, attribute_iterate_cb, &data),
H5CHECK_Iter;
276 herr = H5Literate(group_id, H5_INDEX_NAME, H5_ITER_INC,
nullptr, link_iterate_cb, &data),
H5CHECK_Iter;
278 std::set<std::string> ret;
281 for (
auto &
v : contents.
groups)
288 template <
typename T>
291 hid_t h5file,
bool reading,
const std::string &cP,
295 if constexpr (std::is_same_v<T, int>)
296 T_H5TYPE = H5T_NATIVE_INT;
297 else if constexpr (std::is_same_v<T, index>)
299 else if constexpr (std::is_same_v<T, rowsize>)
301 else if constexpr (std::is_same_v<T, real>)
303 else if constexpr (std::is_same_v<T, std::string>)
306 static_assert(std::is_same_v<T, real>);
314 if constexpr (!std::is_same_v<T, std::string>)
317 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
318 hsize_t attr_size = 1;
319 hid_t attr_space = H5Screate(H5S_SCALAR);
320 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
322 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
323 hid_t attr_id = H5Acreate(group_id, name.c_str(), T_H5TYPE, attr_space, H5P_DEFAULT, aapl_id);
324 herr = H5Awrite(attr_id, T_H5TYPE, &vV),
H5CHECK_Set;
327 H5Sclose(attr_space);
332 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
335 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
337 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
338 hid_t scalar_space = H5Screate(H5S_SCALAR);
339 hid_t string_type = H5Tcreate(H5T_STRING,
v.length());
340 herr = H5Tset_strpad(string_type, H5T_STR_NULLPAD),
H5CHECK_Set;
341 hid_t type_attr_id = H5Acreate(group_id, name.c_str(), string_type, scalar_space, H5P_DEFAULT, aapl_id);
343 herr = H5Awrite(type_attr_id, string_type,
v.data()),
H5CHECK_Set;
355 WriteAttributeScalar<int>(name,
v, h5file, reading, cP, collectiveMetadataRW);
359 WriteAttributeScalar<index>(name,
v, h5file, reading, cP, collectiveMetadataRW);
363 WriteAttributeScalar<real>(name,
v, h5file, reading, cP, collectiveMetadataRW);
367 hid_t file_dataType, hid_t mem_dataType, hid_t dxpl_id, hid_t dapl_id, int64_t chunksize,
int deflateLevel,
368 const void *buf,
int dim2 = -1)
372 fmt::format(
"{},{},{}", nGlobal,
nLocal, nOffset));
373 int rank = dim2 >= 0 ? 2 : 1;
374 std::array<hsize_t, 2> ranksFull{hsize_t(nGlobal), hsize_t(dim2)};
375 std::array<hsize_t, 2> ranksFullUnlim{chunksize > 0 ? H5S_UNLIMITED : hsize_t(nGlobal), hsize_t(dim2)};
376 std::array<hsize_t, 2> offset{hsize_t(nOffset), 0};
377 std::array<hsize_t, 2> siz{hsize_t(
nLocal), hsize_t(dim2)};
378 hid_t memSpace = H5Screate_simple(rank, siz.data(),
nullptr);
379 hid_t fileSpace = H5Screate_simple(rank, ranksFull.data(), ranksFullUnlim.data());
380 std::array<hsize_t, 2> chunk_dims{hsize_t(chunksize > 0 ? chunksize : 0), dim2 >= 0 ? hsize_t(dim2) : 0};
381 hid_t dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
382 if (chunk_dims[0] > 0)
383 herr = H5Pset_chunk(dcpl_id, dim2 > 0 ? 2 : 1, chunk_dims.data()),
H5CHECK_Set;
384#ifdef H5_HAVE_FILTER_DEFLATE
385 if (deflateLevel > 0)
386 herr = H5Pset_deflate(dcpl_id, deflateLevel),
H5CHECK_Set;
389 hid_t dset_id = H5Dcreate(loc, name, file_dataType, fileSpace, H5P_DEFAULT, dcpl_id, dapl_id);
391 herr = H5Sclose(fileSpace);
392 fileSpace = H5Dget_space(dset_id);
393 herr |= H5Sselect_hyperslab(fileSpace, H5S_SELECT_SET, offset.data(),
nullptr, siz.data(),
nullptr);
394 herr |= H5Dwrite(dset_id, mem_dataType, memSpace, fileSpace, dxpl_id, buf);
395 herr |= H5Dclose(dset_id);
396 herr |= H5Pclose(dcpl_id);
397 herr |= H5Sclose(fileSpace);
398 herr |= H5Sclose(memSpace);
400 "h5 error " + fmt::format(
401 "nGlobal {}, nOffset {}, nLocal {}, name {}",
402 nGlobal, nOffset,
nLocal, name));
405 template <
typename T = index>
407 static void WriteDataVector(
const std::string &name,
const T *
v,
size_t size, ArrayGlobalOffset offset, int64_t chunksize,
int deflateLevel,
408 hid_t h5file,
bool reading,
const std::string &cP,
const MPIInfo &mpi, MPI_Comm commDup,
409 bool coll_on_meta,
bool coll_on_data)
411 hid_t T_H5TYPE = H5T_NATIVE_INT;
412 if constexpr (std::is_same_v<T, index>)
414 else if constexpr (std::is_same_v<T, rowsize>)
416 else if constexpr (std::is_same_v<T, real>)
418 else if constexpr (std::is_same_v<T, uint8_t>)
419 T_H5TYPE = H5T_NATIVE_UINT8;
421 static_assert(std::is_same_v<T, uint8_t>);
424 hid_t dxpl_id = H5Pcreate(H5P_DATASET_XFER);
426 if (((offset.isDist() || offset == ArrayGlobalOffset_Parts) && (coll_on_data)) || deflateLevel > 0)
427 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE),
H5CHECK_Set;
429 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT),
H5CHECK_Set;
432 hid_t dapl_id = H5Pcreate(H5P_DATASET_ACCESS);
434 herr = H5Pset_all_coll_metadata_ops(dapl_id,
true),
H5CHECK_Set;
436 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
437 if (offset == ArrayGlobalOffset_One)
438 H5_WriteDataset(group_id, name.c_str(), size, 0,
mpi.rank == 0 ? size : 0,
439 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
441 else if (offset == ArrayGlobalOffset_Parts)
443 uint64_t sizeU{size}, sizeOff{0}, sizeGlobal{0};
444 MPI::Scan(&sizeU, &sizeOff, 1, MPI_UINT64_T, MPI_SUM, commDup);
445 sizeGlobal = sizeOff;
446 MPI::Bcast(&sizeGlobal, 1, MPI_UINT64_T,
mpi.size - 1, commDup);
449 H5_WriteDataset(group_id, name.c_str(), sizeGlobal, sizeOff, size,
450 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
453 std::array<index, 2> offsetC = {
index(sizeOff),
index(sizeGlobal)};
454 H5_WriteDataset(group_id, (name +
"::rank_offsets").c_str(),
mpi.size + 1,
mpi.rank, (
mpi.rank ==
mpi.size - 1) ? 2 : 1,
458 else if (offset.isDist())
461 H5_WriteDataset(group_id, name.c_str(), offset.size(), offset.offset(), size,
462 T_H5TYPE, T_H5TYPE, dxpl_id, dapl_id, chunksize, deflateLevel,
465 std::array<index, 2> offsetC = {offset.offset(), offset.size()};
466 H5_WriteDataset(group_id, (name +
"::rank_offsets").c_str(),
mpi.size + 1,
mpi.rank, (
mpi.rank ==
mpi.size - 1) ? 2 : 1,
480 WriteDataVector<index>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
484 WriteDataVector<rowsize>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
488 WriteDataVector<real>(name,
v.data(),
v.size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
492 WriteAttributeScalar<std::string>(name,
v, h5file, reading, cP, collectiveMetadataRW);
503 WriteDataVector<index>(name,
v->data(),
v->size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
516 WriteDataVector<rowsize>(name,
v->data(),
v->size(), offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
521 template <
typename T>
524 hid_t h5file,
bool reading,
const std::string &cP,
528 if constexpr (std::is_same_v<T, int>)
529 T_H5TYPE = H5T_NATIVE_INT;
530 else if constexpr (std::is_same_v<T, index>)
532 else if constexpr (std::is_same_v<T, rowsize>)
534 else if constexpr (std::is_same_v<T, real>)
536 else if constexpr (std::is_same_v<T, std::string>)
539 static_assert(std::is_same_v<T, real>);
547 if constexpr (!std::is_same_v<T, std::string>)
550 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
551 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
552 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
554 hid_t attr_id = H5Aopen(group_id, name.c_str(), aapl_id);
555 DNDS_assert_info(attr_id >= 0, fmt::format(
"attempting to open attribute [{}/{}] failed", cP, name));
556 hid_t attr_space = H5Aget_space(attr_id);
557 int ndims = H5Sget_simple_extent_ndims(attr_space);
558 DNDS_assert_info(ndims == 0, fmt::format(
"attempting to read attribute [{}/{}] which is not scalar", cP, name));
568 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
569 hid_t aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
572 herr = H5Pset_all_coll_metadata_ops(aapl_id,
true),
H5CHECK_Set;
575 hid_t attr_id = H5Aopen(group_id, name.c_str(), aapl_id);
576 DNDS_assert_info(attr_id >= 0, fmt::format(
"attempting to open attribute [{}/{}] failed", cP, name));
577 hid_t attr_space = H5Aget_space(attr_id);
578 int ndims = H5Sget_simple_extent_ndims(attr_space);
579 DNDS_assert_info(ndims == 0, fmt::format(
"attempting to read attribute [{}/{}] which is not scalar", cP, name));
580 hid_t dtype_id = H5Aget_type(attr_id);
581 bool is_varlen = H5Tis_variable_str(dtype_id);
586 char *attr_value =
nullptr;
591 herr = H5Aread(attr_id, dtype_id, &attr_value),
H5CHECK_Set;
594 H5free_memory(attr_value);
599 size_t size = H5Tget_size(dtype_id);
600 std::vector<char> buffer(size + 1,
'\0');
601 herr = H5Aread(attr_id, dtype_id, buffer.data()),
H5CHECK_Set;
616 ReadAttributeScalar<int>(name,
v, h5file, reading, cP, collectiveMetadataRW);
620 ReadAttributeScalar<index>(name,
v, h5file, reading, cP, collectiveMetadataRW);
624 ReadAttributeScalar<real>(name,
v, h5file, reading, cP, collectiveMetadataRW);
649 hid_t mem_dataType, hid_t dxpl_id, hid_t dapl_id,
650 void *buf,
int &dim2)
653 hid_t dset_id = H5Dopen(loc, name, dapl_id);
654 DNDS_assert_info(dset_id >= 0, fmt::format(
"dataset [{}] open failed", name));
655 hid_t fileSpace = H5Dget_space(dset_id);
656 DNDS_assert_info(fileSpace >= 0, fmt::format(
"dataset [{}] filespace open failed", name));
657 int ndims = H5Sget_simple_extent_ndims(fileSpace);
658 DNDS_assert_info(ndims == 1 || ndims == 2, fmt::format(
"dataset [{}] not having 1 or 2 dims!", name));
659 std::array<hsize_t, 2> sizes{};
660 ndims = H5Sget_simple_extent_dims(fileSpace, sizes.data(),
nullptr);
669 int rank = dim2 >= 0 ? 2 : 1;
670 std::array<hsize_t, 2> offset{hsize_t(nOffset), 0};
671 std::array<hsize_t, 2> siz{hsize_t(
nLocal), hsize_t(dim2)};
672 hid_t memSpace = H5Screate_simple(rank, siz.data(),
nullptr);
674 herr = H5Sselect_hyperslab(fileSpace, H5S_SELECT_SET, offset.data(),
nullptr, siz.data(),
nullptr),
H5CHECK_Set;
675 herr = H5Dread(dset_id, mem_dataType, memSpace, fileSpace, dxpl_id, buf),
H5CHECK_Set;
682 template <
typename T = index>
684 static void ReadDataVector(
const std::string &name, T *
v,
size_t &size, ArrayGlobalOffset &offset,
685 hid_t h5file,
bool reading,
const std::string &cP,
const MPIInfo &mpi,
686 bool coll_on_meta,
bool coll_on_data)
688 hid_t T_H5TYPE = H5T_NATIVE_INT;
689 if constexpr (std::is_same_v<T, index>)
691 else if constexpr (std::is_same_v<T, rowsize>)
693 else if constexpr (std::is_same_v<T, real>)
695 else if constexpr (std::is_same_v<T, uint8_t>)
696 T_H5TYPE = H5T_NATIVE_UINT8;
698 static_assert(std::is_same_v<T, uint8_t>);
701 hid_t dxpl_id = H5Pcreate(H5P_DATASET_XFER);
702 if ((offset.isDist() || offset == ArrayGlobalOffset_One) && coll_on_data)
703 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE),
H5CHECK_Set;
705 herr = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT),
H5CHECK_Set;
708 hid_t dapl_id = H5Pcreate(H5P_DATASET_ACCESS);
711 herr = H5Pset_all_coll_metadata_ops(dapl_id, offset.isDist() || offset == ArrayGlobalOffset_One),
H5CHECK_Set;
714 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, coll_on_meta);
716 if (offset == ArrayGlobalOffset_Unknown)
720 hid_t lapl_id = H5Pcreate(H5P_LINK_ACCESS);
723 herr = H5Pset_all_coll_metadata_ops(lapl_id, offset.isDist() || offset == ArrayGlobalOffset_One),
H5CHECK_Set;
724 htri_t exists_single = H5Lexists(group_id, name.c_str(), lapl_id);
725 htri_t exists_rank_offsets = H5Lexists(group_id, (name +
"::rank_offsets").c_str(), lapl_id);
728 if (exists_single > 0)
730 if (exists_rank_offsets > 0)
732 index nGlobal_offsets{-1};
733 int dim2_offsets{-1};
734 H5_ReadDataset(group_id, (name +
"::rank_offsets").c_str(), nGlobal_offsets, -1, -1,
DNDS_H5T_INDEX(), dxpl_id, dapl_id,
nullptr, dim2_offsets);
736 if (nGlobal_offsets ==
mpi.size + 1)
738 std::array<index, 2>
offsets = {-1, -1};
739 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);
742 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
745 offset = ArrayGlobalOffset{nGlobal,
offsets[0]};
751 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
756 DNDS_assert_info(
false,
"no valid determination; arrays of ArrayGlobalOffset_One need to be explicitly designated" +
757 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
762 fmt::format(
" [{} {}], ", exists_single, exists_rank_offsets) + name);
766 if (offset == ArrayGlobalOffset_One)
772 H5_ReadDataset(group_id, name.c_str(), nGlobal, 0, size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
778 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
800 else if (offset == ArrayGlobalOffset_EvenSplit)
809 H5_ReadDataset(group_id, name.c_str(), nGlobal, -1, -1, T_H5TYPE, dxpl_id, dapl_id,
nullptr, dim2);
813 offset = ArrayGlobalOffset{
index(size), start};
817 DNDS_assert_info(offset.isDist(),
"EvenSplit second pass must have a resolved offset");
818 H5_ReadDataset(group_id, name.c_str(), nGlobal, offset.offset(), size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
822 else if (offset.isDist())
827 size = offset.size();
835 H5_ReadDataset(group_id, name.c_str(), nGlobal, offset.offset(), size, T_H5TYPE, dxpl_id, dapl_id,
v, dim2);
852 ReadDataVector<index>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
854 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
855 ReadDataVector<index>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
861 ReadDataVector<rowsize>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
863 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
864 ReadDataVector<rowsize>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
870 ReadDataVector<real>(name,
nullptr, size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
872 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
873 ReadDataVector<real>(name, size == 0 ? &dummy :
v.data(), size, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
877 ReadAttributeScalar<std::string>(name,
v, h5file, reading, cP, collectiveMetadataRW);
884 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
885 htri_t exists_ref = H5Aexists(group_id, (name +
"::ref").c_str());
893 refPath = cP +
"/" + name;
904 v = std::make_shared<tValue>();
909 ReadDataVector<index>(refPath,
nullptr, size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
911 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
912 ReadDataVector<index>(refPath, size == 0 ? &dummy :
v->data(), size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
920 hid_t group_id = GetGroupOfFileIfExist(h5file, reading, cP, collectiveMetadataRW);
921 htri_t exists_ref = H5Aexists(group_id, (name +
"::ref").c_str());
929 refPath = cP +
"/" + name;
940 v = std::make_shared<tValue>();
945 ReadDataVector<rowsize>(refPath,
nullptr, size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
947 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
948 ReadDataVector<rowsize>(refPath, size == 0 ? &dummy :
v->data(), size, offset, h5file, reading,
"/", mpi, collectiveMetadataRW, collectiveDataRW);
953 WriteDataVector<uint8_t>(name, data, size, offset, chunksize, deflateLevel, h5file, reading, cP, mpi, commDup, collectiveMetadataRW, collectiveDataRW);
957 size_t size_size_t{0};
960 ReadDataVector<uint8_t>(name,
nullptr, size_size_t, offset, h5file, reading, cP, mpi, collectiveMetadataRW, collectiveDataRW);
962 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
966 DNDS_assert(!(offset == ArrayGlobalOffset_Unknown));
968 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
const tPoint const tPoint const tPoint & p