QMCPACK
SoaDistanceTableAB.h
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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
8 // Amrita Mathuriya, amrita.mathuriya@intel.com, Intel Corp.
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
11 //////////////////////////////////////////////////////////////////////////////////////
12 // -*- C++ -*-
13 #ifndef QMCPLUSPLUS_DTDIMPL_AB_H
14 #define QMCPLUSPLUS_DTDIMPL_AB_H
15 
17 #include "Utilities/FairDivide.h"
18 #include "Concurrency/OpenMP.h"
19 
20 namespace qmcplusplus
21 {
22 /**@ingroup nnlist
23  * @brief A derived classe from DistacneTableData, specialized for AB using a transposed form
24  */
25 template<typename T, unsigned D, int SC>
26 struct SoaDistanceTableAB : public DTD_BConds<T, D, SC>, public DistanceTableAB
27 {
28  SoaDistanceTableAB(const ParticleSet& source, ParticleSet& target)
29  : DTD_BConds<T, D, SC>(source.getLattice()),
30  DistanceTableAB(source, target, DTModes::ALL_OFF),
31  evaluate_timer_(createGlobalTimer(std::string("DTAB::evaluate_") + target.getName() + "_" + source.getName(),
33  move_timer_(createGlobalTimer(std::string("DTAB::move_") + target.getName() + "_" + source.getName(),
35  update_timer_(createGlobalTimer(std::string("DTAB::update_") + target.getName() + "_" + source.getName(),
37  {
38  resize();
39  }
40 
41  void resize()
42  {
43  if (num_sources_ * num_targets_ == 0)
44  return;
45 
46  // initialize memory containers and views
47  const int num_sources_padded = getAlignedSize<T>(num_sources_);
48  distances_.resize(num_targets_);
50  for (int i = 0; i < num_targets_; ++i)
51  {
52  distances_[i].resize(num_sources_padded);
53  displacements_[i].resize(num_sources_padded);
54  }
55 
56  // The padding of temp_r_ and temp_dr_ is necessary for the memory copy in the update function
57  // temp_r_ is padded explicitly while temp_dr_ is padded internally
58  temp_r_.resize(num_sources_padded);
60  }
61 
62  SoaDistanceTableAB() = delete;
63  SoaDistanceTableAB(const SoaDistanceTableAB&) = delete;
64 
65  /** evaluate the full table */
66  inline void evaluate(ParticleSet& P) override
67  {
68  ScopedTimer local_timer(evaluate_timer_);
69 #pragma omp parallel
70  {
71  int first, last;
72  FairDivideAligned(num_sources_, getAlignment<T>(), omp_get_num_threads(), omp_get_thread_num(), first, last);
73 
74  //be aware of the sign of Displacement
75  for (int iat = 0; iat < num_targets_; ++iat)
77  distances_[iat].data(), displacements_[iat], first, last);
78  }
79  }
80 
81  ///evaluate the temporary pair relations
82  inline void move(const ParticleSet& P, const PosType& rnew, const IndexType iat, bool prepare_old) override
83  {
84  ScopedTimer local_timer(move_timer_);
86  0, num_sources_);
87  // If the full table is not ready all the time, overwrite the current value.
88  // If this step is missing, DT values can be undefined in case a move is rejected.
89  if (!(modes_ & DTModes::NEED_FULL_TABLE_ANYTIME) && prepare_old)
91  distances_[iat].data(), displacements_[iat], 0, num_sources_);
92  }
93 
94  ///update the stripe for jat-th particle
95  inline void update(IndexType iat) override
96  {
97  ScopedTimer local_timer(update_timer_);
99  for (int idim = 0; idim < D; ++idim)
100  std::copy_n(temp_dr_.data(idim), num_sources_, displacements_[iat].data(idim));
101  }
102 
103  int get_first_neighbor(IndexType iat, RealType& r, PosType& dr, bool newpos) const override
104  {
105  RealType min_dist = std::numeric_limits<RealType>::max();
106  int index = -1;
107  if (newpos)
108  {
109  for (int jat = 0; jat < num_sources_; ++jat)
110  if (temp_r_[jat] < min_dist)
111  {
112  min_dist = temp_r_[jat];
113  index = jat;
114  }
115  if (index >= 0)
116  {
117  r = min_dist;
118  dr = temp_dr_[index];
119  }
120  }
121  else
122  {
123  for (int jat = 0; jat < num_sources_; ++jat)
124  if (distances_[iat][jat] < min_dist)
125  {
126  min_dist = distances_[iat][jat];
127  index = jat;
128  }
129  if (index >= 0)
130  {
131  r = min_dist;
132  dr = displacements_[iat][index];
133  }
134  }
135  assert(index >= 0 && index < num_sources_);
136  return index;
137  }
138 
139 private:
140  /// timer for evaluate()
142  /// timer for move()
144  /// timer for update()
146 };
147 } // namespace qmcplusplus
148 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
QMCTraits::RealType RealType
Definition: DistanceTable.h:44
NewTimer & move_timer_
timer for move()
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
virtual const PosVectorSoa & getAllParticlePos() const =0
all particle position accessor
void move(const ParticleSet &P, const PosType &rnew, const IndexType iat, bool prepare_old) override
evaluate the temporary pair relations
Timer accumulates time and call counts.
Definition: NewTimer.h:135
SoaDistanceTableAB(const ParticleSet &source, ParticleSet &target)
int get_first_neighbor(IndexType iat, RealType &r, PosType &dr, bool newpos) const override
find the first nearest neighbor
NewTimer & update_timer_
timer for update()
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
A collection of functions for dividing fairly.
void evaluate(ParticleSet &P) override
evaluate the full table
AB type of DistanceTable containing storage.
void FairDivideAligned(const int ntot, const int base, const int npart, const int me, int &first, int &last)
Partition ntot over npart and the size of each partition is a multiple of base size.
Definition: FairDivide.h:96
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
void update(IndexType iat) override
update the stripe for jat-th particle
ParticlePos R
Position.
Definition: ParticleSet.h:79
A derived classe from DistacneTableData, specialized for AB using a transposed form.
const std::string & getName() const
return the name of table
Definition: DistanceTable.h:85
omp_int_t omp_get_num_threads()
Definition: OpenMP.h:27
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
whether full table needs to be ready at anytime or not during PbyP Optimization can be implemented du...
QMCTraits::IndexType IndexType
Definition: DistanceTable.h:43
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
std::vector< DisplRow > displacements_
displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes de...
void resize(size_type n)
resize myData
const ParticleSet & origin_
Definition: DistanceTable.h:51
NewTimer & evaluate_timer_
timer for evaluate()
std::vector< DistRow > distances_
distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide ...
DTModes modes_
operation modes defined by DTModes
Definition: DistanceTable.h:60