QMCPACK
MultiFunctorAdapter< FN > Struct Template Reference

generic functor that computes a set of 1D functors More...

+ Collaboration diagram for MultiFunctorAdapter< FN >:

Public Types

using RealType = typename FN::real_type
 
using GridType = LogGridLight< RealType >
 
using single_type = FN
 
using OffloadArray2D = Array< RealType, 2, OffloadPinnedAllocator< RealType > >
 
using OffloadArray3D = Array< RealType, 3, OffloadPinnedAllocator< RealType > >
 
using OffloadArray4D = Array< RealType, 4, OffloadPinnedAllocator< RealType > >
 

Public Member Functions

 MultiFunctorAdapter ()=default
 
 MultiFunctorAdapter (const MultiFunctorAdapter &other)
 
RealType rmax () const
 
void evaluate (RealType r, RealType *restrict u)
 
void batched_evaluate (OffloadArray2D &r, OffloadArray3D &u, RealType Rmax) const
 evaluate for multiple electrons and multiple pbc images More...
 
void batched_evaluateVGL (OffloadArray2D &r, OffloadArray4D &vgl, RealType Rmax) const
 evaluate value, first deriv, second deriv for multiple electrons and multiple pbc images More...
 
void evaluate (RealType r, RealType *restrict u, RealType *restrict du, RealType *restrict d2u)
 
void evaluate (RealType r, RealType *restrict u, RealType *restrict du, RealType *restrict d2u, RealType *restrict d3u)
 

Public Attributes

aligned_vector< std::unique_ptr< single_type > > Rnl
 

Detailed Description

template<typename FN>
struct qmcplusplus::MultiFunctorAdapter< FN >

generic functor that computes a set of 1D functors

Template Parameters
FNanalytic functor, SlaterCombo<T>, GaussianCombo<T>

Analytic functors are light and no state but not efficient. Only for benchmarking.

Definition at line 32 of file MultiFunctorAdapter.h.

Member Typedef Documentation

◆ GridType

Definition at line 35 of file MultiFunctorAdapter.h.

◆ OffloadArray2D

◆ OffloadArray3D

◆ OffloadArray4D

◆ RealType

using RealType = typename FN::real_type

Definition at line 34 of file MultiFunctorAdapter.h.

◆ single_type

using single_type = FN

Definition at line 36 of file MultiFunctorAdapter.h.

Constructor & Destructor Documentation

◆ MultiFunctorAdapter() [1/2]

MultiFunctorAdapter ( )
default

◆ MultiFunctorAdapter() [2/2]

MultiFunctorAdapter ( const MultiFunctorAdapter< FN > &  other)
inline

Definition at line 43 of file MultiFunctorAdapter.h.

References MultiFunctorAdapter< FN >::Rnl.

44  {
45  Rnl.reserve(other.Rnl.size());
46  for (size_t i = 0; i < other.Rnl.size(); ++i)
47  Rnl.push_back(std::make_unique<single_type>(*other.Rnl[i]));
48  }
aligned_vector< std::unique_ptr< single_type > > Rnl

Member Function Documentation

◆ batched_evaluate()

void batched_evaluate ( OffloadArray2D r,
OffloadArray3D u,
RealType  Rmax 
) const
inline

evaluate for multiple electrons and multiple pbc images

r is assumed to be up-to-date on the device before entering this function, and u needs to be updated on the device before exiting this function

Eventually, all computation should be done on the device to avoid transfers, but for now this is all done on the host

Parameters
[in]relectron distances [Nelec, Npbc]
[out]uvalue of all radial functions at all electron distances [Nelec, Npbc, nRnl]
Rmaxevaluate to zero for any distance greater than or equal to Rmax

Definition at line 76 of file MultiFunctorAdapter.h.

References qmcplusplus::n, MultiFunctorAdapter< FN >::Rnl, Array< T, D, ALLOC >::size(), Array< T, D, ALLOC >::updateFrom(), and Array< T, D, ALLOC >::updateTo().

77  {
78  r.updateFrom(); // TODO: remove after offload and make r const
79 
80  const size_t nElec = r.size(0);
81  const size_t Nxyz = r.size(1); // number of PBC images
82  assert(nElec == u.size(0));
83  assert(Nxyz == u.size(1));
84  const size_t nRnl = u.size(2); // number of splines
85  const size_t nR = nElec * Nxyz; // total number of positions to evaluate
86 
87  for (size_t i_e = 0; i_e < nElec; i_e++)
88  for (size_t i_xyz = 0; i_xyz < Nxyz; i_xyz++)
89  if (r(i_e, i_xyz) >= Rmax)
90  for (size_t i = 0, n = Rnl.size(); i < n; ++i)
91  u(i_e, i_xyz, i) = 0.0;
92  else
93  for (size_t i = 0, n = Rnl.size(); i < n; ++i)
94  u(i_e, i_xyz, i) = Rnl[i]->f(r(i_e, i_xyz));
95 
96  u.updateTo(); // TODO: remove after offload
97  }
aligned_vector< std::unique_ptr< single_type > > Rnl

◆ batched_evaluateVGL()

void batched_evaluateVGL ( OffloadArray2D r,
OffloadArray4D vgl,
RealType  Rmax 
) const
inline

evaluate value, first deriv, second deriv for multiple electrons and multiple pbc images

r is assumed to be up-to-date on the device before entering this function, and vgl needs to be updated on the device before exiting this function

Eventually, all computation should be done on the device to avoid transfers, but for now this is all done on the host

Parameters
[in]relectron distances [Nelec, Npbc]
[out]vglval/d1/d2 of all radial functions at all electron distances [3(val,d1,d2), Nelec, Npbc, nRnl]
Rmaxradial function and derivs will evaluate to zero for any distance greater than or equal to Rmax

Definition at line 112 of file MultiFunctorAdapter.h.

References Array< T, D, ALLOC >::data(), Array< T, D, ALLOC >::data_at(), MultiFunctorAdapter< FN >::Rnl, Array< T, D, ALLOC >::size(), Array< T, D, ALLOC >::updateFrom(), and Array< T, D, ALLOC >::updateTo().

113  {
114  r.updateFrom(); // TODO: remove when eval is offloaded
115  const size_t nElec = r.size(0);
116  const size_t Nxyz = r.size(1); // number of PBC images
117  assert(3 == vgl.size(0));
118  assert(nElec == vgl.size(1));
119  assert(Nxyz == vgl.size(2));
120  const size_t nRnl = vgl.size(3); // number of primitives
121  const size_t nR = nElec * Nxyz; // total number of positions to evaluate
122  assert(nRnl == Rnl.size());
123 
124  auto* r_ptr = r.data();
125  auto* u_ptr = vgl.data_at(0, 0, 0, 0);
126  auto* du_ptr = vgl.data_at(1, 0, 0, 0);
127  auto* d2u_ptr = vgl.data_at(2, 0, 0, 0);
128 
129  for (size_t ir = 0; ir < nR; ir++)
130  {
131  // TODO: once this is offloaded, maybe better to just avoid branching and keep values past Rmax
132  if (r_ptr[ir] >= Rmax)
133  {
134  for (size_t i = 0; i < nRnl; ++i)
135  {
136  u_ptr[ir * nRnl + i] = 0.0;
137  du_ptr[ir * nRnl + i] = 0.0;
138  d2u_ptr[ir * nRnl + i] = 0.0;
139  }
140  }
141  else
142  {
143  const RealType r = r_ptr[ir];
144  const RealType rinv = RealType(1) / r;
145  for (size_t i = 0; i < nRnl; ++i)
146  {
147  Rnl[i]->evaluateAll(r, rinv);
148  u_ptr[ir * nRnl + i] = Rnl[i]->Y;
149  du_ptr[ir * nRnl + i] = Rnl[i]->dY;
150  d2u_ptr[ir * nRnl + i] = Rnl[i]->d2Y;
151  }
152  }
153  }
154  vgl.updateTo(); // TODO: remove when eval is offloaded
155  }
aligned_vector< std::unique_ptr< single_type > > Rnl
QMCTraits::RealType RealType

◆ evaluate() [1/3]

void evaluate ( RealType  r,
RealType *restrict  u 
)
inline

Definition at line 57 of file MultiFunctorAdapter.h.

References qmcplusplus::n, and MultiFunctorAdapter< FN >::Rnl.

58  {
59  for (size_t i = 0, n = Rnl.size(); i < n; ++i)
60  u[i] = Rnl[i]->f(r);
61  }
aligned_vector< std::unique_ptr< single_type > > Rnl

◆ evaluate() [2/3]

void evaluate ( RealType  r,
RealType *restrict  u,
RealType *restrict  du,
RealType *restrict  d2u 
)
inline

Definition at line 157 of file MultiFunctorAdapter.h.

References qmcplusplus::n, and MultiFunctorAdapter< FN >::Rnl.

158  {
159  const RealType rinv = RealType(1) / r;
160  for (size_t i = 0, n = Rnl.size(); i < n; ++i)
161  {
162  Rnl[i]->evaluateAll(r, rinv);
163  u[i] = Rnl[i]->Y;
164  du[i] = Rnl[i]->dY;
165  d2u[i] = Rnl[i]->d2Y;
166  }
167  }
aligned_vector< std::unique_ptr< single_type > > Rnl
QMCTraits::RealType RealType

◆ evaluate() [3/3]

void evaluate ( RealType  r,
RealType *restrict  u,
RealType *restrict  du,
RealType *restrict  d2u,
RealType *restrict  d3u 
)
inline

Definition at line 168 of file MultiFunctorAdapter.h.

References qmcplusplus::n, and MultiFunctorAdapter< FN >::Rnl.

173  {
174  const RealType rinv = RealType(1) / r;
175  for (size_t i = 0, n = Rnl.size(); i < n; ++i)
176  {
177  Rnl[i]->evaluateWithThirdDeriv(r, rinv);
178  u[i] = Rnl[i]->Y;
179  du[i] = Rnl[i]->dY;
180  d2u[i] = Rnl[i]->d2Y;
181  d3u[i] = Rnl[i]->d3Y;
182  }
183  }
aligned_vector< std::unique_ptr< single_type > > Rnl
QMCTraits::RealType RealType

◆ rmax()

RealType rmax ( ) const
inline

Definition at line 50 of file MultiFunctorAdapter.h.

51  {
52  //Another magic r_max
53  constexpr RealType r0(100);
54  return r0;
55  }
QMCTraits::RealType RealType

Member Data Documentation

◆ Rnl


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