CHROMA
linear_extrap_predictor.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Linear extrapolation predictor
4  *
5  * Predictors for HMC
6  */
7 
8 #ifndef __linear_extrap_predictor_h__
9 #define __linear_extrap_predictor_h__
10 
11 #include "chromabase.h"
12 #include "handle.h"
16 
17 namespace Chroma
18 {
19 
20  /*! @ingroup predictor */
21  namespace LinearExtrapolation4DChronoPredictorEnv
22  {
23  extern const std::string name;
24  bool registerAll();
25  }
26 
27  //! Last solution predictor
28  /*! @ingroup predictor */
30  public AbsTwoStepChronologicalPredictor4D<LatticeFermion>
31  {
32  private:
35 
36  public:
37  LinearExtrapolation4DChronoPredictor(void) : chrono_bufX(new CircularBuffer<LatticeFermion>((unsigned int)2)), chrono_bufY(new CircularBuffer<LatticeFermion>((unsigned int)2)) {}
38 
39  // Destructor is automagic
41 
42 
43  void guess(LatticeFermion& psi,
45  const LatticeFermion& chi,
47  {
48  START_CODE();
49 
50  switch( chrono_buf->size() ) {
51  case 0:
52  {
53  QDPIO::cout << "LinearExtrapolationPredictor: giving you zero" << std::endl;
54  psi = zero;
55  }
56  break;
57 
58  case 1:
59  {
60  QDPIO::cout << "LinearExtrapolationPredictor: giving you last soln" << std::endl;
61  chrono_buf->get(0,psi);
62  }
63  break;
64 
65  case 2:
66  {
67  QDPIO::cout << "LinearExtrapolationPredictor: giving you linear extrapolation" << std::endl;
68 
69  LatticeFermion y0;
70  chrono_buf->get(0,y0); // Most recent
71 
72  LatticeFermion y1;
73  chrono_buf->get(1,y1); // Least recent
74 
75  psi = Real(2)*y0 - y1; // Linear Extrapolation
76 
77  }
78  break;
79  default:
80  QDPIO::cerr << "Unknown case reached in LinearExtrapPredictor " << std::endl;
81  QDP_abort(1);
82  break;
83  }
84 
85  END_CODE();
86  }
87 
88  void predictX(LatticeFermion& X,
90  const LatticeFermion& chi) {
92  }
93 
94  void predictY(LatticeFermion& Y,
96  const LatticeFermion& chi) {
98  }
99 
100 
101  // No internal state so reset is a nop
102  void reset(void) {
103  chrono_bufX->reset();
104  chrono_bufY->reset();
105  }
106 
107  // Ignore new std::vector
108  void newXVector(const LatticeFermion& X)
109  {
110  START_CODE();
111 
112  QDPIO::cout << "LinearExtrapolationPredictor: registering new X solution. ";
113  chrono_bufX->push(X);
114  QDPIO::cout << " number of vectors stored is = " << chrono_bufX->size() << std::endl;
115 
116  END_CODE();
117  }
118 
119  // Ignore new std::vector
120  void newYVector(const LatticeFermion& Y)
121  {
122  START_CODE();
123 
124  QDPIO::cout << "LinearExtrapolationPredictor: registering new Y solution. ";
125  chrono_bufY->push(Y);
126  QDPIO::cout << " number of vectors stored is = " << chrono_bufY->size() << std::endl;
127 
128  END_CODE();
129  }
130 
131 
132  };
133 
134 
135 
136  /*! @ingroup predictor */
137  namespace LinearExtrapolation5DChronoPredictorEnv
138  {
139  extern const std::string name;
140  bool registerAll();
141  }
142 
143  //! Last solution predictor
144  /*! @ingroup predictor */
146  public AbsChronologicalPredictor5D<LatticeFermion>
147  {
148  private:
150  const int N5;
151 
152  public:
153  LinearExtrapolation5DChronoPredictor(const int N5_) : chrono_buf( new CircularBufferArray<LatticeFermion>(2, N5_) ), N5(N5_) {}
154 
155 
157 
158  // Copying
160 
161  // Zero out psi -- it is a zero guess after all
162  void operator()(multi1d<LatticeFermion>& psi,
164  const multi1d<LatticeFermion>& chi)
165  {
166  START_CODE();
167 
168  switch( chrono_buf->size() ) {
169  case 0:
170  {
171  QDPIO::cout << "LinearExtrapolationPredictor: giving you zero" << std::endl;
172  psi = zero;
173  }
174  break;
175 
176  case 1:
177  {
178  QDPIO::cout << "LinearExtrapolationPredictor: giving you last soln" << std::endl;
179  chrono_buf->get(0, psi);
180  }
181  break;
182 
183  case 2:
184  {
185 
186  QDPIO::cout << "LinearExtrapolationPredictor: giving you linear extrapolation" << std::endl;
187 
188  multi1d<LatticeFermion> y0(N5);
189  chrono_buf->get(0, y0);
190 
191  multi1d<LatticeFermion> y1(N5);
192  chrono_buf->get(1, y1);
193 
194  psi.resize(N5);
195  for(int s = 0; s < N5; s++) {
196  psi[s] = Real(2)*y0[s] - y1[s]; // Linear Extrapolation
197  }
198  }
199  break;
200  default:
201  QDPIO::cerr << "Unknown case reached in LinearExtrapPredictor " << std::endl;
202  QDP_abort(1);
203  break;
204  }
205 
206  END_CODE();
207  }
208 
209 
210  // No internal state so reset is a Nop
211  void reset(void) {
212  chrono_buf->reset();
213  }
214 
215  // Ignore new std::vector
216  // Ignore new std::vector
217  void newVector(const multi1d<LatticeFermion>& psi)
218  {
219  START_CODE();
220 
221  QDPIO::cout << "LinearExtrapolationPredictor: registering new solution. ";
222  chrono_buf->push(psi);
223  QDPIO::cout << " number of vectors stored is = " << chrono_buf->size() << std::endl;
224 
225  END_CODE();
226  }
227 
228  };
229 
230 } // End Namespace Chroma
231 
232 #endif
Primary include file for CHROMA library code.
Chronological predictor for HMC.
Monomial factories.
Circular buffers.
Abstract interface for a Chronological Solution predictor in 5D.
Abstract interface for a Chronological Solution predictor.
Circular buffer of arrays.
Circular Buffer.
Class for counted reference semantics.
Definition: handle.h:33
void predictX(LatticeFermion &X, const LinearOperator< LatticeFermion > &A, const LatticeFermion &chi)
Handle< CircularBuffer< LatticeFermion > > chrono_bufX
Handle< CircularBuffer< LatticeFermion > > chrono_bufY
void predictY(LatticeFermion &Y, const LinearOperator< LatticeFermion > &A, const LatticeFermion &chi)
void guess(LatticeFermion &psi, const LinearOperator< LatticeFermion > &A, const LatticeFermion &chi, Handle< CircularBuffer< LatticeFermion > > chrono_buf)
Handle< CircularBufferArray< LatticeFermion > > chrono_buf
void operator()(multi1d< LatticeFermion > &psi, const LinearOperatorArray< LatticeFermion > &A, const multi1d< LatticeFermion > &chi)
void newVector(const multi1d< LatticeFermion > &psi)
LinearExtrapolation5DChronoPredictor(const LinearExtrapolation5DChronoPredictor &p)
Linear Operator to arrays.
Definition: linearop.h:61
Class for counted reference semantics.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
A(A, psi, r, Ncb, PLUS)
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979