CHROMA
ldag.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief M^dag composition of a linear operator
4  */
5 
6 #ifndef __ldag_h__
7 #define __ldag_h__
8 
9 #include "handle.h"
10 #include "linearop.h"
11 
12 namespace Chroma
13 {
14  //! M^dag linear operator
15  /*!
16  * \ingroup linop
17  *
18  * Linear operator forming M^dag from an operator M
19  */
20  template<typename T>
21  class MdagLinOp : 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  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
43 
44  (*A)(chi, psi, misign);
45  }
46 
47  unsigned long nFlops(void) const {
48  unsigned long nflops=A->nFlops();
49  return nflops;
50  }
51 
52  private:
54  };
55 
56 
57 
58 
59  //! M^dag linear operator over arrays
60  /*!
61  * \ingroup linop
62  *
63  * Linear operator forming M^dag 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  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
91 
92  (*A)(chi, psi, misign);
93  }
94 
95  unsigned long nFlops(void) const {
96  unsigned long nflops=A->nFlops();
97  return nflops;
98  }
99 
100  private:
102  };
103 
104 
105  //! M^dag linear operator
106  /*!
107  * \ingroup linop
108  *
109  * Linear operator forming M^dag from an operator M
110  */
111  template<typename T>
112  class approx_lmdag : public LinearOperator<T>
113  {
114  public:
115  //! Initialize pointer with existing pointer
116  /*! Requires that the pointer p is a return value of new */
118 
119  //! Copy pointer (one more owner)
121 
122  //! Destructor
124 
125  //! Subset comes from underlying operator
126  inline const Subset& subset() const {return A->subset();}
127 
128  //! Apply the operator onto a source std::vector
129  /*! For this operator, the sign is ignored */
130  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
131  {
132  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
133  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
134 
135  (*A)(chi, psi, misign);
136  }
137 
138  //! Apply the operator onto a source std::vector
139  /*! For this operator, the sign is ignored */
140  inline void operator() (T& chi, const T& psi, enum PlusMinus isign, Real epsilon) const
141  {
142  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
143  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
144 
145  (*A)(chi, psi, misign, epsilon/Real(2));
146  }
147 
148  private:
150  };
151 
152 
153  //! Differentiable M^dag linear operator
154  /*!
155  * \ingroup linop
156  *
157  * Diff. Linear operator forming M^dag from an operator M
158  */
159  template<typename T, typename P, typename Q>
160  class DiffMdagLinOp : public DiffLinearOperator<T,P,Q>
161  {
162  public:
163  //! Initialize pointer with existing pointer
164  /*! Requires that the pointer p is a return value of new */
166 
167  //! Copy pointer (one more owner)
169 
170  //! Destructor
172 
173  //! Return the fermion BC object for this linear operator
174  const FermBC<T,P,Q>& getFermBC() const {return A->getFermBC();}
175 
176  //! Subset comes from underlying operator
177  inline const Subset& subset() const {return A->subset();}
178 
179  //! Apply the operator onto a source std::vector
180  /*! For this operator, the sign is ignored */
181  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
182  {
183  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
184  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
185 
186  (*A)(chi, psi, misign);
187  }
188 
189  //! Apply the derivative of the operator
190  /*!
191  * Deriv of chi^dag * A^dag * psi
192  *
193  * Default implementation
194  */
195  virtual void deriv(P& ds_u, const T& chi, const T& psi,
196  enum PlusMinus isign) const
197  {
198  T tmp; QDP::Hints::moveToFastMemoryHint(tmp);
199  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
200 
201  A->deriv(ds_u, chi, psi, misign);
202  }
203 
204 
205  //! Apply the derivative of the operator
206  /*!
207  * Deriv of chi^dag * A^dag * psi
208  *
209  * Default implementation
210  */
211  virtual void deriv(P& ds_u, const T& chi, const T& psi,
212  enum PlusMinus isign, const Real& epsilon) const
213  {
214  T tmp;
215  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
216 
217  A->deriv(ds_u, chi, psi, misign, epsilon);
218  }
219 
220  //! Return the number of flops performed by operator()
221  unsigned long nFlops(void) const {return A->nFlops();}
222 
223  private:
225  };
226 
227 
228 
229 
230  //! M^dag linear operator over arrays
231  /*!
232  * \ingroup linop
233  *
234  * Linear operator forming M^dag from an operator M
235  */
236  template<typename T, typename P, typename Q>
238  {
239  public:
240  //! Initialize pointer with existing pointer
241  /*! Requires that the pointer p is a return value of new */
243 
244  //! Copy pointer (one more owner)
246 
247  //! Destructor
249 
250  //! Return the fermion BC object for this linear operator
251  const FermBC<T,P,Q>& getFermBC() const {return A->getFermBC();}
252 
253  //! Length of array index
254  int size() const {return A->size();}
255 
256  //! Subset comes from underlying operator
257  inline const Subset& subset() const {return A->subset();}
258 
259  //! Apply the operator onto a source std::vector
260  /*! For this operator, the sign is ignored */
261  inline void operator() (multi1d<T>& chi, const multi1d<T>& psi, enum PlusMinus isign) const
262  {
263  multi1d<T> tmp(size()); QDP::Hints::moveToFastMemoryHint(tmp);
264  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
265 
266  (*A)(chi, psi, misign);
267  }
268 
269  //! Apply the derivative of the operator
270  /*!
271  * Deriv of chi^dag * A^dag * psi
272  *
273  * Default implementation
274  */
275  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
276  enum PlusMinus isign) const
277  {
278  multi1d<T> tmp(size()); QDP::Hints::moveToFastMemoryHint(tmp);
279  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
280 
281  A->deriv(ds_u, chi, psi, misign);
282  }
283 
284 
285  //! Apply the derivative of the operator
286  /*!
287  * Deriv of chi^dag * A^dag * psi
288  *
289  * Default implementation
290  */
291  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
292  enum PlusMinus isign, const Real& epsilon) const
293  {
294  multi1d<T> tmp(size());
295  enum PlusMinus misign = (isign == PLUS) ? MINUS : PLUS;
296 
297  A->deriv(ds_u, chi, psi, misign, epsilon);
298  }
299 
300  //! Return the number of flops performed by operator()
301  unsigned long nFlops(void) const {return A->nFlops();}
302 
303  private:
305  };
306 
307 
308 } // End Namespace Chroma
309 
310 
311 #endif
Differentiable Linear Operator.
Definition: linearop.h:150
Differentiable Linear Operator.
Definition: linearop.h:98
M^dag linear operator over arrays.
Definition: ldag.h:238
~DiffMdagLinOpArray()
Destructor.
Definition: ldag.h:248
const Subset & subset() const
Subset comes from underlying operator.
Definition: ldag.h:257
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: ldag.h:275
void operator()(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: ldag.h:261
DiffMdagLinOpArray(DiffLinearOperatorArray< T, P, Q > *p)
Initialize pointer with existing pointer.
Definition: ldag.h:242
DiffMdagLinOpArray(Handle< DiffLinearOperatorArray< T, P, Q > > p)
Copy pointer (one more owner)
Definition: ldag.h:245
int size() const
Length of array index.
Definition: ldag.h:254
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
Definition: ldag.h:251
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: ldag.h:291
unsigned long nFlops(void) const
Return the number of flops performed by operator()
Definition: ldag.h:301
Handle< DiffLinearOperatorArray< T, P, Q > > A
Definition: ldag.h:304
Differentiable M^dag linear operator.
Definition: ldag.h:161
~DiffMdagLinOp()
Destructor.
Definition: ldag.h:171
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: ldag.h:211
DiffMdagLinOp(Handle< DiffLinearOperator< T, P, Q > > p)
Copy pointer (one more owner)
Definition: ldag.h:168
unsigned long nFlops(void) const
Return the number of flops performed by operator()
Definition: ldag.h:221
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: ldag.h:181
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
Definition: ldag.h:174
const Subset & subset() const
Subset comes from underlying operator.
Definition: ldag.h:177
DiffMdagLinOp(DiffLinearOperator< T, P, Q > *p)
Initialize pointer with existing pointer.
Definition: ldag.h:165
Handle< DiffLinearOperator< T, P, Q > > A
Definition: ldag.h:224
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Apply the derivative of the operator.
Definition: ldag.h:195
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 linear operator over arrays.
Definition: ldag.h:67
const Subset & subset() const
Subset comes from underlying operator.
Definition: ldag.h:83
void operator()(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: ldag.h:87
~MdagLinOpArray()
Destructor.
Definition: ldag.h:77
Handle< LinearOperatorArray< T > > A
Definition: ldag.h:101
int size() const
Length of array index.
Definition: ldag.h:80
MdagLinOpArray(LinearOperatorArray< T > *p)
Initialize pointer with existing pointer.
Definition: ldag.h:71
unsigned long nFlops(void) const
Definition: ldag.h:95
MdagLinOpArray(Handle< LinearOperatorArray< T > > p)
Copy pointer (one more owner)
Definition: ldag.h:74
M^dag linear operator.
Definition: ldag.h:22
~MdagLinOp()
Destructor.
Definition: ldag.h:32
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: ldag.h:39
MdagLinOp(Handle< LinearOperator< T > > p)
Copy pointer (one more owner)
Definition: ldag.h:29
unsigned long nFlops(void) const
Definition: ldag.h:47
MdagLinOp(LinearOperator< T > *p)
Initialize pointer with existing pointer.
Definition: ldag.h:26
const Subset & subset() const
Subset comes from underlying operator.
Definition: ldag.h:35
Handle< LinearOperator< T > > A
Definition: ldag.h:53
M^dag linear operator.
Definition: ldag.h:113
~approx_lmdagm()
Destructor.
Definition: ldag.h:123
const Subset & subset() const
Subset comes from underlying operator.
Definition: ldag.h:126
Handle< LinearOperator< T > > A
Definition: ldag.h:149
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: ldag.h:130
approx_lmdagm(Handle< LinearOperator< T > > p)
Copy pointer (one more owner)
Definition: ldag.h:120
approx_lmdagm(LinearOperator< T > *p)
Initialize pointer with existing pointer.
Definition: ldag.h:117
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