18 #include "mpi/mpi_datatype.h" 19 #include "mpi/collectives.h" 30 : wc_list_(wc_list), num_ptcls_(num_ptcls), myComm(c), cur_version(0, 4)
43 std::string froot, cfile;
44 std::string collected(
"no");
48 pAttrib.
add(cfile,
"href");
49 pAttrib.
add(cfile,
"file");
50 pAttrib.
add(froot,
"fileroot");
51 pAttrib.
add(collected,
"collected");
58 froot.erase(froot.begin() + ext, froot.end());
76 std::array<char, 14> h5name;
77 if (std::snprintf(h5name.data(), h5name.size(),
".p%03d", pid++) < 0)
78 throw std::runtime_error(
"Error generating filename");
79 auto fname = std::filesystem::path(froot).concat(h5name.data());
88 std::array<char, 14> h5name;
89 if (std::snprintf(h5name.data(), h5name.size(),
".p%03d", pid) < 0)
90 throw std::runtime_error(
"Error generating filename");
91 auto fname = std::filesystem::path(froot).concat(h5name.data());
107 app_error() <<
" No valid input hdf5 is found." << std::endl;
131 bool success = hin.
open(h5name, H5F_ACC_RDONLY);
149 app_error() <<
" No walkers in " << h5name << std::endl;
153 using Buffer_t = std::vector<QMCTraits::RealType>;
157 std::vector<QMCTraits::FullPrecRealType> weights_in(nw_in);
160 std::vector<int> woffsets;
161 hin.
read(woffsets,
"walker_partition");
164 if (woffsets.size() != np1)
170 app_log() <<
" HDFWalkerInput_0_4::put getting " <<
dims[0] <<
" walkers " << posin.size() << std::endl;
177 auto it = posin.begin() + woffsets[
myComm->
rank()] * nitems;
178 for (
int i = 0; i < nw_in; ++i, it += nitems)
182 const auto woffset = woffsets[
myComm->
rank()];
183 for (
int i = 0; i < nw_in; ++i)
184 wc_list_[i + curWalker]->Weight = weights_in[i + woffset];
198 bool success = hin.
open(h5name, H5F_ACC_RDONLY);
220 app_error() <<
" No walkers in " << h5name << std::endl;
224 using Buffer_t = std::vector<QMCTraits::RealType>;
227 std::vector<int> woffsets_weights(np1, 0);
230 std::vector<int> counts_weights(
myComm->
size());
231 for (
int i = 0; i < counts_weights.size(); ++i)
232 counts_weights[i] = woffsets_weights[i + 1] - woffsets_weights[i];
235 std::vector<int> woffsets(np1, 0);
237 for (
int i = 0; i < woffsets.size(); ++i)
238 woffsets[i] = nitems * woffsets_weights[i];
240 for (
int i = 0; i < counts.size(); ++i)
241 counts[i] = woffsets[i + 1] - woffsets[i];
244 Buffer_t posin(nw_in * nitems);
245 std::vector<QMCTraits::FullPrecRealType> weights_in(nw_in);
246 bool has_weights{
false};
250 bool success = hin.
open(h5name, H5F_ACC_RDONLY);
257 std::vector<QMCTraits::FullPrecRealType> weights_out(counts[
myComm->
rank()]);
258 mpi::scatterv(*
myComm, posin, posout, counts, woffsets);
262 mpi::scatterv(*
myComm, weights_in, weights_out, counts_weights, woffsets_weights);
268 auto it = posout.begin();
269 for (
int i = 0; i < nw_loc; ++i, it += nitems)
272 for (
int i = 0; i < nw_in; ++i)
273 wc_list_[i + curWalker]->Weight = weights_out[i];
280 std::vector<int> woffsets;
281 int woffsets_size = 0;
282 bool success =
false;
288 success = hin.
open(h5name, H5F_ACC_RDONLY);
300 app_error() <<
" No walkers in " << h5name << std::endl;
318 hin.
read(woffsets,
"walker_partition");
319 woffsets_size = woffsets.size();
320 assert(woffsets[woffsets_size - 1] == nw_in);
324 woffsets.resize(woffsets_size);
326 nw_in = woffsets[woffsets_size - 1];
330 success = hin.
open(h5name, H5F_ACC_RDONLY);
334 using Buffer_t = std::vector<QMCTraits::RealType>;
336 std::array<size_t, 1> dims_w{nw_in};
347 std::array<size_t, 1> counts_w{nw_loc};
348 std::array<size_t, 3> offsets{
static_cast<size_t>(woffsets[
myComm->
rank()]), 0, 0};
349 std::array<size_t, 1> offsets_w{
static_cast<size_t>(woffsets[
myComm->
rank()])};
350 Buffer_t posin(nw_loc *
dims[1] *
dims[2]);
351 std::vector<QMCTraits::FullPrecRealType> weights_in(nw_loc);
359 app_log() <<
" HDFWalkerInput_0_4::put getting " <<
dims[0] <<
" walkers " << posin.size() << std::endl;
365 auto it = posin.begin();
366 for (
int i = 0; i < nw_in; ++i, it += nitems)
369 for (
int i = 0; i < nw_in; ++i)
370 wc_list_[i + curWalker]->Weight = weights_in[i];
void checkOptions(xmlNodePtr cur)
check options from xml
bool put(xmlNodePtr cur)
read walkers
bool read_hdf5_scatter(const std::filesystem::path &h5name)
read walkers.
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
std::filesystem::path FileName_noext
std::stack< std::filesystem::path > FileStack
int rank() const
return the rank
size_t getActiveWalkers() const
return the number of active walkers
class to use file space hyperslab with a serialized container
bool put(xmlNodePtr cur)
assign attributes to the set
A set of light weight walkers that are carried between driver sections and restart.
std::ostream & app_error()
const char walker_weights[]
void readSlabReshaped(T &data, const std::array< IT, RANK > &shape, const std::string &aname)
read file dataset with a specific shape into a container and check status
WalkerConfigurations & wc_list_
reference to the list of walker configurations to be read from file
int size() const
return the number of tasks
void FairDivideLow(int ntot, int npart, IV &adist)
partition ntot elements among npart
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Wrapping information on parallelism.
void bcast(T &a, Communicate *comm)
const char config_ext[]
extension of a configuration file
A collection of functions for dividing fairly.
void createWalkers(int numWalkers, size_t numPtcls)
create numWalkers Walkers
const size_t num_ptcls_
number of particles
class to handle a set of attributes of an xmlNode
HDFWalkerInput_0_4(WalkerConfigurations &wc_list, size_t num_ptcls, Communicate *c, const HDFVersion &v)
constructor
void push(const std::string &gname, bool createit=true)
push a group to the group stack
bool is_group(const std::string &aname)
check if aname is a group
bool read_hdf5(const std::filesystem::path &h5name)
read walkers for small number of MPI tasks
bool read_phdf5(const std::filesystem::path &h5name)
read walkers using PHDF5
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
T * get_first_address(ParticleAttrib< TinyVector< T, D >> &a)