OpenAtom  Version1.5a
gspace.ci
1 /** \file CP_State_GSpacePlane.C
2  @addtogroup GSpaceState
3  @{
4 */
5 
6 #ifdef _CP_DEBUG_PSI_OFF_
7 #define _SDAG_DEBUG_PSI_OFF_ true
8 #else
9 #define _SDAG_DEBUG_PSI_OFF_ false
10 #endif
11 
12 #ifdef _CP_DEBUG_SFNL_OFF_
13 #define _SDAG_DEBUG_SFNL_OFF_ true
14 #else
15 #define _SDAG_DEBUG_SFNL_OFF_ false
16 #endif
17 
18 #ifdef _CP_DEBUG_VKS_OFF_
19 #define _SDAG_DEBUG_VKS_OFF_ true
20 #else
21 #define _SDAG_DEBUG_VKS_OFF_ false
22 #endif
23 
24 #ifdef _CP_DEBUG_ORTHO_OFF_
25 #define _SDAG_DEBUG_ORTHO_OFF_ true
26 #else
27 #define _SDAG_DEBUG_ORTHO_OFF_ false
28 #endif
29 
30 module gSpaceDriver
31 {
32  include "uber/Uber.h";
33  array [2D] GSpaceDriver
34  {
35  // Constructor(s)
36  entry GSpaceDriver(const UberCollection _thisInstance);
37 
38  // Start and stop the flow control using SDAG
39  entry void startControl();
40 
41  // Requests to trigger things
42  entry void needUpdatedPsiV();
43  entry void startNonLocalEes(int iteration_loc);
44 
45  // Incoming notifications of task completion
46  entry void doneComputingEnergy(const int AtomGrpIter);
47  entry void doneMovingAtoms(const int AtomGrpIter);
48  entry void donePsiFandVKS();
49  entry void doneLambdaAndCg();
50  entry void doneRedPsi();
51  entry void doneNewPsi();
52  entry void donePsiV();
53  entry void doneOutput();
54  entry void doneNLForces();
55 
56  // Incoming reduction barrier notifications
57  entry [nokeep] void allDoneNLForces(CkReductionMsg *msg) { serial { doneNLForces(); } };
58 
59  //! \brief SDAG method for flow control of the Driver and its associated GSpace object
60  entry void driveGSpace() {
61  //! Loop until we hit the last iteration, or the GSpacePlane has signaled
62  //! that we have met the desired tolerance by setting exitFlag to 1.
63  while(myGSpaceObj->iteration < config.maxIter && !myGSpaceObj->exitFlag && !myGSpaceObj->exitFlagMin) {
64  if ((cp_min_opt==1 && gen_wave==0) || isFirstStep==false) {
65  //! Resets flags and increases the iteration counter
66  serial { myGSpaceObj->thisProxy(thisIndex.x,thisIndex.y).startNewIter(); }
67 
68  if (!_SDAG_DEBUG_PSI_OFF_) {
69  //! If called, releaseSFComputeZ() triggers an NL force computation.
70  if (!_SDAG_DEBUG_SFNL_OFF_ && ees_nonlocal==0 && natm_nl!=0) serial {
71  releaseSFComputeZ();
72  }
73 
74  //! Both branches of this if will trigger an NL force computation if
75  //! releaseSFComputeZ() was not called above.
76  if (!_SDAG_DEBUG_VKS_OFF_) serial {
77  myGSpaceObj->computePsiFandVKS();
78  } else if (!_SDAG_DEBUG_SFNL_OFF_ && ees_nonlocal==1 && natm_nl!=0) serial {
79  startNonLocalEes(myGSpaceObj->iteration);
80  }
81 
82  //! Wait for both the VKS and the NL force computations to complete.
83  overlap {
84  if (!_SDAG_DEBUG_SFNL_OFF_) {
85  when doneNLForces() {}
86  }
87  if (!_SDAG_DEBUG_VKS_OFF_) {
88  when donePsiFandVKS() {}
89  }
90  }
91 
92  serial { myGSpaceObj->combineForcesGetEke(); }
93  } // end if !_SDAG_DEBUG_PSI_OFF_
94 
95  serial { myGSpaceObj->launchAtoms(); }
96 
97  if (!_SDAG_DEBUG_PSI_OFF_) {
98  serial { myGSpaceObj->computeLambdaAndCg(); }
99  when doneLambdaAndCg() {}
100 
101  //! If output is on and we are doing dynamics then dump to file
102  //! every ndump_frq iteration as well as the final iteration. We
103  //! skip the first iterations because nothing moves before iter 2.
104  if (config.stateOutput==1 && cp_min_opt==0 && myGSpaceObj->iteration > 1 &&
105  (myGSpaceObj->iteration % ndump_frq==1 || myGSpaceObj->iteration==config.maxIter || myGSpaceObj->exitFlag==1)) {
106  serial { myGSpaceObj->doOutput(); }
107  when doneOutput() {}
108  }
109 
110  serial { myGSpaceObj->computeRedPsi(); }
111  when doneRedPsi() {}
112  } // end if !_SDAG_DEBUG_PSI_OFF_
113  } // end if (cp_min_opt==1 && gen_wave==0) || firstStep==false
114 
115  if (!_SDAG_DEBUG_PSI_OFF_) {
116  serial { myGSpaceObj->computeNewPsi(); }
117  when doneNewPsi() {}
118 
119  //! If output is on and we are doing minimization then dump to file
120  //! every ndump_frq iteration as well as the final iteration.
121  if (config.stateOutput==1 && cp_min_opt==1 && myGSpaceObj->iteration > 0 &&
122  (myGSpaceObj->iteration % ndump_frq==0 || myGSpaceObj->iteration==config.maxIter || myGSpaceObj->exitFlag==1)) {
123  serial { myGSpaceObj->doOutput(); }
124  when doneOutput() {}
125  }
126 
127  if (isPsiVupdateNeeded && cp_min_opt==1 && myGSpaceObj->iteration > 1) {
128  serial { myGSpaceObj->computeNewPsiV(); }
129  when donePsiV() serial { isPsiVupdateNeeded = false; }
130  }
131  } // end if !_SDAG_DEBUG_PSI_OFF_
132 
133  //! Wait for both the energy computation, and the atoms to be moved
134  //! before going to the next iteration.
135  overlap {
136  if (!_SDAG_DEBUG_PSI_OFF_) {
137  when doneComputingEnergy(const int AtomGrpIter) {}
138  }
139  when doneMovingAtoms(const int AtomsGrpIter) {}
140  }
141 
142  //! Print out the iteration times and set isFirstStep to false.
143  serial {
144  myGSpaceObj->screenPrintWallTimes();
145  isFirstStep = false;
146  }
147  } // end while simulation is running
148 
149  serial {
150 #ifdef _CP_SUBSTEP_TIMING_
151 #if USE_HPM
152  // Print additional timing information
153  (TimeKeeperProxy.ckLocalBranch())->printHPM();
154 #endif
155 #endif
156  // Contribute to a reduction to let the instance controller know
157  // that the computation is complete.
158  CkCallback cb(CkIndex_InstanceController::cleanExit(NULL),
159  CkArrayIndex1D(thisInstance.proxyOffset),
160  instControllerProxy);
161  contribute(cb);
162  }
163  };
164  };
165 };
166 
167 
168 
169 module gParticlePlane
170 {
171  class UberCollection;
172  class PPDummyMsg;
173 
174  message NLDummyMsg;
175  message EnlCookieMsg;
176  message GSPPIFFTMsg {complex data[];};
177 
178  message NLFFTMsg {complex data[];};
179  message CompAtmForcMsg {double zmat[];};
180 
181  array [2D] CP_State_ParticlePlane
182  {
183  entry CP_State_ParticlePlane(int ,int ,int ,int ,int ,int ,int ,int ,int ,int ,int ,int ,int ,int ,int, UberCollection);
184  entry void launchComputeZs();
185  entry void computeZ(PPDummyMsg *dmsg);
186  entry void reduceZ(int size, int atmIndex, complex zmatrix[size],complex zmatrix_fx[size], complex zmatrix_fy[size],complex zmatrix_fz[size]);
187  entry void getForces(int zsize, int atmIndex, complex zmat[zsize]);
188  entry void lPrioStartNLEes(NLDummyMsg *m);
189  entry [nokeep] void setEnlCookie(EnlCookieMsg *m);
190  entry void recvFromEesRPP(GSPPIFFTMsg *m);
191  entry void registrationDone(CkReductionMsg *msg);
192  entry void printEnl(CkReductionMsg *msg);
193  };
194 
195  // This is where the real component lives when using ees for nonlocal
196  array [2D] CP_State_RealParticlePlane {
197  entry CP_State_RealParticlePlane(int , int , int ,int , int ,int ,int,int, UberCollection);
198  entry void init();
199  entry void recvFromEesGPP(NLFFTMsg *);
200  entry void recvZMatEes(CkReductionMsg *);
201  entry [nokeep] void computeAtmForcEes(CompAtmForcMsg *msg);
202 
203  entry [nokeep] void setPlaneRedCookie(EnlCookieMsg *);
204  entry [nokeep] void setEnlCookie(EnlCookieMsg *);
205  entry void registrationDone();
206  entry void printEnlR(CkReductionMsg *);
207  entry void printEnlRSimp(double ,int,int);
208  entry void recvZMatEesSimp(int size, double _zmat[size],int state,
209  int index, int iterNL_in);
210  entry [local] void FFTNLEesFwdR();
211  entry void launchFFTControl(int );
212  entry void enlSectDone(CkReductionMsg *m);
213  entry void planeRedSectDone(CkReductionMsg *m);
214  };
215 };
216 
217 
218 module gStatePlane
219 {
220  extern module pcMessages;
221  extern module instanceController;
222  extern module RDMAMessages;
223 
224  class RDMApair_GSP_PC;
225  class pcSetupMsg;
228  message RSFFTMsg { complex data[]; };
229  message GSIFFTMsg { complex data[]; };
230  message GSRedPsiMsg { complex data[]; };
231  message ProductMsg {double data[];};
232  message GStateOutMsg
233  {
234  complex data[];
235  complex vdata[];
236  int k_x[];
237  int k_y[];
238  int k_z[];
239  };
240 
241  class UberCollection;
242  include "paircalc/pcFwdDeclarations.h";
243  include "load_balance/PeList.h";
244 
245  array [2D] CP_State_RealSpacePlane {
246  entry CP_State_RealSpacePlane( int , int ,int, int, int,int, int, UberCollection);
247 
248  entry void run() {
249  while (true) {
250  for (count = 0; count < nchareG; count++) {
251  // Partially FFTd data comes from CP_State_GSpacePlane
252  when acceptFFT(RSFFTMsg *m) serial { unpackFFT(m); }
253  }
254  serial {
255  iteration++;
256  // Finish the FFT to create Psi[S,R]
257  doFFT();
258  // Reduction of Psi[S,R] to Rho[R] is invoked; Go to sleep
259  }
260 
261  for (countProduct = 0; countProduct < rhoRsubplanes; ++countProduct) {
262  // Rho chares multicast back VKS[R]
263  when acceptProduct(ProductMsg *m) serial { unpackProduct(m); }
264  }
265 
266 #ifdef RSVKS_BARRIER
267  // Performance diagnostic barrier
268  serial {
269  contribute(CkCallback(CkIndex_CP_State_RealSpacePlane::rdoneVks(NULL),
270  UrealSpacePlaneProxy[thisInstance.proxyOffset]));
271  }
272  when rdoneVks(CkReductionMsg *m) serial { delete m; }
273 #endif
274 
275  serial {
276  // Partially FFT VKS*Psi=Force
277  thisProxy[thisIndex].doVksFFT();
278  // Send the partially FFTd force to GSpacePlane
279  sendFPsiToGSP();
280  }
281  }
282  };
283 
284  entry [nokeep] void acceptFFT(RSFFTMsg *m);
285  entry [nokeep] void acceptProduct(ProductMsg *m);
286  entry [local] void doFFT();
287  entry [local] void doVksFFT();
288  entry void setNumPlanesToExpect(int num);
289  entry void printData();
290  entry [nokeep] void init(ProductMsg *m);
291 
292 #ifdef RSVKS_BARRIER
293  entry void rdoneVks(CkReductionMsg *m);
294 #endif
295  };
296 
297  array [2D] CP_State_GSpacePlane
298  {
299  entry CP_State_GSpacePlane(int sizeX, int numG, int numR, int s_grain, int timekeepf, int timekeepb, UberCollection);
300  entry void acceptPairCalcAIDs(pcSetupMsg *msg);
301  entry void initGSpace(int m, complex pts[m], int mv, complex vpts[mv], int nx,int ny,int nz,int ngridaNL,int ngridbNL,int ngridcNL, int istart_cp);
302  entry void acceptIFFT(GSIFFTMsg *msg);
303  entry void completeRDMAhandshake(RDMASetupConfirmationMsg<RDMApair_GSP_PC> *msg);
304  entry [nokeep] void acceptFileOutput(GStateOutMsg *msg);
305 
306  entry void acceptLambda(CkReductionMsg *msg);
307  entry void acceptLambda(partialResultMsg *msg);
308  entry void acceptNewPsi(CkReductionMsg *msg);
309  entry void acceptNewPsi(partialResultMsg *msg);
310  entry void acceptRedPsi(GSRedPsiMsg *msg);
311  entry void acceptNewPsiV(CkReductionMsg *msg);
312  entry void acceptNewPsiV(partialResultMsg *msg);
313  entry void acceptRedPsiV(GSRedPsiMsg *msg);
314 
315  entry void makePCproxies();
316  entry [local] void startNewIter();
317 
318  entry void computeEnergies(int p, double d);
319  entry void acceptCgOverlap(CkReductionMsg *msg);
320  entry void acceptNewTemperature(double temp);
321  entry void readFile();
322  entry [nokeep] void initBeadCookie(ICCookieMsg *msg);
323  entry [nokeep] void minimizeSync(ICCookieMsg *msg);
324  entry void setExitFlag();
325 
326  // Barriers can be turned on for performance diagnostics
327 #ifdef BARRIER_CP_GSPACE_IFFT
328  entry [nokeep] void allDoneIFFT(CkReductionMsg *msg);
329 #endif
330 #ifdef BARRIER_CP_GSPACE_PSI
331  entry [nokeep] void allDonePsi(CkReductionMsg *msg);
332 #endif
333 #ifdef BARRIER_CP_GSPACE_PSIV
334  entry [nokeep] void allDonePsiV(CkReductionMsg *msg);
335 #endif
336 
337  // SDAG ////////
338  entry void computePsiFandVKS() {
339  serial {
340  // Do the z-FFT
341  doFFT();
342  // Transpose by sending to RealSpaceStatePlane
343  sendFFTData();
344  }
345  // Wait for RealSpaceStatePlane to send back partially FFTd forces
346  while (countIFFT != gs.planeSize[1]) {
347  when acceptIFFT(GSIFFTMsg *msg) serial { unpackIFFT(msg); }
348  }
349  serial {
350  countIFFT = 0;
351  // Complete forces from VKS
352  doIFFT();
353  }
354 #ifdef BARRIER_CP_GSPACE_IFFT
355  when allDoneIFFT(CkReductionMsg* msg) {}
356 #endif
357  serial {
358  UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).donePsiFandVKS();
359  }
360  };
361 
362  entry void computeLambdaAndCg() {
363  // Lambda sending is needed for CgOverlap even if ortho is turned off
364  serial {
365  // We launch the computation of the constraint force
366  sendLambda();
367  }
368  if (!_SDAG_DEBUG_ORTHO_OFF_) {
369  while (countLambda != AllLambdaExpected) {
370  case {
371  when acceptLambda(CkReductionMsg *msg) serial { unpackLambda(msg); }
372  when acceptLambda(partialResultMsg *msg) serial { unpackLambda(msg); }
373  }
374  }
375  serial { doLambda(); }
376  }
377  serial { computeCgOverlap(); }
378  when acceptCgOverlap(CkReductionMsg *msg) serial {
379  psiCgOvlap(msg);
380  UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).doneLambdaAndCg();
381  }
382  };
383 
384  entry void computeRedPsi() {
385  serial {
386  // Update the Psis using the forces modified by lambda
387  integrateModForce();
388  // At the gamma point synchronize redundant points on Gx = 0
389  sendRedPsi();
390  }
391  while (iRecvRedPsi == 0) {
392  when acceptRedPsi(GSRedPsiMsg *msg) serial { unpackRedPsi(msg); }
393  }
394  serial {
395  doneRedPsiIntegrate();
396  UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).doneRedPsi();
397  }
398  };
399 
400  entry void computeNewPsi() {
401  serial { sendPsi(); }
402  if (!_SDAG_DEBUG_ORTHO_OFF_) {
403  while (countPsi != AllPsiExpected) {
404  case {
405  when acceptNewPsi(CkReductionMsg *msg) serial { unpackNewPsi(msg); }
406  when acceptNewPsi(partialResultMsg *msg) serial { unpackNewPsi(msg); }
407  }
408  }
409  serial { doNewPsi(); }
410 #ifdef BARRIER_CP_GSPACE_PSI
411  when allDonePsi(CkReductionMsg *msg) {}
412 #endif
413  serial { UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x, thisIndex.y).doneNewPsi(); }
414  }
415  };
416 
417  entry void computeNewPsiV() {
418  serial {
419  acceptedVPsi = false;
420  sendRedPsiV();
421  }
422  while (iRecvRedPsiV == 0) {
423  when acceptRedPsiV(GSRedPsiMsg *msg) serial { unpackRedPsiV(msg); }
424  }
425  serial {
426  doneRedPsiIntegrate();
427  sendPsiV();
428  }
429  while (countVPsi != AllPsiExpected) {
430  case {
431  when acceptNewPsiV(CkReductionMsg *msg) serial { unpackNewPsiV(msg); }
432  when acceptNewPsiV(partialResultMsg *msg) serial { unpackNewPsiV(msg); }
433  }
434  }
435  serial { doNewPsiV(); }
436 #ifdef BARRIER_CP_GSPACE_PSIV
437  when allDonePsiV(CkReductionMsg *msg) {}
438 #endif
439  serial { UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x, thisIndex.y).donePsiV(); }
440  };
441 
442  entry void doOutput() {
443  // Everyone sends their portion of the output to the reduction plane
444  serial { contributeFileOutput(); }
445 
446  // The reduction plane collects all of the output, and writes the file
447  if (thisIndex.y == redPlane) {
448  while (countFileOut < nchareG) {
449  when acceptFileOutput(GStateOutMsg* msg) serial { unpackFileOutput(msg); }
450  }
451  serial { writeOutputFile(); }
452  }
453 
454  // Everyone contributes to the reduction saying that output has completed
455  serial {
456  contribute(CkCallback(CkIndex_GSpaceDriver::doneOutput(), UgSpaceDriverProxy[thisInstance.proxyOffset]));
457  }
458  };
459  };
460 };
461 /*@}*/
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
2D chare array [nchareG][nstates] Handles flow of control within an instance, always same dimensional...
Definition: GSpaceDriver.h:34
entry void driveGSpace()
SDAG method for flow control of the Driver and its associated GSpace object.
Definition: gspace.ci:60
2D chare array [nchareG][nstates] Handles the electronic structure in Fourier space (referred to as G...
paircalc::CreationManager returns relevant chare array handles via this msg
A request from a data sender to setup an RDMA link. Initiates the sender-receiver handshake required ...
Definition: RDMAMessages.h:22
A (hopefully) tiny token that is unique to every data sender-receiver pair, and is shared by them dur...
Definition: RDMAMessages.h:94
Reply from data receiver to the data sender indicating completion of setup on the receiver side...