Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 64 additions & 27 deletions src/Particle/HDFWalkerInput_0_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,19 @@ bool HDFWalkerInput_0_4::read_hdf5(const std::filesystem::path& h5name)
size_t nw_in = 0;

hdf_archive hin(myComm, false); //everone reads this
bool success = hin.open(h5name, H5F_ACC_RDONLY);
if (!hin.open(h5name, H5F_ACC_RDONLY))
return false;
//check if hdf and xml versions can work together
HDFVersion aversion;

hin.read(aversion, hdf::version);
if (!(aversion < i_info.version))
{
int found_group = hin.is_group(hdf::main_state);
if (!hin.is_group(hdf::main_state))
{
app_error() << " HDF5 group " << hdf::main_state << " not found in " << h5name << std::endl;
return false;
}
hin.push(hdf::main_state);
hin.read(nw_in, hdf::num_walkers);
}
Expand Down Expand Up @@ -192,27 +197,40 @@ bool HDFWalkerInput_0_4::read_hdf5_scatter(const std::filesystem::path& h5name)
{
size_t nw_in = 0;

bool success = false;
if (myComm->rank() == 0)
{
hdf_archive hin(myComm); //everone reads this
bool success = hin.open(h5name, H5F_ACC_RDONLY);
//check if hdf and xml versions can work together
HDFVersion aversion;

hin.read(aversion, hdf::version);
if (!(aversion < i_info.version))
success = hin.open(h5name, H5F_ACC_RDONLY);
if (success)
{
int found_group = hin.is_group(hdf::main_state);
hin.push(hdf::main_state);
hin.read(nw_in, hdf::num_walkers);
}
else
{
app_error() << " Mismatched version. xml = " << i_info.version << " hdf = " << aversion << std::endl;
//check if hdf and xml versions can work together
HDFVersion aversion;

hin.read(aversion, hdf::version);
if (!(aversion < i_info.version))
{
if (!hin.is_group(hdf::main_state))
{
app_error() << " HDF5 group " << hdf::main_state << " not found in " << h5name << std::endl;
success = false;
}
else
{
hin.push(hdf::main_state);
hin.read(nw_in, hdf::num_walkers);
}
}
else
{
app_error() << " Mismatched version. xml = " << i_info.version << " hdf = " << aversion << std::endl;
}
}
}

myComm->barrier();
mpi::bcast(*myComm, success);
if (!success)
return false;
mpi::bcast(*myComm, nw_in);

if (nw_in == 0)
Expand Down Expand Up @@ -244,14 +262,21 @@ bool HDFWalkerInput_0_4::read_hdf5_scatter(const std::filesystem::path& h5name)
Buffer_t posin(nw_in * nitems);
std::vector<QMCTraits::FullPrecRealType> weights_in(nw_in);
bool has_weights{false};
bool success2 = false;
if (myComm->rank() == 0)
{
hdf_archive hin(myComm);
bool success = hin.open(h5name, H5F_ACC_RDONLY);
hin.push(hdf::main_state);
hin.readSlabReshaped(posin, dims, hdf::walkers);
has_weights = hin.readEntry(weights_in, hdf::walker_weights);
success2 = hin.open(h5name, H5F_ACC_RDONLY);
if (success2)
{
hin.push(hdf::main_state);
hin.readSlabReshaped(posin, dims, hdf::walkers);
has_weights = hin.readEntry(weights_in, hdf::walker_weights);
}
}
mpi::bcast(*myComm, success2);
if (!success2)
return false;

Buffer_t posout(counts[myComm->rank()]);
std::vector<QMCTraits::FullPrecRealType> weights_out(counts[myComm->rank()]);
Expand Down Expand Up @@ -292,14 +317,21 @@ bool HDFWalkerInput_0_4::read_phdf5(const std::filesystem::path& h5name)
hin.read(aversion, hdf::version);
if (!(aversion < i_info.version))
{
int found_group = hin.is_group(hdf::main_state);
hin.push(hdf::main_state);
hin.read(nw_in, hdf::num_walkers);
if (nw_in == 0)
if (!hin.is_group(hdf::main_state))
{
app_error() << " No walkers in " << h5name << std::endl;
app_error() << " HDF5 group " << hdf::main_state << " not found in " << h5name << std::endl;
success = false;
}
else
{
hin.push(hdf::main_state);
hin.read(nw_in, hdf::num_walkers);
if (nw_in == 0)
{
app_error() << " No walkers in " << h5name << std::endl;
success = false;
}
}
}
else
{
Expand Down Expand Up @@ -327,8 +359,13 @@ bool HDFWalkerInput_0_4::read_phdf5(const std::filesystem::path& h5name)
}

hdf_archive hin(myComm, true); //everone reads this
success = hin.open(h5name, H5F_ACC_RDONLY);
int found_group = hin.is_group(hdf::main_state);
if (!hin.open(h5name, H5F_ACC_RDONLY))
return false;
if (!hin.is_group(hdf::main_state))
{
app_error() << " HDF5 group " << hdf::main_state << " not found in " << h5name << std::endl;
return false;
}
hin.push(hdf::main_state);

using Buffer_t = std::vector<QMCTraits::RealType>;
Expand Down
51 changes: 35 additions & 16 deletions src/io/hdf/hdf_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ void hdf_archive::create_basic_plist()
H5Pclose(file_cpl_);
throw std::runtime_error("hdf_archive failed to create link create properties!");
}
H5Pset_create_intermediate_group(lcpl_id, true);
if (H5Pset_create_intermediate_group(lcpl_id, true) < 0)
{
H5Pclose(file_apl_);
H5Pclose(file_cpl_);
H5Pclose(lcpl_id);
throw std::runtime_error("hdf_archive failed to set link create properties!");
}
xfer_plist = H5Pcreate(H5P_DATASET_XFER);
if (xfer_plist == H5I_INVALID_HID)
{
Expand All @@ -98,11 +104,16 @@ void hdf_archive::set_access_plist(Communicate* comm, bool request_pio)
// This in needed as well other resulting logic to support the unlikely
// optimization of using the global H5P_DEFAULT instead of just
// having hdf_archive own its access plist.
H5Pset_all_coll_metadata_ops(file_apl_, true);
H5Pset_coll_metadata_write(file_apl_, true);
H5Pset_fapl_mpio(file_apl_, comm->getMPI(), info);
// enable parallel collective I/O
H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
if (H5Pset_all_coll_metadata_ops(file_apl_, true) < 0 || H5Pset_coll_metadata_write(file_apl_, true) < 0 ||
H5Pset_fapl_mpio(file_apl_, comm->getMPI(), info) < 0 ||
H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE) < 0)
{
H5Pclose(file_apl_);
H5Pclose(file_cpl_);
H5Pclose(lcpl_id);
H5Pclose(xfer_plist);
throw std::runtime_error("hdf_archive failed to set parallel HDF5 properties!");
}
use_phdf5 = true;
}
#endif
Expand Down Expand Up @@ -133,11 +144,15 @@ void hdf_archive::set_access_plist(boost::mpi3::communicator& comm, bool request
#if defined(ENABLE_PHDF5)
// enable parallel I/O
MPI_Info info = MPI_INFO_NULL;
H5Pset_all_coll_metadata_ops(file_apl_, true);
H5Pset_coll_metadata_write(file_apl_, true);
H5Pset_fapl_mpio(file_apl_, comm.get(), info);
// enable parallel collective I/O
H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
if (H5Pset_all_coll_metadata_ops(file_apl_, true) < 0 || H5Pset_coll_metadata_write(file_apl_, true) < 0 ||
H5Pset_fapl_mpio(file_apl_, comm.get(), info) < 0 || H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE) < 0)
{
H5Pclose(file_apl_);
H5Pclose(file_cpl_);
H5Pclose(lcpl_id);
H5Pclose(xfer_plist);
throw std::runtime_error("hdf_archive failed to set parallel HDF5 properties!");
}
use_phdf5 = true;
#else
use_phdf5 = false;
Expand Down Expand Up @@ -198,13 +213,14 @@ bool hdf_archive::is_group(const std::string& aname)
H5O_info_t oinfo;
#endif
oinfo.type = H5O_TYPE_UNKNOWN;
herr_t status;
#if H5_VERSION_GE(1, 12, 0)
H5Oget_info_by_name3(p, aname.c_str(), &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
status = H5Oget_info_by_name3(p, aname.c_str(), &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
#else
H5Oget_info_by_name(p, aname.c_str(), &oinfo, H5P_DEFAULT);
status = H5Oget_info_by_name(p, aname.c_str(), &oinfo, H5P_DEFAULT);
#endif

if (oinfo.type != H5O_TYPE_GROUP)
if (status < 0 || oinfo.type != H5O_TYPE_GROUP)
return false;
return true;
}
Expand Down Expand Up @@ -234,11 +250,14 @@ void hdf_archive::push(const std::string& gname, bool createit)
oinfo.type = H5O_TYPE_UNKNOWN;
if (H5Lexists(p, gname.c_str(), H5P_DEFAULT) > 0)
{
herr_t status;
#if H5_VERSION_GE(1, 12, 0)
H5Oget_info_by_name3(p, gname.c_str(), &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
status = H5Oget_info_by_name3(p, gname.c_str(), &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
#else
H5Oget_info_by_name(p, gname.c_str(), &oinfo, H5P_DEFAULT);
status = H5Oget_info_by_name(p, gname.c_str(), &oinfo, H5P_DEFAULT);
#endif
if (status < 0)
oinfo.type = H5O_TYPE_UNKNOWN;
}

if ((oinfo.type != H5O_TYPE_GROUP) && createit)
Expand Down
11 changes: 2 additions & 9 deletions src/io/hdf/hdf_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class hdf_archive
inline void flush()
{
if (file_id != is_closed)
H5Fflush(file_id, H5F_SCOPE_LOCAL);
if (H5Fflush(file_id, H5F_SCOPE_LOCAL) < 0)
throw std::runtime_error("H5Fflush failed.");
}

///return true if the file is closed
Expand Down Expand Up @@ -414,14 +415,6 @@ class hdf_archive
hyperslab_proxy<T, RANK> pxy(data, globals, counts, offsets);
read(pxy, aname);
}

inline void unlink(const std::string& aname)
{
if (Mode[NOIO])
return;
hid_t p = group_id.empty() ? file_id : group_id.top();
herr_t status = H5Ldelete(p, aname.c_str(), H5P_DEFAULT);
}
};

} // namespace qmcplusplus
Expand Down
Loading
Loading