QMCPACK
SoaDistanceTableAA.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_AA_H
14 #define QMCPLUSPLUS_DTDIMPL_AA_H
15 
17 #include "DistanceTable.h"
18 
19 namespace qmcplusplus
20 {
21 /**@ingroup nnlist
22  * @brief A derived classe from DistacneTableData, specialized for dense case
23  */
24 template<typename T, unsigned D, int SC>
25 struct SoaDistanceTableAA : public DTD_BConds<T, D, SC>, public DistanceTableAA
26 {
27  /// actual memory for dist and displacements_
29 
31  : DTD_BConds<T, D, SC>(target.getLattice()),
34 #if !defined(NDEBUG)
36 #endif
37  evaluate_timer_(createGlobalTimer(std::string("DTAA::evaluate_") + target.getName() + "_" + target.getName(),
39  move_timer_(createGlobalTimer(std::string("DTAA::move_") + target.getName() + "_" + target.getName(),
41  update_timer_(createGlobalTimer(std::string("DTAA::update_") + target.getName() + "_" + target.getName(),
43  {
44  resize();
45  }
46 
47  SoaDistanceTableAA() = delete;
48  SoaDistanceTableAA(const SoaDistanceTableAA&) = delete;
49  ~SoaDistanceTableAA() override {}
50 
51  size_t compute_size(int N) const
52  {
53  const size_t num_padded = getAlignedSize<T>(N);
54  const size_t Alignment = getAlignment<T>();
55  return (num_padded * (2 * N - num_padded + 1) + (Alignment - 1) * num_padded) / 2;
56  }
57 
58  void resize()
59  {
60  // initialize memory containers and views
61  const size_t total_size = compute_size(num_targets_);
62  memory_pool_.resize(total_size * (1 + D));
63  distances_.resize(num_targets_);
65  for (int i = 0; i < num_targets_; ++i)
66  {
67  distances_[i].attachReference(memory_pool_.data() + compute_size(i), i);
68  displacements_[i].attachReference(i, total_size, memory_pool_.data() + total_size + compute_size(i));
69  }
70 
75  }
76 
77  inline void evaluate(ParticleSet& P) override
78  {
79  ScopedTimer local_timer(evaluate_timer_);
80  constexpr T BigR = std::numeric_limits<T>::max();
81  for (int iat = 1; iat < num_targets_; ++iat)
83  displacements_[iat], 0, iat, iat);
84  }
85 
86  ///evaluate the temporary pair relations
87  inline void move(const ParticleSet& P, const PosType& rnew, const IndexType iat, bool prepare_old) override
88  {
89  ScopedTimer local_timer(move_timer_);
90 
91 #if !defined(NDEBUG)
92  old_prepared_elec_id_ = prepare_old ? iat : -1;
93 #endif
95  num_targets_, iat);
96  // set up old_r_ and old_dr_ for moves may get accepted.
97  if (prepare_old)
98  {
99  //recompute from scratch
101  0, num_targets_, iat);
102  old_r_[iat] = std::numeric_limits<T>::max(); //assign a big number
103  }
104  }
105 
106  int get_first_neighbor(IndexType iat, RealType& r, PosType& dr, bool newpos) const override
107  {
108  //ensure there are neighbors
109  assert(num_targets_ > 1);
110  RealType min_dist = std::numeric_limits<RealType>::max();
111  int index = -1;
112  if (newpos)
113  {
114  for (int jat = 0; jat < num_targets_; ++jat)
115  if (temp_r_[jat] < min_dist && jat != iat)
116  {
117  min_dist = temp_r_[jat];
118  index = jat;
119  }
120  assert(index >= 0);
121  dr = temp_dr_[index];
122  }
123  else
124  {
125  for (int jat = 0; jat < iat; ++jat)
126  if (distances_[iat][jat] < min_dist)
127  {
128  min_dist = distances_[iat][jat];
129  index = jat;
130  }
131  for (int jat = iat + 1; jat < num_targets_; ++jat)
132  if (distances_[jat][iat] < min_dist)
133  {
134  min_dist = distances_[jat][iat];
135  index = jat;
136  }
137  assert(index != iat && index >= 0);
138  if (index < iat)
139  dr = displacements_[iat][index];
140  else
141  dr = displacements_[index][iat];
142  }
143  r = min_dist;
144  return index;
145  }
146 
147  /** After accepting the iat-th particle, update the iat-th row of distances_ and displacements_.
148  * Upper triangle is not needed in the later computation and thus not updated
149  */
150  inline void update(IndexType iat) override
151  {
152  ScopedTimer local_timer(update_timer_);
153  //update [0, iat)
154  const int nupdate = iat;
155  //copy row
156  assert(nupdate <= temp_r_.size());
157  std::copy_n(temp_r_.data(), nupdate, distances_[iat].data());
158  for (int idim = 0; idim < D; ++idim)
159  std::copy_n(temp_dr_.data(idim), nupdate, displacements_[iat].data(idim));
160  //copy column
161  for (size_t i = iat + 1; i < num_targets_; ++i)
162  {
163  distances_[i][iat] = temp_r_[i];
164  displacements_[i](iat) = -temp_dr_[i];
165  }
166  }
167 
168  void updatePartial(IndexType jat, bool from_temp) override
169  {
170  ScopedTimer local_timer(update_timer_);
171  //update [0, jat)
172  const int nupdate = jat;
173  if (from_temp)
174  {
175  //copy row
176  assert(nupdate <= temp_r_.size());
177  std::copy_n(temp_r_.data(), nupdate, distances_[jat].data());
178  for (int idim = 0; idim < D; ++idim)
179  std::copy_n(temp_dr_.data(idim), nupdate, displacements_[jat].data(idim));
180  }
181  else
182  {
183  assert(old_prepared_elec_id_ == jat);
184  //copy row
185  assert(nupdate <= old_r_.size());
186  std::copy_n(old_r_.data(), nupdate, distances_[jat].data());
187  for (int idim = 0; idim < D; ++idim)
188  std::copy_n(old_dr_.data(idim), nupdate, displacements_[jat].data(idim));
189  }
190  }
191 
192 private:
193  ///number of targets with padding
194  const size_t num_targets_padded_;
195 #if !defined(NDEBUG)
196  /** set to particle id after move() with prepare_old = true. -1 means not prepared.
197  * It is intended only for safety checks, not for codepath selection.
198  */
200 #endif
201  /// timer for evaluate()
203  /// timer for move()
205  /// timer for update()
207 };
208 } // namespace qmcplusplus
209 #endif
int old_prepared_elec_id_
set to particle id after move() with prepare_old = true.
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
size_t getAlignedSize(size_t n)
return size in T&#39;s of allocated aligned memory
std::vector< T, aligned_allocator< T > > aligned_vector
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
SoaDistanceTableAA(ParticleSet &target)
virtual const PosVectorSoa & getAllParticlePos() const =0
all particle position accessor
void updatePartial(IndexType jat, bool from_temp) override
fill partially the distance table by the pair relations from the temporary or old particle position...
if(c->rank()==0)
Timer accumulates time and call counts.
Definition: NewTimer.h:135
std::vector< DisplRow > displacements_
displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes de...
DisplRow old_dr_
old displacements
DistRow old_r_
old distances
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
size_type size() const
return the current size
Definition: OhmmsVector.h:162
NewTimer & evaluate_timer_
timer for evaluate()
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
ParticlePos R
Position.
Definition: ParticleSet.h:79
const std::string & getName() const
return the name of table
Definition: DistanceTable.h:85
A derived classe from DistacneTableData, specialized for dense case.
AA type of DistanceTable containing storage.
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
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
int get_first_neighbor(IndexType iat, RealType &r, PosType &dr, bool newpos) const override
NewTimer & update_timer_
timer for update()
void move(const ParticleSet &P, const PosType &rnew, const IndexType iat, bool prepare_old) override
evaluate the temporary pair relations
void resize(size_type n)
resize myData
std::vector< DistRow > distances_
distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide ...
const size_t num_targets_padded_
number of targets with padding
aligned_vector< RealType > memory_pool_
actual memory for dist and displacements_
NewTimer & move_timer_
timer for move()
void update(IndexType iat) override
After accepting the iat-th particle, update the iat-th row of distances_ and displacements_.
void evaluate(ParticleSet &P) override
evaluate the full Distance Table