OpenAtom  Version1.5a
CP_State_RealSpacePlane.C
Go to the documentation of this file.
1 /// Things to do
2 /// dofft should do the fft
3 //#define RSVKS_BARRIER
4 //////////////////////////////////////////////////////////////////////////////
5 //////////////////////////////////////////////////////////////////////////////
6 //////////////////////////////////////////////////////////////////////////////
7 /** \file CP_State_RealSpacePlane.C
8  * @defgroup RealSpaceState RealSpaceState
9  *
10  * \brief Handles electronic structure in real space, creates input
11  * for \ref Density computation in CP_RhoRealSpacePlane. The points
12  * of plane-wave pseudo-potential are cut along the x-dimension for
13  * finer parallelization.
14  *
15  * Chare Array 2D chare array nplanex X nstates.
16  *
17  * This is a description of the "life" of a CP_State_RealSpacePlane object.
18  *
19  * At the start of the program, the constructor
20  * CP_State_RealSpacePlane() is called. The CP_State_GSpacePlane
21  * objects send data to CP_State_RealSpacePlane after doing FFT in the
22  * y direction. The data is sent through the doFFT() method. In this
23  * method FFTs in the z and x directions are performed. After this the
24  * squared magnitudes of the psi_r values are sent to
25  * RealSpaceDensity. The CP_State_RealSpacePlane object is idle until
26  * further messages are sent to it.
27  *
28  * The idle period of the CP_State_RealSpacePlane is ended by a
29  * message from RealSpaceDensity objects - doProduct(). In this method
30  * the Slab of data in CP_State_RealSpacePlane, psi_r, is multiplied
31  * with the data sent from RealSpaceDensity. Then, inverse ffts in z
32  * and x directions are performed. Then the slab of data is send to
33  * CP_State_GSpacePlanes so that the inverse fft in the x direction
34  * can be performed.
35  */
36 //////////////////////////////////////////////////////////////////////////////
37 
38 #include "CP_State_GSpacePlane.h"
39 #include "CP_State_Plane.h"
41 #include "main/cpaimd.h"
42 #include "utility/util.h"
43 #include "charm++.h"
44 
45 #include <iostream>
46 #include <fstream>
47 #include <cmath>
48 
49 
50 
51 //////////////////////////////////////////////////////////////////////////////
52 extern CProxy_TimeKeeper TimeKeeperProxy;
53 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
54 extern CkVec <CProxy_GSpaceDriver> UgSpaceDriverProxy;
55 extern CkVec <CProxy_CP_Rho_RealSpacePlane> UrhoRealProxy;
56 extern CkVec <CProxy_CP_State_RealSpacePlane> UrealSpacePlaneProxy;
57 extern CProxy_main mainProxy;
58 extern CkVec <CProxy_CP_State_ParticlePlane> UparticlePlaneProxy;
59 extern CkVec <CProxy_FFTcache> UfftCacheProxy;
60 extern CProxy_InstanceController instControllerProxy;
61 extern CkGroupID mCastGrpId;
62 extern ComlibInstanceHandle mssInstance;
63 
64 extern int sizeX;
65 extern Config config;
66 extern CkReduction::reducerType sumFastDoubleType;
67 
68 #define CHARM_ON
69 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cpnonlocal.h"
70 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cpintegrate.h"
71 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cprspaceion.h"
72 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cplocal.h"
73 #include "../../src_piny_physics_v1.0/include/class_defs/piny_constants.h"
74 #include "../../src_piny_physics_v1.0/include/class_defs/allclass_cp.h"
75 //////////////////////////////////////////////////////////////////////////////
76 
77 //#define _CP_DEBUG_STATER_VERBOSE_
78 /** @addtogroup RealSpaceState
79  @{
80 */
81 
82 //////////////////////////////////////////////////////////////////////////////
83 //////////////////////////////////////////////////////////////////////////////
84 //////////////////////////////////////////////////////////////////////////////
86  int realSpaceUnits, int _ngrida, int _ngridb, int _ngridc,
87  int _rfortime, int _rbacktime, UberCollection _instance)
88  : thisInstance(_instance)
89 {
90 //////////////////////////////////////////////////////////////////////////////
91 /// ckout << "State R Space Constructor : "
92 /// << thisIndex.x << " " << thisIndex.y << " " <<CkMyPe() << endl;
93 //////////////////////////////////////////////////////////////////////////////
94 
95  countProduct=0;
96  count = 0;
97  rhoRsubplanes = config.rhoRsubplanes;
98  numCookies=0;
99  ngrida = _ngrida;
100  ngridb = _ngridb;
101  ngridc = _ngridc;
102  if(config.doublePack){
103  csize = (ngrida/2 + 1)*ngridb;
104  rsize = (ngrida + 2)*ngridb; ;
105  }else{
106  csize = ngrida*ngridb;
107  rsize = 2*csize;
108  }//endif
109  iplane_ind = thisIndex.y;
110  istate = thisIndex.x;
111  ibead_ind = thisInstance.idxU.x;
112  kpoint_ind = thisInstance.idxU.y;
113  itemper_ind = thisInstance.idxU.z;
114 
115  forwardTimeKeep=_rfortime;
116  backwardTimeKeep=_rbacktime;
117  initRealStateSlab(&rs, ngrida, ngridb, ngridc, gSpaceUnits,
118  realSpaceUnits, thisIndex.x, thisIndex.y);
119 
120  RhoReductionDest=thisInstance;
121  if(config.UberJmax>1) RhoReductionDest.idxU.y=0; // not at the gamma point
122  RhoReductionDest.setPO();
123  setMigratable(false);
124  cookie= new CkSectionInfo[rhoRsubplanes];
125  iteration = 0;
126  thisProxy[thisIndex].run();
127 
128 }
129 //////////////////////////////////////////////////////////////////////////////
130 
131 //////////////////////////////////////////////////////////////////////////////
132 //////////////////////////////////////////////////////////////////////////////
133 //////////////////////////////////////////////////////////////////////////////
134 void CP_State_RealSpacePlane::pup(PUP::er &p){
135  CBase_CP_State_RealSpacePlane::pup(p);
136  __sdag_pup(p);
137 
138  p|iplane_ind;
139  p|istate;
140  p|ibead_ind; p|kpoint_ind; p|itemper_ind;
141  p|iteration;
142  p|rhoRsubplanes;
143  p|ngrida;
144  p|ngridb;
145  p|ngridc;
146  p|count;
147  p|countProduct;
148  p|csize;
149  p|rsize;
150  PUParray(p,cookie,rhoRsubplanes);
151  p|gproxy;
152  p|numCookies;
153  rs.pup(p); // pup your plane, now, honey.
154 
155 }
156 //////////////////////////////////////////////////////////////////////////////
157 
158 //////////////////////////////////////////////////////////////////////////////
159 //////////////////////////////////////////////////////////////////////////////
160 //////////////////////////////////////////////////////////////////////////////
161 void CP_State_RealSpacePlane::setNumPlanesToExpect(int num){
162  rs.numPlanesToExpect = num;
163 }
164 //////////////////////////////////////////////////////////////////////////////
165 
166 
167 //////////////////////////////////////////////////////////////////////////////
168 //////////////////////////////////////////////////////////////////////////////
169 //////////////////////////////////////////////////////////////////////////////
171 //////////////////////////////////////////////////////////////////////////////
172 
173  if(thisIndex.x >= config.nstates || thisIndex.x < 0 ||
174  thisIndex.y >= ngridc || thisIndex.y < 0){
175  CkPrintf("A message has arrived to real state state char index %d %d\n",
176  thisIndex.x,thisIndex.y);
177  CkPrintf("This chare is out of range. Boy, you sure made a big boo-boo!!\n");
178  CkExit();
179  }//endif
180 
181 #ifdef _CP_SUBSTEP_TIMING_
182  // If this is the first incoming FFT data, then start the fwd phase timing
183  if(forwardTimeKeep>0 && count == 0)
184  {
185  double rstart=CmiWallTimer();
186  CkCallback cb(CkIndex_TimeKeeper::collectStart(NULL),0,TimeKeeperProxy);
187  contribute(sizeof(double),&rstart,CkReduction::min_double, cb , forwardTimeKeep);
188  }
189 #endif
190 
191 #ifdef _NAN_CHECK_
192  for(int i=0;i<msg->size ;i++)
193  {
194  CkAssert(isnan(msg->data[i].re)==0);
195  CkAssert(isnan(msg->data[i].im)==0);
196  }
197 #endif
198 
199  CPcharmParaInfo *sim = CPcharmParaInfo::get();
200  int size = msg->size;
201  int Index = msg->senderIndex;
202  int Jndex = msg->senderJndex;
203  int Kndex = msg->senderKndex;
204  complex *partiallyFFTd = msg->data;
205  int nchareG = sim->nchareG;
206  int **tranUnpack = sim->index_tran_upack;
207  int *nline_per_chareG = sim->nlines_per_chareG;
208 
209  int planeSize = rs.size;
210 
211  /****************************************
212  char junk[1000];
213  sprintf(junk,"rstate%d.%d.out",thisIndex.x,thisIndex.y);
214  FILE *fp = fopen(junk,"a");
215  fprintf(fp,"Receiving from %d %d who is sending to %d %d : stuff %d of total %d\n",
216  Jndex,Index,Jndex,Kndex,count,nchareG);
217  fclose(fp);
218  *****************************************/
219 
220 //////////////////////////////////////////////////////////////////////////////
221 /// Unpack the message
222 /// You have received packed data (x,y) from processor sendIndex
223 /// Every real space chare receives the same x,y indicies.
224 /// For double pack, x=0,1,2,3,4 ... y= {-K ... K}
225 /// The x increase with processor number. The y are split.
226 /// The rundescriptor contains all we need to unpack the data.
227 /// For doublepack : nffty*run[i][j].x + run[i][j].y
228 /// we store this stuff in the convenient package
229 /// Pictorially a half cylinder is sent which is unpacked into
230 /// a half cube for easy FFTing. Y is the inner index.
231 
232  // non-zero elements are set. Zero elements are zeroed here
233  // planeSize also contains extra elements on the boundary for fftw
234  if(config.conserveMemory && count==0){rs.allocate();}
235  complex *planeArr = rs.planeArr;
236  if(count==0){bzero(planeArr,planeSize*sizeof(complex));}
237 
238  if(size!=nline_per_chareG[Index]){
239  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
240  CkPrintf("Dude, %d != %d for chare %d %d\n",size,nline_per_chareG[Index],
241  thisIndex.y,Index);
242  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
243  CkExit();
244  }//endif
245 
246  for(int i=0;i< size;i++){
247  if(tranUnpack[Index][i]<0 || tranUnpack[Index][i]>=planeSize){
248  CkPrintf("tranUnpack index out of range %d %d %d\n",i,Index,tranUnpack[Index][i]);
249  CkExit();
250  }//endif
251  planeArr[tranUnpack[Index][i]] = partiallyFFTd[i];
252  }//endif
253 
254 //////////////////////////////////////////////////////////////////////////////
255  }//end routine
256 //////////////////////////////////////////////////////////////////////////////
257 
258 
259 //////////////////////////////////////////////////////////////////////////////
260 /// After receiving from G-space, FFT to real space
261 //////////////////////////////////////////////////////////////////////////////
262 //////////////////////////////////////////////////////////////////////////////
263 //////////////////////////////////////////////////////////////////////////////
265 //////////////////////////////////////////////////////////////////////////////
266 
267 #ifdef _CP_DEBUG_STATER_VERBOSE_
268  ckout << "Real Space " << thisIndex.x << " " << thisIndex.y << " doing FFT" << endl;
269 #endif
270 
271  CP *cp = CP::get();
272 #include "../class_defs/allclass_strip_cp.h"
273  double *occ = cpcoeffs_info->occ_up;
274  double *wght_kpt = cpcoeffs_info->wght_kpt;
275 
276  double occ_now = occ[istate+1];
277  double wght_kpt_now = wght_kpt[kpoint_ind+1];
278 
279  double wght_rho = occ_now*wght_kpt_now;
280 
281 //////////////////////////////////////////////////////////////////////////////
282 /// Perform the FFT and get psi^2 which we can store in cache tmpData because
283 /// we will blast it right off before losing control
284 
285  CPcharmParaInfo *sim = CPcharmParaInfo::get();
286  FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
287  int nplane_x = sim->nplane_x;
288  complex *planeArr = rs.planeArr;
289  double *planeArrR = rs.planeArrR;
290 
291  // more convenient definition
292  if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
293 
294 #if CMK_TRACE_ENABLED
295  double StartTime=CmiWallTimer();
296 #endif
297 
298  char junk[1000];
299  FILE *fp;
300 
301  /************************************
302  sprintf(junk,"rstate%d.%d_beforeFFT.out",thisIndex.x,thisIndex.y);
303  fp = fopen(junk,"w");
304  if(!config.doublePack){
305  for(int i=0;i<ngridb;i++){
306  for(int j=i*ngrida,k=0;j<(i+1)*ngrida;j++,k++){
307  fprintf(fp,"%d %d %g %g\n",i,k,planeArr[(j)].re,planeArr[(j)].im);
308  }//endfor
309  }//endfor
310  }//endif
311  fclose(fp);
312  ************************************/
313 
314  fftcache->doStpFFTGtoR_Rchare(planeArr,planeArrR,nplane_x,ngrida,ngridb,iplane_ind);
315 
316  /****************************************
317  sprintf(junk,"rstate%d.%d_afterFFT.out",thisIndex.x,thisIndex.y);
318  fp = fopen(junk,"w");
319  if(!config.doublePack){
320  for(int i=0;i<ngridb;i++){
321  for(int j=i*ngrida,k=0;j<(i+1)*ngrida;j++,k++){
322  fprintf(fp,"%d %d %g %g\n",i,k,planeArr[(j)].re,planeArr[(j)].im);
323  }//endfor
324  }//endfor
325  }//endif
326  fclose(fp);
327  ************************************/
328 
329  fftcache->getCacheMem("CP_State_RealSpacePlane::doFFT");
330 
331  double *data = fftcache->tmpDataR;
332 
333  if(config.doublePack){
334  for(int i=0,i2=0;i<ngridb;i++,i2+=2){
335  for(int j=i*ngrida;j<(i+1)*ngrida;j++){
336  data[j] = planeArrR[(j+i2)]*planeArrR[(j+i2)];
337  data[j] *= wght_rho;
338  }//endfor
339  }//endfor
340  }else{
341  for(int i=0;i<ngridb;i++){
342  for(int j=i*ngrida;j<(i+1)*ngrida;j++){
343  data[j] = (planeArr[j].getMagSqr());
344  data[j] *= wght_rho;
345  }//endfor
346  }//endfor
347  }//endif
348  CmiNetworkProgress();
349 
350 #if CMK_TRACE_ENABLED
351  traceUserBracketEvent(doRealFwFFT_, StartTime, CmiWallTimer());
352 #endif
353 
354 //////////////////////////////////////////////////////////////////////////////
355 /// If non-local itself is on and the ees method is to be used, launch
356 
357 #ifndef _CP_DEBUG_SFNL_OFF_ // non-local is allowed
358  int ees_nonlocal = sim->ees_nloc_on;
359  int natm_nl = sim->natm_nl;
360 
361  if(ees_nonlocal==1 && config.launchNLeesFromRho==0 && natm_nl>0){
362  // CkAssert(config.nchareG<=ngridc);
363  int div = (config.nchareG / ngridc);
364  int rem = (config.nchareG % ngridc);
365  int ind = thisIndex.y+ngridc;
366  if(div>1){
367  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
368  CkPrintf("NchareG too large for ngridc for launch Scheme\n");
369  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
370  CkExit();
371  }//endif
372 
373  if(thisIndex.y<config.nchareG){
374  UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).startNonLocalEes(iteration);
375  }//endif
376  if((div==1) && (thisIndex.y<rem)){
377  UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,ind).startNonLocalEes(iteration);
378  }//endif
379 
380  }//endif : eesnonlocal is on
381 #endif
382 
383 //////////////////////////////////////////////////////////////////////////////
384 /// Send off the reduction unless you are skipping rho, whence you call doproduct
385 
386 #ifdef _CP_DEBUG_RHO_OFF_
387  if(thisIndex.x==0 && thisIndex.y==0){
388  CkPrintf("EHART = OFF FOR DEBUGGING\n");
389  CkPrintf("EExt = OFF FOR DEBUGGING\n");
390  CkPrintf("EWALD_recip = OFF FOR DEBUGGING\n");
391  CkPrintf("EEXC = OFF FOR DEBUGGING\n");
392  CkPrintf("EGGA = OFF FOR DEBUGGING\n");
393  CkPrintf("EEXC+EGGA = OFF FOR DEBUGGING\n");
394  }//endif
395  if(config.doublePack){
396  bzero(planeArrR,(ngrida+2)*ngridb*sizeof(double));
397  }else{
398  bzero(planeArrR,(ngrida*ngridb*2)*sizeof(double))
399  }//endif
400  fftcache->freeCacheMem("CP_State_RealSpacePlane::doFFT");
401 #else
402  doReduction();
403 #endif
404 
405 //---------------------------------------------------------------------------
406  }//end routine
407 //////////////////////////////////////////////////////////////////////////////
408 
409 
410 
411 //////////////////////////////////////////////////////////////////////////////
412 /// No one else can use tmpdataR until I perform doReduction because
413 /// I will not be rolled out until I finish my scalar work.
414 //////////////////////////////////////////////////////////////////////////////
415 //////////////////////////////////////////////////////////////////////////////
416 //////////////////////////////////////////////////////////////////////////////
418 //////////////////////////////////////////////////////////////////////////////
419 /// Grab some local pointer and do some checking.
420 
421  CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(mCastGrpId).ckLocalBranch();
422  FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
423  double *data = fftcache->tmpDataR;
424 
425 #ifdef _CP_DEBUG_STATER_VERBOSE_
426  CkPrintf("In StateRSpacePlane[%d %d] doReduction %d\n", thisIndex.x, thisIndex.y,
427  CmiMemoryUsage());
428 #endif
429 
430 #ifdef _NAN_CHECK_
431  for(int i=0;i<ngrida*ngridb ;i++){
432  if(isnan(data[i])!=0){
433  CkPrintf("RS [%d %d] issuing nan at %d out of %d\n",
434  thisIndex.x, thisIndex.y, i, ngridb*ngrida);
435  CkAbort("RS nan in the fftcache");
436  }
437  }//endif
438 #endif
439 
440 //////////////////////////////////////////////////////////////////////////////
441 /// Perform the Reduction to get the density : vks holds psi^2 for us
442 /// Return values for vks cannot hit this chare until the reduciton is complete.
443 
444 #if CMK_TRACE_ENABLED
445  double StartTime=CmiWallTimer();
446 #endif
447 
448  // Need loop of contribute calls, one for each nchareRhoSplit offset
449  // into data. Need a vector of cookies and callback functions
450 
451  int subSize = (ngridb/rhoRsubplanes);
452  int subRem = (ngridb % rhoRsubplanes);
453 
454  int off = 0;
455  for(int subplane=0; subplane<rhoRsubplanes; subplane++){
456  int dataSize = subSize*ngrida;
457  if(subplane < subRem){dataSize += ngrida;}
458  CkCallback cb(CkIndex_CP_Rho_RealSpacePlane::acceptDensity(0),
459  CkArrayIndex2D(thisIndex.y,subplane),UrhoRealProxy[RhoReductionDest.proxyOffset].ckGetArrayID());
460  mcastGrp->contribute(dataSize*sizeof(double),&(data[off]),
461  sumFastDoubleType,cookie[subplane],cb);
462  off += dataSize;
463  }//endfor : subplanes
464  CkAssert(off==ngrida*ngridb);
465 
466  CmiNetworkProgress(); // yuck!
467 
468 #if CMK_TRACE_ENABLED
469  traceUserBracketEvent(DoFFTContribute_, StartTime, CmiWallTimer());
470 #endif
471 
472  fftcache->freeCacheMem("CP_State_RealSpacePlane::doReduction");
473 #ifdef _CP_SUBSTEP_TIMING_
474  if(forwardTimeKeep>0)
475  {
476  double rend=CmiWallTimer();
477  CkCallback cb(CkIndex_TimeKeeper::collectEnd(NULL),0,TimeKeeperProxy);
478  contribute(sizeof(double),&rend,CkReduction::max_double, cb , forwardTimeKeep);
479  }
480 #endif
481 
482 //////////////////////////////////////////////////////////////////////////////
483  }//end routine
484 //////////////////////////////////////////////////////////////////////////////
485 
486 
487 //////////////////////////////////////////////////////////////////////////////
488 //////////////////////////////////////////////////////////////////////////////
489 //////////////////////////////////////////////////////////////////////////////
490 /**
491  * In this method, we receive vks from the density. We apply this to psi to
492  * create psiVks, when all are here we call the working doProduct for
493  * FFTing. This is a stream processing scheme.
494  */
495 //////////////////////////////////////////////////////////////////////////////
497 //////////////////////////////////////////////////////////////////////////////
498 
499  CP *cp = CP::get();
500 #include "../class_defs/allclass_strip_cp.h"
501  double *occ = cpcoeffs_info->occ_up;
502  double *wght_kpt = cpcoeffs_info->wght_kpt;
503 
504  double occ_now = occ[istate+1];
505  double wght_kpt_now = wght_kpt[kpoint_ind+1];
506 
507  double wght_rho = occ_now*wght_kpt_now;
508 
509 
510 //////////////////////////////////////////////////////////////////////////////
511 /// Do not delete msg. Its a nokeep.
512 //////////////////////////////////////////////////////////////////////////////
513 
514 #ifdef _CP_DEBUG_STATER_VERBOSE_
515  CkPrintf("In StateRSpacePlane[%d %d] doProd \n", thisIndex.x, thisIndex.y);
516 #endif
517 #ifdef _CP_SUBSTEP_TIMING_
518  if(backwardTimeKeep>0)
519  {
520  double rstart=CmiWallTimer();
521  CkCallback cb(CkIndex_TimeKeeper::collectStart(NULL),0,TimeKeeperProxy);
522  contribute(sizeof(double),&rstart,CkReduction::min_double, cb , backwardTimeKeep);
523  }
524 #endif
525 
526 #ifdef _NAN_CHECK_
527  for(int i=0;i<msg->datalen ;i++){
528  CkAssert(isnan(msg->data[i])==0);
529  }
530 #endif
531 
532 //////////////////////////////////////////////////////////////////////////////
533 ///Unpack and check size, use message data for multiply, then resume
534 ///which calls doProduct
535 
536 
537  double *vks_tmp = msg->data;
538  int mychare = msg->idx;
539  int mysize = msg->datalen;
540  int myindex = msg->subplane; // subplaneindex of rhor
541  CkAssert(mychare==thisIndex.y);
542 
543  int subSize = (ngridb/rhoRsubplanes);
544  int subRem = (ngridb % rhoRsubplanes);
545  int subAdd = (myindex < subRem ? 1 : 0);
546  int subMax = (myindex < subRem ? myindex : subRem);
547  int myNgridb = subSize+subAdd;
548  int size = ngrida*myNgridb;
549  CkAssert(mysize == size);
550 
551 //////////////////////////////////////////////////////////////////////////////
552 
553  // multiply psi by vks to form psiVks
554  if(config.doublePack){
555  double *psiVks = rs.planeArrR;
556  int off = (subSize*myindex + subMax)*(ngrida+2);
557  for(int i=0,i2=off;i<myNgridb;i++,i2+=2){
558  for(int j=i*ngrida;j<(i+1)*ngrida;j++){
559  psiVks[(j+i2)] *= vks_tmp[j]*wght_rho;
560  }//endfor
561  }//endfor
562  }else{
563  complex *psiVks = rs.planeArr;
564  int off = (subSize*myindex + subMax)*(ngrida);
565  for(int i=0;i<myNgridb;i++){
566  for(int j=i*ngrida;j<(i+1)*ngrida;j++){
567  psiVks[(j+off)] = psiVks[(j+off)]*(vks_tmp[j]*wght_rho);
568  }//endfor
569  }//endfor
570  }//endif
571  CmiNetworkProgress();
572  }//endroutine
573 //////////////////////////////////////////////////////////////////////////////
574 
575 
576 //////////////////////////////////////////////////////////////////////////////
577 //////////////////////////////////////////////////////////////////////////////
578 //////////////////////////////////////////////////////////////////////////////
579 /*
580  * Do the fft of psi*vks stored in rho_rs.planeArrayR
581  */
582 //////////////////////////////////////////////////////////////////////////////
584 //////////////////////////////////////////////////////////////////////////////
585 /// A little output under some circumstances
586 
587 #ifdef _CP_DEBUG_STATER_VERBOSE_
588  CkPrintf("In RealSpacePlane[%d %d] doProduct %d\n",
589  thisIndex.x, thisIndex.y,CmiMemoryUsage());
590 #endif
591 
592 #ifndef _CP_DEBUG_RHO_OFF_
593 #ifdef _CP_DEBUG_VKS_RSPACE_
594  if(thisIndex.x==0 && thisIndex.y == 0){
595  FILE *fp = fopen("psivks_real_y0_state0.out","w");
596  for(int i=0;i<(ngrida+2)*ngridb;i++){
597  fprintf(fp,"%g\n",rho_rs.planeArrayR[i]);
598  }//endfor
599  fclose(fp);
600  }//endif
601 #endif
602 #endif
603 
604 ///////////////////////////////////////////////////////////////////==
605 /// Do the FFT of psi*vks
606 
607  //------------------------------------------------------------------
608  // Start the timer
609 #if CMK_TRACE_ENABLED
610  double StartTime=CmiWallTimer();
611 #endif
612 
613  //------------------------------------------------------------------
614  // The FFT
615  CPcharmParaInfo *sim = CPcharmParaInfo::get();
616  FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
617  int nplane_x = sim->nplane_x;
618  complex *planeArr = rs.planeArr;
619  double *planeArrR = rs.planeArrR;
620  // more convenient definition
621  if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
622 
623  fftcache->doStpFFTRtoG_Rchare(planeArr,planeArrR,nplane_x,ngrida,ngridb,iplane_ind);
624 
625  //------------------------------------------------------------------
626  // End timer
627 #if CMK_TRACE_ENABLED
628  traceUserBracketEvent(doRealBwFFT_, StartTime, CmiWallTimer());
629 #endif
630 
631 //---------------------------------------------------------------------------
632  }//end routine
633 //////////////////////////////////////////////////////////////////////////////
634 
635 
636 //////////////////////////////////////////////////////////////////////////////
637 //////////////////////////////////////////////////////////////////////////////
638 //////////////////////////////////////////////////////////////////////////////
640 ///////////////////////////////////////////////////////////////////==
641 /// Perform the transpose and then the blast off the final 1D-FFT
642 
643  CPcharmParaInfo *sim = CPcharmParaInfo::get();
644  int nchareG = sim->nchareG;
645  int **tranpack = sim->index_tran_upack;
646  int *nlines_per_chareG = sim->nlines_per_chareG;
647  complex *vks_on_state = rs.planeArr;
648 
649  /****************************************
650  char junk[1000];
651  sprintf(junk,"vks_on_state%d.%d_afterFFT.out",thisIndex.x,thisIndex.y);
652  FILE *fp = fopen(junk,"w");
653  if(!config.doublePack){
654  for(int i=0;i<ngridb;i++){
655  for(int j=i*ngrida,k=0;j<(i+1)*ngrida;j++,k++){
656  fprintf(fp,"%d %d %g %g\n",i,k,vks_on_state[(j)].re,vks_on_state[(j)].im);
657  }//endfor
658  }//endfor
659  }//endif
660  fclose(fp);
661  **********************************************/
662 
663  //------------------------------------------------------------------
664 
665 #ifdef USE_COMLIB
666 #ifdef OLD_COMMLIB
667  if (config.useMssInsGP){mssInstance.beginIteration();}
668 #else
669  if (config.useMssInsGP){ComlibBegin(gproxy,0);}
670 #endif
671 #endif
672 
673  for (int ic = 0; ic < nchareG; ic ++) { // chare arrays to which we will send
674 
675  int sendFFTDataSize = nlines_per_chareG[ic];
676  GSIFFTMsg *msg = new (sendFFTDataSize, 8 * sizeof(int)) GSIFFTMsg;
677  msg->size = sendFFTDataSize;
678  msg->offset = thisIndex.y; // z-index
679  complex *data = msg->data;
680 
681  if(config.prioFFTMsg){
682  CkSetQueueing(msg, CK_QUEUEING_IFIFO);
683  *(int*)CkPriorityPtr(msg) = config.gsifftpriority+thisIndex.x*rs.ngrid_a;
684  }//endif
685 
686  for(int i=0;i<sendFFTDataSize;i++){data[i] = vks_on_state[tranpack[ic][i]];}
687  gproxy(thisIndex.x, ic).acceptIFFT(msg); // send the message
688  CmiNetworkProgress();
689 
690  }//end for : chare sending
691 
692 #ifdef USE_COMLIB
693 #ifdef OLD_COMMLIB
694  if (config.useMssInsGP){mssInstance.endIteration();}
695 #else
696  if (config.useMssInsGP){ComlibEnd(gproxy,0);}
697 #endif
698 #endif
699 
700  //------------------------------------------------------------------
701 
702 ///////////////////////////////////////////////////////////////////==
703 /// clean up the states
704 
705  if(config.conserveMemory){
706  rs.destroy();
707  }//endif
708 #ifdef _CP_SUBSTEP_TIMING_
709  if(backwardTimeKeep>0)
710  {
711  double rend=CmiWallTimer();
712  CkCallback cb(CkIndex_TimeKeeper::collectEnd(NULL),0,TimeKeeperProxy);
713  contribute(sizeof(double),&rend,CkReduction::max_double, cb , backwardTimeKeep);
714  }
715 #endif
716 
717 //////////////////////////////////////////////////////////////////////////////
718  }//end routine : CP_State_RealSpacePlane::sendFPsiToGSP
719 //////////////////////////////////////////////////////////////////////////////
720 
721 
722 //////////////////////////////////////////////////////////////////////////////
723 //////////////////////////////////////////////////////////////////////////////
724 //////////////////////////////////////////////////////////////////////////////
725 /**
726 * Setting up the multicast trees for Gengbin's library
727 */
728 //////////////////////////////////////////////////////////////////////////////
730 //////////////////////////////////////////////////////////////////////////////
731 /// Do not delete msg. Its a nokeep.
732 //////////////////////////////////////////////////////////////////////////////
733 
734  gproxy = UgSpacePlaneProxy[thisInstance.proxyOffset];
735  numCookies++;
736  // based on where this came from, put it in the cookie vector
737  CkGetSectionInfo(cookie[msg->subplane], msg);
738  if(numCookies == config.rhoRsubplanes)
739  {
740  // CkPrintf("{%d} RSP [%d,%d] contributing numCookies %d = config.rhoRsubplanes %d\n",thisInstance.proxyOffset, thisIndex.x,thisIndex.y,numCookies, config.rhoRsubplanes);
741  contribute(sizeof(int), &numCookies, CkReduction::sum_int,
742  CkCallback(CkIndex_InstanceController::doneInit(NULL),CkArrayIndex1D(thisInstance.proxyOffset),instControllerProxy), thisInstance.proxyOffset);
743  }
744  // do not delete nokeep message
745 #ifdef USE_COMLIB
746  if (config.useMssInsGP){
747  ComlibAssociateProxy(mssInstance,gproxy);
748  }//endif
749 #endif
750 
751 }
752 //////////////////////////////////////////////////////////////////////////////
753 
754 //////////////////////////////////////////////////////////////////////////////
755 //////////////////////////////////////////////////////////////////////////////
756 //////////////////////////////////////////////////////////////////////////////
757 void CP_State_RealSpacePlane::ResumeFromSync(){
758 #ifdef USE_COMLIB
759 /// if(config.useMssInsGP)
760 /// ComlibResetProxy(gproxy);
761 #endif
762 }
763 //////////////////////////////////////////////////////////////////////////////
764 
765 
766 //////////////////////////////////////////////////////////////////////////////
767 //////////////////////////////////////////////////////////////////////////////
768 //////////////////////////////////////////////////////////////////////////////
769 void CP_State_RealSpacePlane::printData() {
770  char str[20];
771  sprintf(str, "RSP%dx%d.out", thisIndex.x, thisIndex.y);
772  FILE *outfile = fopen(str, "w");
773  int ioff = 0;
774  for (int i = 0; i < rs.ngrid_b; i++) {
775  for (int j = 0; j < rs.ngrid_a; j++){
776  fprintf(outfile, "%10.5lf", rs.planeArr[(j+ioff)].getMagSqr());
777  fprintf(outfile, "\n");
778  }
779  ioff += rs.ngrid_a;
780  }
781  fclose(outfile);
782 }
783 //////////////////////////////////////////////////////////////////////////////
784 
785 /*@}*/
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
void doStpFFTRtoG_Rchare(complex *, double *, int, int, int, int)
////////////////////////////////////////////////////////////////////////////= ///////////////////////...
Definition: fftCache.C:1288
void doStpFFTGtoR_Rchare(complex *, double *, int, int, int, int)
Definition: fftCache.C:1203
CProxy_InstanceController instControllerProxy
Definition: cpaimd.ci:236
void init(ProductMsg *)
Setting up the multicast trees for Gengbin's library.
CkGroupID mCastGrpId
Multicast manager group that handles many mcast/redns in the code. Grep for info. ...
Definition: cpaimd.C:216
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...
void doReduction()
No one else can use tmpdataR until I perform doReduction because I will not be rolled out until I fin...
Some basic data structures and the array map classes are defined here.
void doFFT()
After receiving from G-space, FFT to real space /////////////////////////////////////////////////////...
void initRealStateSlab(RealStateSlab *rs, int ngrid_a, int ngrid_b, int ngrid_c, int gSpaceUnits, int realSpaceUnits, int stateIndex, int thisPlane)
Definition: stateSlab.C:392
void unpackProduct(ProductMsg *)
In this method, we receive vks from the density.
CP_State_RealSpacePlane_SDAG_CODE CP_State_RealSpacePlane(int, int, int, int, int, int, int, UberCollection)