QMCPACK
OperatorEstBase.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File refactored from: OperatorBase.cpp
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 /**@file
13  */
14 #include "Message/Communicate.h"
15 #include "OperatorEstBase.h"
17 
18 namespace qmcplusplus
19 {
20 OperatorEstBase::OperatorEstBase(DataLocality dl) : data_locality_(dl), walkers_weight_(0) {}
21 
23  : data_locality_(oth.data_locality_), my_name_(oth.my_name_), walkers_weight_(0)
24 {}
25 
26 void OperatorEstBase::collect(const RefVector<OperatorEstBase>& type_erased_operator_estimators)
27 {
28  for (OperatorEstBase& crowd_oeb : type_erased_operator_estimators)
29  {
30  std::transform(data_.begin(), data_.end(), crowd_oeb.get_data().begin(), data_.begin(), std::plus<>{});
31  walkers_weight_ += crowd_oeb.walkers_weight_;
32  crowd_oeb.zero();
33  }
34 }
35 
37 {
38  for (QMCT::RealType& elem : data_)
39  elem *= invTotWgt;
40 }
41 
43 {
44  if (h5desc_.empty())
45  return;
46  // We have to do this to deal with the legacy design that Observables using
47  // collectables in mixed precision were accumulated in float but always written
48  // to hdf5 in double.
49 #ifdef MIXED_PRECISION
50  std::vector<QMCT::FullPrecRealType> expanded_data(data_.size(), 0.0);
51  std::copy_n(data_.begin(), data_.size(), expanded_data.begin());
52  assert(!data_.empty());
53  // auto total = std::accumulate(data_->begin(), data_->end(), 0.0);
54  // std::cout << "data size: " << data_->size() << " : " << total << '\n';
55  for (auto& h5d : h5desc_)
56  h5d.write(expanded_data.data(), file);
57 #else
58  for (auto& h5d : h5desc_)
59  h5d.write(data_.data(), file);
60 #endif
61  file.pop();
62 }
63 
65 {
67  std::fill(data_.begin(), data_.end(), 0.0);
68  else
69  data_.clear();
70  walkers_weight_ = 0;
71 }
72 
73 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
std::vector< ObservableHelper > h5desc_
virtual void normalize(QMCT::RealType invToWgt)
class to handle hdf file
Definition: hdf_archive.h:51
DataLocality data_locality_
locality for accumulation of estimator data.
QMCT::FullPrecRealType walkers_weight_
OperatorEstBase(DataLocality dl)
constructor
void zero()
zero data appropriately for the DataLocality
An abstract class for gridded estimators.
std::vector< std::reference_wrapper< T > > RefVector
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
Definition: syclBLAS.cpp:548
DataLocality
data locality with respect to walker buffer
Definition: DataLocality.h:19
void write(hdf_archive &file)
Write to previously registered observable_helper hdf5 wrapper.
Declaration of QMCHamiltonian.
virtual void collect(const RefVector< OperatorEstBase > &oebs)
Reduce estimator result data from crowds to rank.