QMCPACK
SoaDistanceTableAA< T, D, SC > Struct Template Reference

A derived classe from DistacneTableData, specialized for dense case. More...

+ Inheritance diagram for SoaDistanceTableAA< T, D, SC >:
+ Collaboration diagram for SoaDistanceTableAA< T, D, SC >:

Public Member Functions

 SoaDistanceTableAA (ParticleSet &target)
 
 SoaDistanceTableAA ()=delete
 
 SoaDistanceTableAA (const SoaDistanceTableAA &)=delete
 
 ~SoaDistanceTableAA () override
 
size_t compute_size (int N) const
 
void resize ()
 
void evaluate (ParticleSet &P) override
 evaluate the full Distance Table More...
 
void move (const ParticleSet &P, const PosType &rnew, const IndexType iat, bool prepare_old) override
 evaluate the temporary pair relations More...
 
int get_first_neighbor (IndexType iat, RealType &r, PosType &dr, bool newpos) const override
 
void update (IndexType iat) override
 After accepting the iat-th particle, update the iat-th row of distances_ and displacements_. More...
 
void updatePartial (IndexType jat, bool from_temp) override
 fill partially the distance table by the pair relations from the temporary or old particle position. More...
 
- Public Member Functions inherited from DTD_BConds< T, D, SC >
 DTD_BConds (const CrystalLattice< T, D > &lat)
 constructor: doing nothing More...
 
apply_bc (TinyVector< T, D > &displ) const
 apply BC on displ and return |displ|^2 More...
 
void apply_bc (std::vector< TinyVector< T, D >> &dr, std::vector< T > &r, std::vector< T > &rinv) const
 apply BC on dr and evaluate r and rinv More...
 
void apply_bc (std::vector< TinyVector< T, D >> &dr, std::vector< T > &r) const
 
void evaluate_rsquared (TinyVector< T, D > *restrict dr, T *restrict rr, int n)
 
- Public Member Functions inherited from DistanceTableAA
 DistanceTableAA (const ParticleSet &target, DTModes modes)
 constructor using source and target ParticleSet More...
 
const std::vector< DistRow > & getDistances () const
 return full table distances More...
 
const std::vector< DisplRow > & getDisplacements () const
 return full table displacements More...
 
const DistRowgetDistRow (int iel) const
 return a row of distances for a given target particle More...
 
const DisplRowgetDisplRow (int iel) const
 return a row of displacements for a given target particle More...
 
const DistRowgetTempDists () const
 return the temporary distances when a move is proposed More...
 
const DisplRowgetTempDispls () const
 return the temporary displacements when a move is proposed More...
 
const DistRowgetOldDists () const
 return old distances set up by move() for optimized distance table consumers More...
 
const DisplRowgetOldDispls () const
 return old displacements set up by move() for optimized distance table consumers More...
 
virtual size_t get_num_particls_stored () const
 
virtual const RealTypegetMultiWalkerTempDataPtr () const
 return multi walker temporary pair distance table data pointer More...
 
virtual const RealTypemw_evalDistsInRange (const RefVectorWithLeader< DistanceTable > &dt_list, const RefVectorWithLeader< ParticleSet > &p_list, size_t range_begin, size_t range_end) const
 
- Public Member Functions inherited from DistanceTable
 DistanceTable (const ParticleSet &source, const ParticleSet &target, DTModes modes)
 constructor using source and target ParticleSet More...
 
 DistanceTable (const DistanceTable &)=delete
 copy constructor. deleted More...
 
virtual ~DistanceTable ()=default
 virutal destructor More...
 
DTModes getModes () const
 get modes More...
 
void setModes (DTModes modes)
 set modes More...
 
const std::string & getName () const
 return the name of table More...
 
const ParticleSetget_origin () const
 returns the reference the origin particleset More...
 
size_t centers () const
 returns the number of centers More...
 
size_t targets () const
 returns the number of centers More...
 
size_t sources () const
 returns the number of source particles More...
 
virtual void mw_evaluate (const RefVectorWithLeader< DistanceTable > &dt_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 
virtual void mw_recompute (const RefVectorWithLeader< DistanceTable > &dt_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< bool > &recompute) const
 recompute multi walker internal data, recompute More...
 
virtual void mw_move (const RefVectorWithLeader< DistanceTable > &dt_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< PosType > &rnew_list, const IndexType iat, bool prepare_old=true) const
 walker batched version of move. More...
 
virtual void mw_updatePartial (const RefVectorWithLeader< DistanceTable > &dt_list, IndexType jat, const std::vector< bool > &from_temp)
 walker batched version of updatePartial. More...
 
virtual void finalizePbyP (const ParticleSet &P)
 finalize distance table calculation after particle-by-particle moves if update() doesn't make the table up-to-date during p-by-p moves finalizePbyP takes action to bring the table up-to-date More...
 
virtual void mw_finalizePbyP (const RefVectorWithLeader< DistanceTable > &dt_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 walker batched version of finalizePbyP If not DTModes::NEED_TEMP_DATA_ON_HOST, host distance table data is not updated at all during p-by-p Thus, a recompute is necessary to update the whole host distance table for consumers like the Coulomb potential. More...
 
virtual int get_first_neighbor (IndexType iat, RealType &r, PosType &dr, bool newpos) const =0
 find the first nearest neighbor More...
 
void print (std::ostream &os)
 
virtual void createResource (ResourceCollection &collection) const
 initialize a shared resource and hand it to a collection More...
 
virtual void acquireResource (ResourceCollection &collection, const RefVectorWithLeader< DistanceTable > &dt_list) const
 acquire a shared resource from a collection More...
 
virtual void releaseResource (ResourceCollection &collection, const RefVectorWithLeader< DistanceTable > &dt_list) const
 return a shared resource to a collection More...
 

Public Attributes

aligned_vector< RealTypememory_pool_
 actual memory for dist and displacements_ More...
 

Private Attributes

const size_t num_targets_padded_
 number of targets with padding More...
 
int old_prepared_elec_id_
 set to particle id after move() with prepare_old = true. More...
 
NewTimerevaluate_timer_
 timer for evaluate() More...
 
NewTimermove_timer_
 timer for move() More...
 
NewTimerupdate_timer_
 timer for update() More...
 

Additional Inherited Members

- Public Types inherited from DistanceTable
using IndexType = QMCTraits::IndexType
 
using RealType = QMCTraits::RealType
 
using PosType = QMCTraits::PosType
 
using DistRow = Vector< RealType, aligned_allocator< RealType > >
 
using DisplRow = VectorSoaContainer< RealType, DIM >
 
- Static Public Attributes inherited from DistanceTable
static constexpr unsigned DIM = OHMMS_DIM
 
- Protected Attributes inherited from DistanceTableAA
std::vector< DistRowdistances_
 distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide if it is a memory view or the actual storage For only the lower triangle (j<i) data can be accessed safely. More...
 
std::vector< DisplRowdisplacements_
 displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes decide if it is a memory view or the actual storage only the lower triangle (j<i) is defined. More...
 
DistRow temp_r_
 temp_r More...
 
DisplRow temp_dr_
 temp_dr More...
 
DistRow old_r_
 old distances More...
 
DisplRow old_dr_
 old displacements More...
 
- Protected Attributes inherited from DistanceTable
const ParticleSetorigin_
 
const size_t num_sources_
 
const size_t num_targets_
 
const std::string name_
 name of the table More...
 
DTModes modes_
 operation modes defined by DTModes More...
 

Detailed Description

template<typename T, unsigned D, int SC>
struct qmcplusplus::SoaDistanceTableAA< T, D, SC >

A derived classe from DistacneTableData, specialized for dense case.

Definition at line 25 of file SoaDistanceTableAA.h.

Constructor & Destructor Documentation

◆ SoaDistanceTableAA() [1/3]

SoaDistanceTableAA ( ParticleSet target)
inline

Definition at line 30 of file SoaDistanceTableAA.h.

References SoaDistanceTableAA< T, D, SC >::resize().

31  : DTD_BConds<T, D, SC>(target.getLattice()),
33  num_targets_padded_(getAlignedSize<T>(num_targets_)),
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  }
int old_prepared_elec_id_
set to particle id after move() with prepare_old = true.
NewTimer & evaluate_timer_
timer for evaluate()
DistanceTableAA(const ParticleSet &target, DTModes modes)
constructor using source and target ParticleSet
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
NewTimer & update_timer_
timer for update()
const size_t num_targets_padded_
number of targets with padding
NewTimer & move_timer_
timer for move()

◆ SoaDistanceTableAA() [2/3]

SoaDistanceTableAA ( )
delete

◆ SoaDistanceTableAA() [3/3]

SoaDistanceTableAA ( const SoaDistanceTableAA< T, D, SC > &  )
delete

◆ ~SoaDistanceTableAA()

~SoaDistanceTableAA ( )
inlineoverride

Definition at line 49 of file SoaDistanceTableAA.h.

49 {}

Member Function Documentation

◆ compute_size()

size_t compute_size ( int  N) const
inline

Definition at line 51 of file SoaDistanceTableAA.h.

References qmcplusplus::Units::force::N.

Referenced by SoaDistanceTableAA< T, D, SC >::resize(), and qmcplusplus::TEST_CASE().

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  }

◆ evaluate()

void evaluate ( ParticleSet P)
inlineoverridevirtual

evaluate the full Distance Table

Parameters
Pthe target particle set

Implements DistanceTable.

Definition at line 77 of file SoaDistanceTableAA.h.

References DistanceTableAA::displacements_, DistanceTableAA::distances_, SoaDistanceTableAA< T, D, SC >::evaluate_timer_, DynamicCoordinates::getAllParticlePos(), ParticleSet::getCoordinates(), DistanceTable::num_targets_, and ParticleSet::R.

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)
82  DTD_BConds<T, D, SC>::computeDistances(P.R[iat], P.getCoordinates().getAllParticlePos(), distances_[iat].data(),
83  displacements_[iat], 0, iat, iat);
84  }
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
std::vector< DisplRow > displacements_
displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes de...
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 ...

◆ get_first_neighbor()

int get_first_neighbor ( IndexType  iat,
RealType r,
PosType dr,
bool  newpos 
) const
inlineoverride

Definition at line 106 of file SoaDistanceTableAA.h.

References DistanceTableAA::displacements_, DistanceTableAA::distances_, DistanceTable::num_targets_, DistanceTableAA::temp_dr_, and DistanceTableAA::temp_r_.

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  }
std::vector< DisplRow > displacements_
displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes de...
QMCTraits::RealType RealType
std::vector< DistRow > distances_
distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide ...

◆ move()

void move ( const ParticleSet P,
const PosType rnew,
const IndexType  iat,
bool  prepare_old 
)
inlineoverridevirtual

evaluate the temporary pair relations

Implements DistanceTable.

Definition at line 87 of file SoaDistanceTableAA.h.

References Vector< T, Alloc >::data(), DynamicCoordinates::getAllParticlePos(), ParticleSet::getCoordinates(), SoaDistanceTableAA< T, D, SC >::move_timer_, DistanceTable::num_targets_, DistanceTableAA::old_dr_, SoaDistanceTableAA< T, D, SC >::old_prepared_elec_id_, DistanceTableAA::old_r_, ParticleSet::R, DistanceTableAA::temp_dr_, and DistanceTableAA::temp_r_.

88  {
89  ScopedTimer local_timer(move_timer_);
90 
91 #if !defined(NDEBUG)
92  old_prepared_elec_id_ = prepare_old ? iat : -1;
93 #endif
94  DTD_BConds<T, D, SC>::computeDistances(rnew, P.getCoordinates().getAllParticlePos(), temp_r_.data(), temp_dr_, 0,
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
100  DTD_BConds<T, D, SC>::computeDistances(P.R[iat], P.getCoordinates().getAllParticlePos(), old_r_.data(), old_dr_,
101  0, num_targets_, iat);
102  old_r_[iat] = std::numeric_limits<T>::max(); //assign a big number
103  }
104  }
int old_prepared_elec_id_
set to particle id after move() with prepare_old = true.
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
DisplRow old_dr_
old displacements
DistRow old_r_
old distances
NewTimer & move_timer_
timer for move()

◆ resize()

void resize ( )
inline

Definition at line 58 of file SoaDistanceTableAA.h.

References SoaDistanceTableAA< T, D, SC >::compute_size(), DistanceTableAA::displacements_, DistanceTableAA::distances_, SoaDistanceTableAA< T, D, SC >::memory_pool_, DistanceTable::num_targets_, DistanceTableAA::old_dr_, DistanceTableAA::old_r_, VectorSoaContainer< T, D, Alloc >::resize(), Vector< T, Alloc >::resize(), DistanceTableAA::temp_dr_, and DistanceTableAA::temp_r_.

Referenced by SoaDistanceTableAA< T, D, SC >::SoaDistanceTableAA().

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  }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
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
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 ...
aligned_vector< RealType > memory_pool_
actual memory for dist and displacements_

◆ update()

void update ( IndexType  iat)
inlineoverridevirtual

After accepting the iat-th particle, update the iat-th row of distances_ and displacements_.

Upper triangle is not needed in the later computation and thus not updated

Implements DistanceTable.

Definition at line 150 of file SoaDistanceTableAA.h.

References qmcplusplus::syclBLAS::copy_n(), Vector< T, Alloc >::data(), VectorSoaContainer< T, D, Alloc >::data(), DistanceTableAA::displacements_, DistanceTableAA::distances_, DistanceTable::num_targets_, Vector< T, Alloc >::size(), DistanceTableAA::temp_dr_, DistanceTableAA::temp_r_, and SoaDistanceTableAA< T, D, SC >::update_timer_.

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  }
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
std::vector< DisplRow > displacements_
displacements_[num_targets_][3][num_sources_], [i][3][j] = r_A2[j] - r_A1[i] Note: Derived classes de...
size_type size() const
return the current size
Definition: OhmmsVector.h:162
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
NewTimer & update_timer_
timer for update()
std::vector< DistRow > distances_
distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide ...

◆ updatePartial()

void updatePartial ( IndexType  jat,
bool  from_temp 
)
inlineoverridevirtual

fill partially the distance table by the pair relations from the temporary or old particle position.

Used in forward mode when a move is reject

Parameters
iatthe particle with an accepted move
from_tempif true, copy from temp. if false, copy from old

Reimplemented from DistanceTable.

Definition at line 168 of file SoaDistanceTableAA.h.

References qmcplusplus::syclBLAS::copy_n(), Vector< T, Alloc >::data(), VectorSoaContainer< T, D, Alloc >::data(), DistanceTableAA::displacements_, DistanceTableAA::distances_, DistanceTableAA::old_dr_, SoaDistanceTableAA< T, D, SC >::old_prepared_elec_id_, DistanceTableAA::old_r_, Vector< T, Alloc >::size(), DistanceTableAA::temp_dr_, DistanceTableAA::temp_r_, and SoaDistanceTableAA< T, D, SC >::update_timer_.

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  }
int old_prepared_elec_id_
set to particle id after move() with prepare_old = true.
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
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
size_type size() const
return the current size
Definition: OhmmsVector.h:162
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
NewTimer & update_timer_
timer for update()
std::vector< DistRow > distances_
distances_[num_targets_][num_sources_], [i][3][j] = |r_A2[j] - r_A1[i]| Note: Derived classes decide ...

Member Data Documentation

◆ evaluate_timer_

NewTimer& evaluate_timer_
private

timer for evaluate()

Definition at line 202 of file SoaDistanceTableAA.h.

Referenced by SoaDistanceTableAA< T, D, SC >::evaluate().

◆ memory_pool_

aligned_vector<RealType> memory_pool_

actual memory for dist and displacements_

Definition at line 28 of file SoaDistanceTableAA.h.

Referenced by SoaDistanceTableAA< T, D, SC >::resize().

◆ move_timer_

NewTimer& move_timer_
private

timer for move()

Definition at line 204 of file SoaDistanceTableAA.h.

Referenced by SoaDistanceTableAA< T, D, SC >::move().

◆ num_targets_padded_

const size_t num_targets_padded_
private

number of targets with padding

Definition at line 194 of file SoaDistanceTableAA.h.

◆ old_prepared_elec_id_

int old_prepared_elec_id_
private

set to particle id after move() with prepare_old = true.

-1 means not prepared. It is intended only for safety checks, not for codepath selection.

Definition at line 199 of file SoaDistanceTableAA.h.

Referenced by SoaDistanceTableAA< T, D, SC >::move(), and SoaDistanceTableAA< T, D, SC >::updatePartial().

◆ update_timer_

NewTimer& update_timer_
private

The documentation for this struct was generated from the following file: