QMCPACK
HDFWalkerOutput Class Reference

Writes a set of walker configurations to an HDF5 file. More...

+ Collaboration diagram for HDFWalkerOutput:

Public Member Functions

 HDFWalkerOutput (size_t num_ptcls, const std::string &fname, Communicate *c)
 constructor More...
 
 ~HDFWalkerOutput ()
 destructor More...
 
bool dump (const WalkerConfigurations &w, int block)
 dump configurations More...
 

Private Types

using BufferType = PooledData< OHMMS_PRECISION >
 PooledData<T> is used to define the shape of multi-dimensional array. More...
 

Private Member Functions

void write_configuration (const WalkerConfigurations &W, hdf_archive &hout, int block)
 

Private Attributes

bool DoNotAppend
 if true, keep it in memory More...
 
int appended_blocks
 number of blocks for append More...
 
size_t number_of_walkers_
 number of walkers when a state is dumped More...
 
const size_t number_of_particles_
 number of particles More...
 
CommunicatemyComm
 communicator More...
 
int currentConfigNumber
 
std::string RootName
 rootname More...
 
std::string prevFile
 
std::vector< Communicate::requestmyRequest
 
std::array< BufferType, 2 > RemoteData
 
std::array< std::vector< QMCTraits::FullPrecRealType >, 2 > RemoteDataW
 
int block
 

Detailed Description

Writes a set of walker configurations to an HDF5 file.

Definition at line 26 of file HDFWalkerOutput.h.

Member Typedef Documentation

◆ BufferType

PooledData<T> is used to define the shape of multi-dimensional array.

Definition at line 60 of file HDFWalkerOutput.h.

Constructor & Destructor Documentation

◆ HDFWalkerOutput()

HDFWalkerOutput ( size_t  num_ptcls,
const std::string &  fname,
Communicate c 
)

constructor

Definition at line 57 of file HDFWalkerOutput.cpp.

References HDFWalkerOutput::block.

58  : appended_blocks(0),
60  number_of_particles_(num_ptcls),
61  myComm(c),
63  RootName(aroot)
64 {
65  block = -1;
66 }
std::string RootName
rootname
const size_t number_of_particles_
number of particles
Communicate * myComm
communicator
int appended_blocks
number of blocks for append
size_t number_of_walkers_
number of walkers when a state is dumped

◆ ~HDFWalkerOutput()

~HDFWalkerOutput ( )
default

destructor

Destructor writes the state of random numbers and close the file.

Member Function Documentation

◆ dump()

bool dump ( const WalkerConfigurations W,
int  nblock 
)

dump configurations

Write the set of walker configurations to the HDF5 file.

Parameters
wwalkers
Wset of walker configurations

Dump is for restart and do not preserve the file

  • version
  • state_0
    • block (int)
    • number_of_walkers (int)
    • walker_partition (int array)
    • walkers (nw,np,3)

Definition at line 82 of file HDFWalkerOutput.cpp.

References hdf_archive::close(), qmcplusplus::hdf::config_ext, hdf_archive::create(), HDFWalkerOutput::currentConfigNumber, Communicate::getName(), qmcplusplus::hdf::main_state, HDFWalkerOutput::myComm, HDFWalkerOutput::prevFile, hdf_archive::push(), qmcplusplus::hdf::version, HDFVersion::version, hdf_archive::write(), and HDFWalkerOutput::write_configuration().

Referenced by MCWalkerConfiguration::dumpEnsemble(), and qmcplusplus::TEST_CASE().

83 {
84  std::filesystem::path FileName = myComm->getName();
85  FileName.concat(hdf::config_ext);
86  //rotate files
87  //if(!myComm->rank() && currentConfigNumber)
88  //{
89  // std::ostringstream o;
90  // o<<myComm->getName()<<".b"<<(currentConfigNumber%5) << hdf::config_ext;
91  // rename(prevFile.c_str(),o.str().c_str());
92  //}
93 
94  //try to use collective
95  hdf_archive dump_file(myComm, true);
96  dump_file.create(FileName);
97  HDFVersion cur_version;
98  dump_file.write(cur_version.version, hdf::version);
99  dump_file.push(hdf::main_state);
100  dump_file.write(nblock, "block");
101 
102  write_configuration(W, dump_file, nblock);
103  dump_file.close();
104 
106  prevFile = FileName;
107  return true;
108 }
Communicate * myComm
communicator
const std::string & getName() const
Definition: Communicate.h:131
const char config_ext[]
extension of a configuration file
Definition: HDFVersion.h:27
const char main_state[]
Definition: HDFVersion.h:31
void write_configuration(const WalkerConfigurations &W, hdf_archive &hout, int block)
const char version[]
Definition: HDFVersion.h:30

◆ write_configuration()

void write_configuration ( const WalkerConfigurations W,
hdf_archive hout,
int  block 
)
private

Definition at line 110 of file HDFWalkerOutput.cpp.

References HDFWalkerOutput::block, gatherv(), WalkerConfigurations::getActiveWalkers(), WalkerConfigurations::getWalkerOffsets(), hdf_archive::is_parallel(), HDFWalkerOutput::myComm, qmcplusplus::hdf::num_walkers, HDFWalkerOutput::number_of_particles_, HDFWalkerOutput::number_of_walkers_, OHMMS_DIM, WalkerConfigurations::putConfigurations(), Communicate::rank(), HDFWalkerOutput::RemoteData, HDFWalkerOutput::RemoteDataW, Communicate::size(), qmcplusplus::hdf::walker_weights, qmcplusplus::hdf::walkers, hdf_archive::write(), and hdf_archive::writeSlabReshaped().

Referenced by HDFWalkerOutput::dump().

111 {
112  const int wb = OHMMS_DIM * number_of_particles_;
113  if (nblock > block)
114  {
115  RemoteData[0].resize(wb * W.getActiveWalkers());
116  RemoteDataW[0].resize(W.getActiveWalkers());
117  W.putConfigurations(RemoteData[0].data(), RemoteDataW[0].data());
118  block = nblock;
119  }
120 
121  auto& walker_offsets = W.getWalkerOffsets();
122  number_of_walkers_ = walker_offsets[myComm->size()];
124 
125  if (hout.is_parallel())
126  {
127  { // write walker offset.
128  // Though it is a small array, it needs to be written collectively in large scale runs.
129  std::array<size_t, 1> gcounts{static_cast<size_t>(myComm->size()) + 1};
130  std::array<size_t, 1> counts{0};
131  std::array<size_t, 1> offsets{static_cast<size_t>(myComm->rank())};
132  std::vector<int> myWalkerOffset;
133  if (myComm->size() - 1 == myComm->rank())
134  {
135  counts[0] = 2;
136  myWalkerOffset.push_back(walker_offsets[myComm->rank()]);
137  myWalkerOffset.push_back(walker_offsets[myComm->size()]);
138  }
139  else
140  {
141  counts[0] = 1;
142  myWalkerOffset.push_back(walker_offsets[myComm->rank()]);
143  }
144  hyperslab_proxy<std::vector<int>, 1> slab(myWalkerOffset, gcounts, counts, offsets);
145  hout.write(slab, "walker_partition");
146  }
147  { // write walker configuration
148  std::array<size_t, 3> gcounts{number_of_walkers_, number_of_particles_, OHMMS_DIM};
149  std::array<size_t, 3> counts{W.getActiveWalkers(), number_of_particles_, OHMMS_DIM};
150  std::array<size_t, 3> offsets{static_cast<size_t>(walker_offsets[myComm->rank()]), 0, 0};
151  hyperslab_proxy<BufferType, 3> slab(RemoteData[0], gcounts, counts, offsets);
152  hout.write(slab, hdf::walkers);
153  }
154  {
155  std::array<size_t, 1> gcounts{number_of_walkers_};
156  std::array<size_t, 1> counts{W.getActiveWalkers()};
157  std::array<size_t, 1> offsets{static_cast<size_t>(walker_offsets[myComm->rank()])};
158  hyperslab_proxy<std::vector<QMCTraits::FullPrecRealType>, 1> slab(RemoteDataW[0], gcounts, counts, offsets);
159  hout.write(slab, hdf::walker_weights);
160  }
161  }
162  else
163  { //gaterv to the master and master writes it, could use isend/irecv
164  hout.write(walker_offsets, "walker_partition");
165  if (myComm->size() > 1)
166  {
167  std::vector<int> displ(myComm->size()), counts(myComm->size());
168  for (int i = 0; i < myComm->size(); ++i)
169  {
170  counts[i] = wb * (walker_offsets[i + 1] - walker_offsets[i]);
171  displ[i] = wb * walker_offsets[i];
172  }
173  if (!myComm->rank())
174  RemoteData[1].resize(wb * walker_offsets[myComm->size()]);
175  mpi::gatherv(*myComm, RemoteData[0], RemoteData[1], counts, displ);
176  // update counts and displ for gathering walker weights
177  for (int i = 0; i < myComm->size(); ++i)
178  {
179  counts[i] = (walker_offsets[i + 1] - walker_offsets[i]);
180  displ[i] = walker_offsets[i];
181  }
182  if (!myComm->rank())
183  RemoteDataW[1].resize(walker_offsets[myComm->size()]);
184  mpi::gatherv(*myComm, RemoteDataW[0], RemoteDataW[1], counts, displ);
185  }
186  int buffer_id = (myComm->size() > 1) ? 1 : 0;
187  {
188  std::array<size_t, 3> gcounts{number_of_walkers_, number_of_particles_, OHMMS_DIM};
189  hout.writeSlabReshaped(RemoteData[buffer_id], gcounts, hdf::walkers);
190  }
191  {
192  std::array<size_t, 1> gcounts{number_of_walkers_};
193  hout.writeSlabReshaped(RemoteDataW[buffer_id], gcounts, hdf::walker_weights);
194  }
195  }
196 }
std::array< BufferType, 2 > RemoteData
const size_t number_of_particles_
number of particles
std::array< std::vector< QMCTraits::FullPrecRealType >, 2 > RemoteDataW
int rank() const
return the rank
Definition: Communicate.h:116
Communicate * myComm
communicator
const char num_walkers[]
Definition: HDFVersion.h:37
const char walker_weights[]
Definition: HDFVersion.h:38
const char walkers[]
Definition: HDFVersion.h:36
int size() const
return the number of tasks
Definition: Communicate.h:118
#define OHMMS_DIM
Definition: config.h:64
void gatherv(T *sb, T *rb, int n, IT &counts, IT &displ, int dest)
size_t number_of_walkers_
number of walkers when a state is dumped

Member Data Documentation

◆ appended_blocks

int appended_blocks
private

number of blocks for append

Definition at line 31 of file HDFWalkerOutput.h.

◆ block

int block
private

◆ currentConfigNumber

int currentConfigNumber
private

Definition at line 42 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::dump().

◆ DoNotAppend

bool DoNotAppend
private

if true, keep it in memory

Definition at line 29 of file HDFWalkerOutput.h.

◆ myComm

Communicate* myComm
private

communicator

Definition at line 41 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::dump(), and HDFWalkerOutput::write_configuration().

◆ myRequest

std::vector<Communicate::request> myRequest
private

Definition at line 61 of file HDFWalkerOutput.h.

◆ number_of_particles_

const size_t number_of_particles_
private

number of particles

Definition at line 39 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::write_configuration().

◆ number_of_walkers_

size_t number_of_walkers_
private

number of walkers when a state is dumped

When the number of walkers per state has changed, NumOfWalkers is used to reallocate the hdf5 group.

Definition at line 37 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::write_configuration().

◆ prevFile

std::string prevFile
private

Definition at line 45 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::dump().

◆ RemoteData

std::array<BufferType, 2> RemoteData
private

Definition at line 62 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::write_configuration().

◆ RemoteDataW

std::array<std::vector<QMCTraits::FullPrecRealType>, 2> RemoteDataW
private

Definition at line 63 of file HDFWalkerOutput.h.

Referenced by HDFWalkerOutput::write_configuration().

◆ RootName

std::string RootName
private

rootname

Definition at line 44 of file HDFWalkerOutput.h.


The documentation for this class was generated from the following files: