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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14
15
16 #include "SkEstimator_CUDA.h"
17 #include "Particle/MCWalkerConfiguration.h"
18 #include "QMCDrivers/WalkerProperties.h"
19
20 namespace qmcplusplus
21 {
22 using WP = WalkerProperties::Indexes;
23
addEnergy(MCWalkerConfiguration & W,std::vector<RealType> & LocalEnergy)24 void SkEstimator_CUDA::addEnergy(MCWalkerConfiguration& W, std::vector<RealType>& LocalEnergy)
25 {
26 int nw = W.WalkerList.size();
27 gpu::host_vector<CUDA_PRECISION_FULL> rhok_host;
28 int stride = (int)(W.WalkerList[0]->get_rhok_ptr(1) - W.WalkerList[0]->get_rhok_ptr(0));
29 RealType OneOverNW = 1.0 / (RealType)nw;
30 std::vector<CUDA_PRECISION> rhok_total(2 * NumK, 0.0);
31 for (int iw = 0; iw < nw; iw++)
32 {
33 Walker_t& walker = *(W.WalkerList[iw]);
34 rhok_host = walker.Rhok_GPU;
35 fill(rhok_total.begin(), rhok_total.end(), 0.0);
36 for (int isp = 0; isp < NumSpecies; isp++)
37 for (int ik = 0; ik < 2 * NumK; ik++)
38 rhok_total[ik] += rhok_host[ik + isp * stride];
39 if (hdf5_out)
40 {
41 for (int ik = 0; ik < NumK; ik++)
42 W.Collectables[myIndex + ik] += OneOverN * OneOverNW *
43 (rhok_total[2 * ik + 0] * rhok_total[2 * ik + 0] + rhok_total[2 * ik + 1] * rhok_total[2 * ik + 1]);
44 }
45 else
46 {
47 for (int ik = 0; ik < NumK; ik++)
48 W.WalkerList[iw]->getPropertyBase()[WP::NUMPROPERTIES + myIndex + ik] = OneOverN *
49 (rhok_total[2 * ik + 0] * rhok_total[2 * ik + 0] + rhok_total[2 * ik + 1] * rhok_total[2 * ik + 1]);
50 }
51 }
52 }
53 } // namespace qmcplusplus
54