NAMD
PmeSolver.h
Go to the documentation of this file.
1 #ifndef PMESOLVER_H
2 #define PMESOLVER_H
3 #include <vector>
4 #include "ReductionMgr.h"
5 #include "PatchMap.h"
6 #include "PmeSolverUtil.h"
7 #include "PmeSolver.decl.h"
8 
9 class PmePencilXYZMap : public CBase_PmePencilXYZMap {
10 public:
11  PmePencilXYZMap(int pe) : pe(pe) {
12  }
13  //PmePencilXYZMap(CkMigrateMessage *m) {}
14  int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
15  return 0;
16  }
17  virtual int procNum(int, const CkArrayIndex& idx) {
18  return pe;
19  }
20  virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
21  if (pe == CkMyPe()) {
22  if ( ! msg ) NAMD_bug("PmePencilXYZMap::populateInitial, multiple pencils on a pe?");
23  mgr->insertInitial(CkArrayIndex1D(0), msg);
24  msg = NULL;
25  }
26  mgr->doneInserting();
27  if (msg != NULL) CkFreeMsg(msg);
28  }
29 private:
30  const int pe;
31 };
32 
33 class PmePencilXMap : public CBase_PmePencilXMap {
34 public:
35  PmePencilXMap(int ia, int ib, int width, const std::vector<int>& pes) : ia(ia), ib(ib), width(width), pes(pes) {}
36  int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
37  return 0;
38  }
39  virtual int procNum(int, const CkArrayIndex& idx) {
40  int ind = idx.data()[ia] + idx.data()[ib] * width;
41  if (ind < 0 || ind >= pes.size())
42  NAMD_bug("PmePencilXMap::procNum, index out of bounds");
43  return pes[ind];
44  }
45  virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
46  for (int i=0;i < pes.size();i++) {
47  if (pes[i] == CkMyPe()) {
48  if ( msg == NULL ) NAMD_bug("PmePencilXMap::populateInitial, multiple pencils on a pe?");
49  CkArrayIndex3D ai(0,0,0);
50  ai.data()[ib] = i / width;
51  ai.data()[ia] = i % width;
52  //fprintf(stderr, "Pe %d i %d at %d %d\n", pes[i], i, ai.data()[ia], ai.data()[ib]);
53  if ( procNum(0,ai) != CkMyPe() ) NAMD_bug("PmePencilXMap::populateInitial, map is inconsistent");
54  mgr->insertInitial(ai,msg);
55  msg = NULL;
56  }
57  }
58  mgr->doneInserting();
59  if (msg != NULL) CkFreeMsg(msg);
60  }
61 private:
62  // Index of CkArrayIndex data()
63  const int ia, ib;
64  // Width of the 2D array in pes
65  const int width;
66  // List of Pes. Index is given by pes[i + j*width]
67  const std::vector<int> pes;
68 };
69 
70 class PmePencilXYMap : public CBase_PmePencilXYMap {
71 public:
72  PmePencilXYMap(const std::vector<int>& pes) : pes(pes) {}
73  int registerArray(CkArrayIndex& numElements, CkArrayID aid) {
74  return 0;
75  }
76  virtual int procNum(int, const CkArrayIndex& idx) {
77  int ind = idx.data()[2];
78  if (ind < 0 || ind >= pes.size())
79  NAMD_bug("PmePencilXYMap::procNum, index out of bounds");
80  return pes[ind];
81  }
82  virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr) {
83  for (int i=0;i < pes.size();i++) {
84  if (pes[i] == CkMyPe()) {
85  if ( msg == NULL ) NAMD_bug("PmePencilXYMap::populateInitial, multiple pencils on a pe?");
86  CkArrayIndex3D ai(0,0,0);
87  ai.data()[2] = i;
88  if ( procNum(0,ai) != CkMyPe() ) NAMD_bug("PmePencilXYMap::populateInitial, map is inconsistent");
89  mgr->insertInitial(ai, msg);
90  msg = NULL;
91  }
92  }
93  mgr->doneInserting();
94  if (msg != NULL) CkFreeMsg(msg);
95  }
96 private:
97  // List of Pes.
98  const std::vector<int> pes;
99 };
100 
101 class PmeStartMsg : public CMessage_PmeStartMsg {
102 public:
103  float *data;
104  int dataSize;
105  int device;
106 };
107 
108 class PmeRunMsg : public CMessage_PmeRunMsg {
109 public:
113 };
114 
115 class PmeDoneMsg : public CMessage_PmeDoneMsg {
116 public:
117  PmeDoneMsg(int i, int j) : i(i), j(j) {}
118  int i, j;
119 };
120 
121 class PmeBlockMsg : public CMessage_PmeBlockMsg {
122 public:
124  int dataSize;
125  int x, y, z;
129 };
130 
131 class PmePencilXYZ : public CBase_PmePencilXYZ {
132 public:
133  PmePencilXYZ_SDAG_CODE
134  PmePencilXYZ();
135  PmePencilXYZ(CkMigrateMessage *m);
136  virtual ~PmePencilXYZ();
137  void skip();
138 protected:
145  virtual void backwardDone();
146  void submitReductions();
147 private:
148  void forwardFFT();
149  void backwardFFT();
150  void forwardDone();
151  void initFFT(PmeStartMsg *msg);
152 
153  SubmitReduction* reduction;
154 
155 };
156 
157 class PmePencilXY : public CBase_PmePencilXY {
158 public:
159  PmePencilXY_SDAG_CODE
160  PmePencilXY();
161  PmePencilXY(CkMigrateMessage *m);
162  virtual ~PmePencilXY();
163 protected:
168  std::vector<int> blockSizes;
171  void initBlockSizes();
172  int imsg;
173 private:
174  void forwardFFT();
175  void backwardFFT();
176  void initFFT(PmeStartMsg *msg);
177  virtual void forwardDone();
178  virtual void backwardDone();
179  virtual void recvDataFromZ(PmeBlockMsg *msg);
180  virtual void start(const CkCallback &);
181 
182 };
183 
184 class PmePencilX : public CBase_PmePencilX {
185 public:
186  PmePencilX_SDAG_CODE
187  PmePencilX();
188  PmePencilX(CkMigrateMessage *m);
189  virtual ~PmePencilX();
190 protected:
195  std::vector<int> blockSizes;
198  void initBlockSizes();
199  int imsg;
200 private:
201  void forwardFFT();
202  void backwardFFT();
203  void initFFT(PmeStartMsg *msg);
204  virtual void forwardDone();
205  virtual void backwardDone();
206  virtual void recvDataFromY(PmeBlockMsg *msg);
207  virtual void start(const CkCallback &);
208 
209 };
210 
211 class PmePencilY : public CBase_PmePencilY {
212 public:
213  PmePencilY_SDAG_CODE
214  PmePencilY();
215  PmePencilY(CkMigrateMessage *m);
216  virtual ~PmePencilY();
217 protected:
222  std::vector<int> blockSizes;
225  void initBlockSizes();
226  int imsg;
227 private:
228  void forwardFFT();
229  void backwardFFT();
230  void initFFT(PmeStartMsg *msg);
231  virtual void forwardDone();
232  virtual void backwardDone();
233  virtual void recvDataFromX(PmeBlockMsg *msg);
234  virtual void recvDataFromZ(PmeBlockMsg *msg);
235  virtual void start(const CkCallback &);
236 
237 };
238 
239 class PmePencilZ : public CBase_PmePencilZ {
240 public:
241  PmePencilZ_SDAG_CODE
242  PmePencilZ();
243  PmePencilZ(CkMigrateMessage *m);
244  virtual ~PmePencilZ();
245  void skip();
246 protected:
252  std::vector<int> blockSizes;
255  void initBlockSizes();
256  void submitReductions();
257  int imsg;
258 private:
259  void forwardFFT();
260  void backwardFFT();
261  void forwardDone();
262  void initFFT(PmeStartMsg *msg);
263  virtual void backwardDone();
264  virtual void recvDataFromY(PmeBlockMsg *msg);
265  virtual void start(const CkCallback &);
266 
267  SubmitReduction* reduction;
268 
269 };
270 
271 // #define CK_TEMPLATES_ONLY
272 // #include "PmeSolver.def.h"
273 // #undef CK_TEMPLATES_ONLY
274 
275 #endif // PMESOLVER_H
FFTCompute * fftCompute
Definition: PmeSolver.h:141
bool doEnergy
Definition: PmeSolver.h:126
virtual ~PmePencilXYZ()
Definition: PmeSolver.C:37
PmeDoneMsg(int i, int j)
Definition: PmeSolver.h:117
Lattice lattice
Definition: PmeSolver.h:253
bool doEnergy
Definition: PmeSolver.h:248
int numStrayAtoms
Definition: PmeSolver.h:111
FFTCompute * fftCompute
Definition: PmeSolver.h:193
PmePencilXYMap(const std::vector< int > &pes)
Definition: PmeSolver.h:72
std::vector< int > blockSizes
Definition: PmeSolver.h:252
bool doVirial
Definition: PmeSolver.h:165
int registerArray(CkArrayIndex &numElements, CkArrayID aid)
Definition: PmeSolver.h:14
virtual int procNum(int, const CkArrayIndex &idx)
Definition: PmeSolver.h:39
virtual ~PmePencilXY()
Definition: PmeSolver.C:136
void submitReductions()
Definition: PmeSolver.C:71
bool doVirial
Definition: PmeSolver.h:110
virtual void backwardDone()
Definition: PmeSolver.C:67
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:167
int registerArray(CkArrayIndex &numElements, CkArrayID aid)
Definition: PmeSolver.h:73
int numStrayAtoms
Definition: PmeSolver.h:170
virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr)
Definition: PmeSolver.h:20
PmeKSpaceCompute * pmeKSpaceCompute
Definition: PmeSolver.h:251
Lattice lattice
Definition: PmeSolver.h:143
PmePencilX_SDAG_CODE PmePencilX()
Definition: PmeSolver.C:222
int numStrayAtoms
Definition: PmeSolver.h:144
float2 * data
Definition: PmeSolver.h:123
std::vector< int > blockSizes
Definition: PmeSolver.h:222
PmeGrid pmeGrid
Definition: PmeSolver.h:164
bool doVirial
Definition: PmeSolver.h:248
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:250
std::vector< int > blockSizes
Definition: PmeSolver.h:195
int dataSize
Definition: PmeSolver.h:124
virtual ~PmePencilY()
Definition: PmeSolver.C:308
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:221
bool doVirial
Definition: PmeSolver.h:219
bool doVirial
Definition: PmeSolver.h:140
bool doVirial
Definition: PmeSolver.h:192
void initBlockSizes()
Definition: PmeSolver.C:261
PmePencilXMap(int ia, int ib, int width, const std::vector< int > &pes)
Definition: PmeSolver.h:35
int numStrayAtoms
Definition: PmeSolver.h:224
virtual int procNum(int, const CkArrayIndex &idx)
Definition: PmeSolver.h:17
bool doEnergy
Definition: PmeSolver.h:219
PmeGrid pmeGrid
Definition: PmeSolver.h:247
PmeGrid pmeGrid
Definition: PmeSolver.h:139
int numStrayAtoms
Definition: PmeSolver.h:127
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void initBlockSizes()
Definition: PmeSolver.C:331
PmePencilXY_SDAG_CODE PmePencilXY()
Definition: PmeSolver.C:121
PmeKSpaceCompute * pmeKSpaceCompute
Definition: PmeSolver.h:142
FFTCompute * fftCompute
Definition: PmeSolver.h:166
virtual int procNum(int, const CkArrayIndex &idx)
Definition: PmeSolver.h:76
std::vector< int > blockSizes
Definition: PmeSolver.h:168
PmePencilXYZ_SDAG_CODE PmePencilXYZ()
Definition: PmeSolver.C:18
bool doEnergy
Definition: PmeSolver.h:140
int dataSize
Definition: PmeSolver.h:104
Lattice lattice
Definition: PmeSolver.h:196
PmePencilZ_SDAG_CODE PmePencilZ()
Definition: PmeSolver.C:366
int registerArray(CkArrayIndex &numElements, CkArrayID aid)
Definition: PmeSolver.h:36
FFTCompute * fftCompute
Definition: PmeSolver.h:220
int numStrayAtoms
Definition: PmeSolver.h:254
PmePencilXYZMap(int pe)
Definition: PmeSolver.h:11
FFTCompute * fftCompute
Definition: PmeSolver.h:249
void skip()
Definition: PmeSolver.C:91
Lattice lattice
Definition: PmeSolver.h:223
virtual ~PmePencilX()
Definition: PmeSolver.C:238
bool doVirial
Definition: PmeSolver.h:126
bool doEnergy
Definition: PmeSolver.h:192
float * data
Definition: PmeSolver.h:103
Lattice lattice
Definition: PmeSolver.h:112
bool doEnergy
Definition: PmeSolver.h:165
virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr)
Definition: PmeSolver.h:45
void initBlockSizes()
Definition: PmeSolver.C:411
Lattice lattice
Definition: PmeSolver.h:169
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:194
virtual void populateInitial(int, CkArrayOptions &, void *msg, CkArrMgr *mgr)
Definition: PmeSolver.h:82
void submitReductions()
Definition: PmeSolver.C:428
void initBlockSizes()
Definition: PmeSolver.C:159
PmePencilY_SDAG_CODE PmePencilY()
Definition: PmeSolver.C:292
virtual ~PmePencilZ()
Definition: PmeSolver.C:386
PmeGrid pmeGrid
Definition: PmeSolver.h:218
PmeGrid pmeGrid
Definition: PmeSolver.h:191
Lattice lattice
Definition: PmeSolver.h:128
bool doEnergy
Definition: PmeSolver.h:110
int numStrayAtoms
Definition: PmeSolver.h:197
void skip()
Definition: PmeSolver.C:462