CHROMA
lmdagm.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief M^dag*M composition of a linear operator
4  */
5 
6 #ifndef __lmdagm_h__
7 #define __lmdagm_h__
8 
9 #include "handle.h"
10 #include "linearop.h"
11 
12 namespace Chroma
13 {
14  //! M^dag.M linear operator
15  /*!
16  * \ingroup linop
17  *
18  * Linear operator forming M^dag.M from an operator M
19  */
20  template<typename T>
21  class MdagMLinOp : public LinearOperator<T>
22  {
23  public:
24  //! Initialize pointer with existing pointer
25  /*! Requires that the pointer p is a return value of new */
27 
28  //! Copy pointer (one more owner)
30 
31  //! Destructor
33 
34  //! Subset comes from underlying operator
35  inline const Subset& subset() const {return A->subset();}
36 
37  //! Apply the operator onto a source std::vector
38  /*! For this operator, the sign is ignored */
39  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
40  {
41  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
42 
43  (*A)(tmp, psi, PLUS);
44  (*A)(chi, tmp, MINUS);
45  }
46 
47  unsigned long nFlops(void) const {
48  unsigned long nflops=2*A->nFlops();
49  return nflops;
50  }
51 
52  private:
54  };
55 
56 
57 
58 
59  //! M^dag.M linear operator over arrays
60  /*!
61  * \ingroup linop
62  *
63  * Linear operator forming M^dag.M from an operator M
64  */
65  template<typename T>
67  {
68  public:
69  //! Initialize pointer with existing pointer
70  /*! Requires that the pointer p is a return value of new */
72 
73  //! Copy pointer (one more owner)
75 
76  //! Destructor
78 
79  //! Length of array index
80  int size() const {return A->size();}
81 
82  //! Subset comes from underlying operator
83  inline const Subset& subset() const {return A->subset();}
84 
85  //! Apply the operator onto a source std::vector
86  /*! For this operator, the sign is ignored */
87  inline void operator() (multi1d<T>& chi, const multi1d<T>& psi, enum PlusMinus isign) const
88  {
89  multi1d<T> tmp(size()); QDP::Hints::moveToFastMemoryHint(tmp);
90  (*A)(tmp, psi, PLUS);
91  (*A)(chi, tmp, MINUS);
92  }
93 
94  unsigned long nFlops(void) const {
95  unsigned long nflops=2*A->nFlops();
96  return nflops;
97  }
98 
99  private:
101  };
102 
103 
104  //! M^dag.M linear operator
105  /*!
106  * \ingroup linop
107  *
108  * Linear operator forming M^dag.M from an operator M
109  */
110  template<typename T>
111  class approx_lmdagm : public LinearOperator<T>
112  {
113  public:
114  //! Initialize pointer with existing pointer
115  /*! Requires that the pointer p is a return value of new */
117 
118  //! Copy pointer (one more owner)
120 
121  //! Destructor
123 
124  //! Subset comes from underlying operator
125  inline const Subset& subset() const {return A->subset();}
126 
127  //! Apply the operator onto a source std::vector
128  /*! For this operator, the sign is ignored */
129  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
130  {
131  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
132 
133  (*A)(tmp, psi, PLUS);
134  (*A)(chi, tmp, MINUS);
135  }
136 
137  //! Apply the operator onto a source std::vector
138  /*! For this operator, the sign is ignored */
139  inline void operator() (T& chi, const T& psi, enum PlusMinus isign, Real epsilon) const
140  {
141  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
142 
143  (*A)(tmp, psi, PLUS, epsilon/Real(2));
144  (*A)(chi, tmp, MINUS, epsilon/Real(2));
145  }
146 
147  private:
149  };
150 
151 
152  //! Differentiable M^dag.M linear operator
153  /*!
154  * \ingroup linop
155  *
156  * Diff. Linear operator forming M^dag.M from an operator M
157  */
158  template<typename T, typename P, typename Q>
159  class DiffMdagMLinOp : public DiffLinearOperator<T,P,Q>
160  {
161  public:
162  //! Initialize pointer with existing pointer
163  /*! Requires that the pointer p is a return value of new */
165 
166  //! Copy pointer (one more owner)
168 
169  //! Destructor
171 
172  //! Return the fermion BC object for this linear operator
173  const FermBC<T,P,Q>& getFermBC() const {return A->getFermBC();}
174 
175  //! Subset comes from underlying operator
176  inline const Subset& subset() const {return A->subset();}
177 
178  //! Apply the operator onto a source std::vector
179  /*! For this operator, the sign is ignored */
180  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
181  {
182  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
183 
184  (*A)(tmp, psi, PLUS);
185  (*A)(chi, tmp, MINUS);
186  }
187 
188  //! Apply the derivative of the operator
189  /*!
190  * Deriv of chi^dag * A^dag * A * psi
191  *
192  * Default implementation
193  */
194  virtual void deriv(P& ds_u, const T& chi, const T& psi,
195  enum PlusMinus isign) const
196  {
197  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
198 
199  (*A)(tmp, psi, PLUS);
200  A->deriv(ds_u, chi, tmp, MINUS);
201 
202  P ds_tmp; // deriv routines should resize
203  (*A)(tmp, chi, PLUS); // note using PLUS
204  A->deriv(ds_tmp, tmp, psi, PLUS);
205  ds_u += ds_tmp;
206  }
207 
208 
209  //! Apply the derivative of the operator
210  /*!
211  * Deriv of chi^dag * A^dag * A * psi
212  *
213  * Default implementation
214  */
215  virtual void deriv(P& ds_u, const T& chi, const T& psi,
216  enum PlusMinus isign, const Real& epsilon) const
217  {
218  T tmp;
219 
220  (*A)(tmp, psi, PLUS, epsilon);
221  A->deriv(ds_u, chi, tmp, MINUS, epsilon);
222 
223  P ds_tmp; // deriv routines should resize
224  (*A)(tmp, chi, PLUS, epsilon); // note using PLUS
225  A->deriv(ds_tmp, tmp, psi, PLUS, epsilon);
226  ds_u += ds_tmp;
227  }
228 
229  //! Return the number of flops performed by operator()
230  unsigned long nFlops(void) const {return 2*A->nFlops();}
231 
232  private:
234  };
235 
236 
237 
238 
239  //! M^dag.M linear operator over arrays
240  /*!
241  * \ingroup linop
242  *
243  * Linear operator forming M^dag.M from an operator M
244  */
245  template<typename T, typename P, typename Q>
247  {
248  public:
249  //! Initialize pointer with existing pointer
250  /*! Requires that the pointer p is a return value of new */
252 
253  //! Copy pointer (one more owner)
255 
256  //! Destructor
258 
259  //! Return the fermion BC object for this linear operator
260  const FermBC<T,P,Q>& getFermBC() const {return A->getFermBC();}
261 
262  //! Length of array index
263  int size() const {return A->size();}
264 
265  //! Subset comes from underlying operator
266  inline const Subset& subset() const {return A->subset();}
267 
268  //! Apply the operator onto a source std::vector
269  /*! For this operator, the sign is ignored */
270  inline void operator() (multi1d<T>& chi, const multi1d<T>& psi, enum PlusMinus isign) const
271  {
272  multi1d<T> tmp(size()); QDP::Hints::moveToFastMemoryHint(tmp);
273  (*A)(tmp, psi, PLUS);
274  (*A)(chi, tmp, MINUS);
275  }
276 
277  //! Apply the derivative of the operator
278  /*!
279  * Deriv of chi^dag * A^dag * A * psi
280  *
281  * Default implementation
282  */
283  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
284  enum PlusMinus isign) const
285  {
286  multi1d<T> tmp(size()); QDP::Hints::moveToFastMemoryHint(tmp);
287 
288  (*A)(tmp, psi, PLUS);
289  A->deriv(ds_u, chi, tmp, MINUS);
290 
291  P ds_tmp; // deriv routines should resize
292  (*A)(tmp, chi, PLUS); // note using PLUS
293  A->deriv(ds_tmp, tmp, psi, PLUS);
294  ds_u += ds_tmp;
295  }
296 
297 
298  //! Apply the derivative of the operator
299  /*!
300  * Deriv of chi^dag * A^dag * A * psi
301  *
302  * Default implementation
303  */
304  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
305  enum PlusMinus isign, const Real& epsilon) const
306  {
307  multi1d<T> tmp(size());
308 
309  (*A)(tmp, psi, PLUS, epsilon);
310  A->deriv(ds_u, chi, tmp, MINUS, epsilon);
311 
312  P ds_tmp; // deriv routines should resize
313  (*A)(tmp, chi, PLUS, epsilon); // note using PLUS
314  A->deriv(ds_tmp, tmp, psi, PLUS, epsilon);
315  ds_u += ds_tmp;
316  }
317 
318  //! Return the number of flops performed by operator()
319  unsigned long nFlops(void) const {return 2*A->nFlops();}
320 
321  private:
323  };
324 
325 
326 } // End Namespace Chroma
327 
328 
329 #endif
Differentiable Linear Operator.
Definition: linearop.h:150
Differentiable Linear Operator.
Definition: linearop.h:98
M^dag.M linear operator over arrays.
Definition: lmdagm.h:247
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
Definition: lmdagm.h:260
DiffMdagMLinOpArray(DiffLinearOperatorArray< T, P, Q > *p)
Initialize pointer with existing pointer.
Definition: lmdagm.h:251
Handle< DiffLinearOperatorArray< T, P, Q > > A
Definition: lmdagm.h:322
unsigned long nFlops(void) const
Return the number of flops performed by operator()
Definition: lmdagm.h:319
const Subset & subset() const
Subset comes from underlying operator.
Definition: lmdagm.h:266
int size() const
Length of array index.
Definition: lmdagm.h:263
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the derivative of the operator.
Definition: lmdagm.h:283
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign, const Real &epsilon) const
Apply the derivative of the operator.
Definition: lmdagm.h:304
~DiffMdagMLinOpArray()
Destructor.
Definition: lmdagm.h:257
void operator()(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lmdagm.h:270
DiffMdagMLinOpArray(Handle< DiffLinearOperatorArray< T, P, Q > > p)
Copy pointer (one more owner)
Definition: lmdagm.h:254
Differentiable M^dag.M linear operator.
Definition: lmdagm.h:160
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign, const Real &epsilon) const
Apply the derivative of the operator.
Definition: lmdagm.h:215
Handle< DiffLinearOperator< T, P, Q > > A
Definition: lmdagm.h:233
const Subset & subset() const
Subset comes from underlying operator.
Definition: lmdagm.h:176
DiffMdagMLinOp(DiffLinearOperator< T, P, Q > *p)
Initialize pointer with existing pointer.
Definition: lmdagm.h:164
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lmdagm.h:180
DiffMdagMLinOp(Handle< DiffLinearOperator< T, P, Q > > p)
Copy pointer (one more owner)
Definition: lmdagm.h:167
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
Definition: lmdagm.h:173
~DiffMdagMLinOp()
Destructor.
Definition: lmdagm.h:170
unsigned long nFlops(void) const
Return the number of flops performed by operator()
Definition: lmdagm.h:230
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Apply the derivative of the operator.
Definition: lmdagm.h:194
Base class for all fermion action boundary conditions.
Definition: fermbc.h:20
Class for counted reference semantics.
Definition: handle.h:33
Linear Operator to arrays.
Definition: linearop.h:61
Linear Operator.
Definition: linearop.h:27
M^dag.M linear operator over arrays.
Definition: lmdagm.h:67
~MdagMLinOpArray()
Destructor.
Definition: lmdagm.h:77
Handle< LinearOperatorArray< T > > A
Definition: lmdagm.h:100
MdagMLinOpArray(LinearOperatorArray< T > *p)
Initialize pointer with existing pointer.
Definition: lmdagm.h:71
void operator()(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lmdagm.h:87
unsigned long nFlops(void) const
Definition: lmdagm.h:94
int size() const
Length of array index.
Definition: lmdagm.h:80
MdagMLinOpArray(Handle< LinearOperatorArray< T > > p)
Copy pointer (one more owner)
Definition: lmdagm.h:74
const Subset & subset() const
Subset comes from underlying operator.
Definition: lmdagm.h:83
M^dag.M linear operator.
Definition: lmdagm.h:22
MdagMLinOp(Handle< LinearOperator< T > > p)
Copy pointer (one more owner)
Definition: lmdagm.h:29
unsigned long nFlops(void) const
Definition: lmdagm.h:47
~MdagMLinOp()
Destructor.
Definition: lmdagm.h:32
Handle< LinearOperator< T > > A
Definition: lmdagm.h:53
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lmdagm.h:39
MdagMLinOp(LinearOperator< T > *p)
Initialize pointer with existing pointer.
Definition: lmdagm.h:26
const Subset & subset() const
Subset comes from underlying operator.
Definition: lmdagm.h:35
M^dag.M linear operator.
Definition: lmdagm.h:112
Handle< LinearOperator< T > > A
Definition: lmdagm.h:148
approx_lmdagm(Handle< LinearOperator< T > > p)
Copy pointer (one more owner)
Definition: lmdagm.h:119
const Subset & subset() const
Subset comes from underlying operator.
Definition: lmdagm.h:125
~approx_lmdagm()
Destructor.
Definition: lmdagm.h:122
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lmdagm.h:129
approx_lmdagm(LinearOperator< T > *p)
Initialize pointer with existing pointer.
Definition: lmdagm.h:116
Class for counted reference semantics.
Linear Operators.
int epsilon(int i, int j, int k)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
LinOpSysSolverMGProtoClover::T T
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13