NAMD
PmeSolver.C
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "Priorities.h"
3 #if !defined(NAMD_HIP)
4 struct float2 {float x,y;};
5 #endif
6 #include "PmeSolver.h"
7 
8 //
9 // Data flow for PmePencilXYZ
10 //
11 // dataSrc [xyz] dataDst
12 //
13 // dataDst [solve] dataDst
14 //
15 // dataDst [xyz] dataSrc
16 //
17 // dataSrc [force]
18 //
19 
21  __sdag_init();
22  setMigratable(false);
23  fftCompute = NULL;
24  pmeKSpaceCompute = NULL;
26  doEnergy = false;
27  doVirial = false;
28 }
29 
30 PmePencilXYZ::PmePencilXYZ(CkMigrateMessage *m) {
31  NAMD_bug("PmePencilXYZ cannot be migrated");
32  //__sdag_init();
33  // setMigratable(false);
34  // fftCompute = NULL;
35  // pmeKSpaceCompute = NULL;
36  // reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
37 }
38 
40  if (fftCompute != NULL) delete fftCompute;
41  if (pmeKSpaceCompute != NULL) delete pmeKSpaceCompute;
42  delete reduction;
43 }
44 
45 void PmePencilXYZ::initFFT(PmeStartMsg *msg) {
46  if (fftCompute == NULL)
47  NAMD_bug("PmePencilXYZ::initFFT, fftCompute not initialized");
48  fftCompute->init(msg->data, msg->dataSize, NULL, 0, Perm_X_Y_Z, pmeGrid, 3, 0, 0, 0);
49 }
50 
51 void PmePencilXYZ::forwardFFT() {
52  if (fftCompute == NULL)
53  NAMD_bug("PmePencilXYZ::forwardFFT, fftCompute not initialized");
55 }
56 
57 void PmePencilXYZ::backwardFFT() {
58  if (fftCompute == NULL)
59  NAMD_bug("PmePencilXYZ::backwardFFT, fftCompute not initialized");
61 }
62 
63 void PmePencilXYZ::forwardDone() {
64  if (pmeKSpaceCompute == NULL)
65  NAMD_bug("PmePencilXYZ::forwardDone, pmeKSpaceCompute not initialized");
67 }
68 
70  NAMD_bug("PmePencilXYZ::backwardDone(), base class method called");
71 }
72 
74  if (pmeKSpaceCompute == NULL)
75  NAMD_bug("PmePencilXYZ::submitReductions, pmeKSpaceCompute not initialized");
76  double virial[9];
77  double energy = pmeKSpaceCompute->getEnergy();
78  pmeKSpaceCompute->getVirial(virial);
79  reduction->item(REDUCTION_ELECT_ENERGY_SLOW) += energy;
80  reduction->item(REDUCTION_VIRIAL_SLOW_XX) += virial[0];
81  reduction->item(REDUCTION_VIRIAL_SLOW_XY) += virial[1];
82  reduction->item(REDUCTION_VIRIAL_SLOW_XZ) += virial[2];
83  reduction->item(REDUCTION_VIRIAL_SLOW_YX) += virial[3];
84  reduction->item(REDUCTION_VIRIAL_SLOW_YY) += virial[4];
85  reduction->item(REDUCTION_VIRIAL_SLOW_YZ) += virial[5];
86  reduction->item(REDUCTION_VIRIAL_SLOW_ZX) += virial[6];
87  reduction->item(REDUCTION_VIRIAL_SLOW_ZY) += virial[7];
88  reduction->item(REDUCTION_VIRIAL_SLOW_ZZ) += virial[8];
90  reduction->submit();
91 }
92 
94  reduction->submit();
95 }
96 
97 //###########################################################################
98 //###########################################################################
99 //###########################################################################
100 
101 //
102 // Data flow for PmePencilXY & PmePencilZ
103 //
104 // dataSrc(XY) [xy] dataDst(XY)
105 //
106 // dataDst(XY) [transp] dataSrc(Z)
107 //---------------------------------
108 //
109 // dataSrc(Z) [z] dataDst(Z)
110 //
111 // dataDst(Z) [solve] dataDst(Z)
112 //
113 // dataDst(Z) [z] dataSrc(Z)
114 //
115 // dataSrc(Z) [transp] dataDst(XY)
116 //---------------------------------
117 //
118 // dataDst(XY) [xy] dataSrc(XY)
119 //
120 // dataSrc(XY) [force]
121 //
122 
124  __sdag_init();
125  setMigratable(false);
126  fftCompute = NULL;
127  pmeTranspose = NULL;
128 }
129 
130 PmePencilXY::PmePencilXY(CkMigrateMessage *m) {
131  NAMD_bug("PmePencilXY cannot be migrated");
132 //__sdag_init();
133  // setMigratable(false);
134  // fftCompute = NULL;
135  // pmeTranspose = NULL;
136 }
137 
139  if (fftCompute != NULL) delete fftCompute;
140  if (pmeTranspose != NULL) delete pmeTranspose;
141 }
142 
143 void PmePencilXY::initFFT(PmeStartMsg *msg) {
144  if (fftCompute == NULL)
145  NAMD_bug("PmePencilXY::initFFT, fftCompute not initialized");
146  fftCompute->init(msg->data, msg->dataSize, NULL, 0, Perm_X_Y_Z, pmeGrid, 2, 0, thisIndex.z, 0);
147 }
148 
149 void PmePencilXY::forwardFFT() {
150  if (fftCompute == NULL)
151  NAMD_bug("PmePencilXY::forwardFFT, fftCompute not initialized");
152  fftCompute->forward();
153 }
154 
155 void PmePencilXY::backwardFFT() {
156  if (fftCompute == NULL)
157  NAMD_bug("PmePencilXY::backwardFFT, fftCompute not initialized");
158  fftCompute->backward();
159 }
160 
162  blockSizes.resize(pmeGrid.xBlocks);
163  for (int x=0;x < pmeGrid.xBlocks;x++) {
164  int i0, i1, j0, j1, k0, k1;
165  getBlockDim(pmeGrid, Perm_cX_Y_Z, x, 0, thisIndex.z,
166  i0, i1, j0, j1, k0, k1);
167  int size = (i1-i0+1)*(j1-j0+1)*(k1-k0+1);
168  blockSizes[x] = size;
169  }
170 }
171 
172 void PmePencilXY::forwardDone() {
173  NAMD_bug("PmePencilXY::forwardDone(), base class method called");
174 }
175 
176 void PmePencilXY::backwardDone() {
177  NAMD_bug("PmePencilXY::backwardDone(), base class method called");
178 }
179 
180 void PmePencilXY::recvDataFromZ(PmeBlockMsg *msg) {
181  NAMD_bug("PmePencilXY::recvDataFromZ(), base class method called");
182 }
183 
184 void PmePencilXY::start(const CkCallback &) {
185  NAMD_bug("PmePencilXY::start(), base class method called");
186 }
187 
188 //###########################################################################
189 //###########################################################################
190 //###########################################################################
191 
192 //
193 // Data flow for PmePencilX & PmePencilX & PmePencilZ
194 //
195 // dataSrc(X) [x] dataDst(X)
196 //
197 // dataDst(X) [transp] dataSrc(Y)
198 //---------------------------------
199 //
200 // dataSrc(Y) [y] dataDst(Y)
201 //
202 // dataDst(Y) [transp] dataSrc(Z)
203 //---------------------------------
204 //
205 // dataSrc(Z) [z] dataDst(Z)
206 //
207 // dataDst(Z) [solve] dataDst(Z)
208 //
209 // dataDst(Z) [z] dataSrc(Z)
210 //
211 // dataSrc(Z) [transp] dataDst(Y)
212 //---------------------------------
213 //
214 // dataDst(Y) [y] dataSrc(Y)
215 //
216 // dataSrc(Y) [transp] dataDst(X)
217 //---------------------------------
218 //
219 // dataDst(X) [x] dataSrc(X)
220 //
221 // dataSrc(X) [force]
222 //
223 
225  __sdag_init();
226  setMigratable(false);
227  fftCompute = NULL;
228  pmeTranspose = NULL;
229  numStrayAtoms = 0;
230 }
231 
232 PmePencilX::PmePencilX(CkMigrateMessage *m) {
233  NAMD_bug("PmePencilX cannot be migrated");
234 //__sdag_init();
235  // setMigratable(false);
236  // fftCompute = NULL;
237  // pmeTranspose = NULL;
238 }
239 
241  if (fftCompute != NULL) delete fftCompute;
242  if (pmeTranspose != NULL) delete pmeTranspose;
243 }
244 
245 void PmePencilX::initFFT(PmeStartMsg *msg) {
246  if (fftCompute == NULL)
247  NAMD_bug("PmePencilX::initFFT, fftCompute not initialized");
248  fftCompute->init(msg->data, msg->dataSize, NULL, 0, Perm_X_Y_Z, pmeGrid, 1, thisIndex.y, thisIndex.z, 0);
249 }
250 
251 void PmePencilX::forwardFFT() {
252  if (fftCompute == NULL)
253  NAMD_bug("PmePencilX::forwardFFT, fftCompute not initialized");
254  fftCompute->forward();
255 }
256 
257 void PmePencilX::backwardFFT() {
258  if (fftCompute == NULL)
259  NAMD_bug("PmePencilX::backwardFFT, fftCompute not initialized");
260  fftCompute->backward();
261 }
262 
264  blockSizes.resize(pmeGrid.xBlocks);
265  for (int x=0;x < pmeGrid.xBlocks;x++) {
266  int i0, i1, j0, j1, k0, k1;
267  getBlockDim(pmeGrid, Perm_cX_Y_Z, x, thisIndex.y, thisIndex.z,
268  i0, i1, j0, j1, k0, k1);
269  int size = (i1-i0+1)*(j1-j0+1)*(k1-k0+1);
270  blockSizes[x] = size;
271  }
272 }
273 
274 void PmePencilX::forwardDone() {
275  NAMD_bug("PmePencilX::forwardDone(), base class method called");
276 }
277 
278 void PmePencilX::backwardDone() {
279  NAMD_bug("PmePencilX::backwardDone(), base class method called");
280 }
281 
282 void PmePencilX::recvDataFromY(PmeBlockMsg *msg) {
283  NAMD_bug("PmePencilX::recvDataFromY(), base class method called");
284 }
285 
286 void PmePencilX::start(const CkCallback &) {
287  NAMD_bug("PmePencilX::start(), base class method called");
288 }
289 
290 //###########################################################################
291 //###########################################################################
292 //###########################################################################
293 
295  __sdag_init();
296  setMigratable(false);
297  fftCompute = NULL;
298  pmeTranspose = NULL;
299  numStrayAtoms = 0;
300 }
301 
302 PmePencilY::PmePencilY(CkMigrateMessage *m) {
303  NAMD_bug("PmePencilY cannot be migrated");
304  // __sdag_init();
305  // setMigratable(false);
306  // fftCompute = NULL;
307  // pmeTranspose = NULL;
308 }
309 
311  if (fftCompute != NULL) delete fftCompute;
312  if (pmeTranspose != NULL) delete pmeTranspose;
313 }
314 
315 void PmePencilY::initFFT(PmeStartMsg *msg) {
316  if (fftCompute == NULL)
317  NAMD_bug("PmePencilY::initFFT, fftCompute not initialized");
318  fftCompute->init(msg->data, msg->dataSize, NULL, 0, Perm_Y_Z_cX, pmeGrid, 1, thisIndex.z, thisIndex.x, 0);
319 }
320 
321 void PmePencilY::forwardFFT() {
322  if (fftCompute == NULL)
323  NAMD_bug("PmePencilY::forwardFFT, fftCompute not initialized");
324  fftCompute->forward();
325 }
326 
327 void PmePencilY::backwardFFT() {
328  if (fftCompute == NULL)
329  NAMD_bug("PmePencilY::backwardFFT, fftCompute not initialized");
330  fftCompute->backward();
331 }
332 
334  blockSizes.resize(pmeGrid.yBlocks);
335  for (int y=0;y < pmeGrid.yBlocks;y++) {
336  int i0, i1, j0, j1, k0, k1;
337  getBlockDim(pmeGrid, Perm_Y_Z_cX, y, thisIndex.z, thisIndex.x,
338  i0, i1, j0, j1, k0, k1);
339  int size = (i1-i0+1)*(j1-j0+1)*(k1-k0+1);
340  blockSizes[y] = size;
341  }
342 }
343 
344 void PmePencilY::forwardDone() {
345  NAMD_bug("PmePencilY::forwardDone(), base class method called");
346 }
347 
348 void PmePencilY::backwardDone() {
349  NAMD_bug("PmePencilY::backwardDone(), base class method called");
350 }
351 
352 void PmePencilY::recvDataFromX(PmeBlockMsg *msg) {
353  NAMD_bug("PmePencilY::recvDataFromX(), base class method called");
354 }
355 
356 void PmePencilY::recvDataFromZ(PmeBlockMsg *msg) {
357  NAMD_bug("PmePencilY::recvDataFromZ(), base class method called");
358 }
359 
360 void PmePencilY::start(const CkCallback &) {
361  NAMD_bug("PmePencilY::start(), base class method called");
362 }
363 
364 //###########################################################################
365 //###########################################################################
366 //###########################################################################
367 
369  __sdag_init();
370  setMigratable(false);
371  fftCompute = NULL;
372  pmeTranspose = NULL;
373  pmeKSpaceCompute = NULL;
375  doEnergy = false;
376  doVirial = false;
377  numStrayAtoms = 0;
378 }
379 
380 PmePencilZ::PmePencilZ(CkMigrateMessage *m) {
381  NAMD_bug("PmePencilZ cannot be migrated");
382  //__sdag_init();
383  // setMigratable(false);
384  // fftCompute = NULL;
385  // pmeTranspose = NULL;
386 }
387 
389  if (fftCompute != NULL) delete fftCompute;
390  if (pmeTranspose != NULL) delete pmeTranspose;
391  if (pmeKSpaceCompute != NULL) delete pmeKSpaceCompute;
392  delete reduction;
393 }
394 
395 void PmePencilZ::initFFT(PmeStartMsg *msg) {
396  if (fftCompute == NULL)
397  NAMD_bug("PmePencilZ::initFFT, fftCompute not initialized");
398  fftCompute->init(msg->data, msg->dataSize, NULL, 0, Perm_Z_cX_Y, pmeGrid, 1, thisIndex.x, thisIndex.y, 0);
399 }
400 
401 void PmePencilZ::forwardFFT() {
402  if (fftCompute == NULL)
403  NAMD_bug("PmePencilZ::forwardFFT, fftCompute not initialized");
404  fftCompute->forward();
405 }
406 
407 void PmePencilZ::backwardFFT() {
408  if (fftCompute == NULL)
409  NAMD_bug("PmePencilZ::backwardFFT, fftCompute not initialized");
410  fftCompute->backward();
411 }
412 
414  blockSizes.resize(pmeGrid.zBlocks);
415  for (int z=0;z < pmeGrid.zBlocks;z++) {
416  int i0, i1, j0, j1, k0, k1;
417  getBlockDim(pmeGrid, Perm_Z_cX_Y, z, thisIndex.x, thisIndex.y,
418  i0, i1, j0, j1, k0, k1);
419  int size = (i1-i0+1)*(j1-j0+1)*(k1-k0+1);
420  blockSizes[z] = size;
421  }
422 }
423 
424 void PmePencilZ::forwardDone() {
425  if (pmeKSpaceCompute == NULL)
426  NAMD_bug("PmePencilZ::forwardDone, pmeKSpaceCompute not initialized");
428 }
429 
431  if (pmeKSpaceCompute == NULL)
432  NAMD_bug("PmePencilZ::submitReductions, pmeKSpaceCompute not initialized");
433  double virial[9];
434  double energy = pmeKSpaceCompute->getEnergy();
435  // fprintf(stderr, "PmePencilZ::submitReductions(), numStrayAtoms %d\n", numStrayAtoms);
436  pmeKSpaceCompute->getVirial(virial);
437  reduction->item(REDUCTION_ELECT_ENERGY_SLOW) += energy;
438  reduction->item(REDUCTION_VIRIAL_SLOW_XX) += virial[0];
439  reduction->item(REDUCTION_VIRIAL_SLOW_XY) += virial[1];
440  reduction->item(REDUCTION_VIRIAL_SLOW_XZ) += virial[2];
441  reduction->item(REDUCTION_VIRIAL_SLOW_YX) += virial[3];
442  reduction->item(REDUCTION_VIRIAL_SLOW_YY) += virial[4];
443  reduction->item(REDUCTION_VIRIAL_SLOW_YZ) += virial[5];
444  reduction->item(REDUCTION_VIRIAL_SLOW_ZX) += virial[6];
445  reduction->item(REDUCTION_VIRIAL_SLOW_ZY) += virial[7];
446  reduction->item(REDUCTION_VIRIAL_SLOW_ZZ) += virial[8];
448  reduction->submit();
449  numStrayAtoms = 0;
450 }
451 
452 void PmePencilZ::backwardDone() {
453  NAMD_bug("PmePencilZ::backwardDone(), base class method called");
454 }
455 
456 void PmePencilZ::recvDataFromY(PmeBlockMsg *msg) {
457  NAMD_bug("PmePencilY::recvDataFromY(), base class method called");
458 }
459 
460 void PmePencilZ::start(const CkCallback &) {
461  NAMD_bug("PmePencilZ::start(), base class method called");
462 }
463 
465  reduction->submit();
466 }
467 
468 #include "PmeSolver.def.h"
FFTCompute * fftCompute
Definition: PmeSolver.h:141
virtual ~PmePencilXYZ()
Definition: PmeSolver.C:39
int zBlocks
Definition: PmeBase.h:22
Lattice lattice
Definition: PmeSolver.h:253
bool doEnergy
Definition: PmeSolver.h:248
FFTCompute * fftCompute
Definition: PmeSolver.h:193
std::vector< int > blockSizes
Definition: PmeSolver.h:252
virtual void solve(Lattice &lattice, const bool doEnergy, const bool doVirial, float *data)=0
float x
Definition: PmeSolver.C:4
virtual ~PmePencilXY()
Definition: PmeSolver.C:138
void submitReductions()
Definition: PmeSolver.C:73
virtual void backwardDone()
Definition: PmeSolver.C:69
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:167
virtual void backward()=0
BigReal & item(int i)
Definition: ReductionMgr.h:312
PmeKSpaceCompute * pmeKSpaceCompute
Definition: PmeSolver.h:251
SubmitReduction * willSubmit(int setID, int size=-1)
Definition: ReductionMgr.C:365
Lattice lattice
Definition: PmeSolver.h:143
PmePencilX_SDAG_CODE PmePencilX()
Definition: PmeSolver.C:224
static ReductionMgr * Object(void)
Definition: ReductionMgr.h:278
int numStrayAtoms
Definition: PmeSolver.h:144
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
virtual ~PmePencilY()
Definition: PmeSolver.C:310
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:221
int yBlocks
Definition: PmeBase.h:22
bool doVirial
Definition: PmeSolver.h:140
void initBlockSizes()
Definition: PmeSolver.C:263
float y
Definition: PmeSolver.C:4
int numStrayAtoms
Definition: PmeSolver.h:224
PmeGrid pmeGrid
Definition: PmeSolver.h:247
PmeGrid pmeGrid
Definition: PmeSolver.h:139
void NAMD_bug(const char *err_msg)
Definition: common.C:123
void initBlockSizes()
Definition: PmeSolver.C:333
PmePencilXY_SDAG_CODE PmePencilXY()
Definition: PmeSolver.C:123
PmeKSpaceCompute * pmeKSpaceCompute
Definition: PmeSolver.h:142
FFTCompute * fftCompute
Definition: PmeSolver.h:166
std::vector< int > blockSizes
Definition: PmeSolver.h:168
gridSize z
PmePencilXYZ_SDAG_CODE PmePencilXYZ()
Definition: PmeSolver.C:20
bool doEnergy
Definition: PmeSolver.h:140
int dataSize
Definition: PmeSolver.h:104
virtual void getVirial(double *virial)=0
PmePencilZ_SDAG_CODE PmePencilZ()
Definition: PmeSolver.C:368
float * getDataDst()
FFTCompute * fftCompute
Definition: PmeSolver.h:220
int numStrayAtoms
Definition: PmeSolver.h:254
FFTCompute * fftCompute
Definition: PmeSolver.h:249
void skip()
Definition: PmeSolver.C:93
virtual ~PmePencilX()
Definition: PmeSolver.C:240
float * data
Definition: PmeSolver.h:103
static void getBlockDim(const PmeGrid &pmeGrid, const int permutation, const int iblock, const int jblock, const int kblock, int &i0, int &i1, int &j0, int &j1, int &k0, int &k1)
Definition: PmeSolverUtil.h:86
void init(float *dataSrc_in, int dataSrcSize_in, float *dataDst_in, int dataDstSize_in, int permutation, PmeGrid pmeGrid, int pmePencilType, int jblock, int kblock, int flags)
gridSize y
virtual void forward()=0
void initBlockSizes()
Definition: PmeSolver.C:413
PmeTranspose * pmeTranspose
Definition: PmeSolver.h:194
void submit(void)
Definition: ReductionMgr.h:323
void submitReductions()
Definition: PmeSolver.C:430
int xBlocks
Definition: PmeBase.h:22
void initBlockSizes()
Definition: PmeSolver.C:161
gridSize x
PmePencilY_SDAG_CODE PmePencilY()
Definition: PmeSolver.C:294
virtual ~PmePencilZ()
Definition: PmeSolver.C:388
PmeGrid pmeGrid
Definition: PmeSolver.h:218
PmeGrid pmeGrid
Definition: PmeSolver.h:191
virtual double getEnergy()=0
int numStrayAtoms
Definition: PmeSolver.h:197
void skip()
Definition: PmeSolver.C:464