38 #include "CP_State_GSpacePlane.h"
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;
62 extern ComlibInstanceHandle mssInstance;
66 extern CkReduction::reducerType sumFastDoubleType;
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"
86 int realSpaceUnits,
int _ngrida,
int _ngridb,
int _ngridc,
88 : thisInstance(_instance)
97 rhoRsubplanes = config.rhoRsubplanes;
102 if(config.doublePack){
103 csize = (ngrida/2 + 1)*ngridb;
104 rsize = (ngrida + 2)*ngridb; ;
106 csize = ngrida*ngridb;
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;
115 forwardTimeKeep=_rfortime;
116 backwardTimeKeep=_rbacktime;
118 realSpaceUnits, thisIndex.x, thisIndex.y);
120 RhoReductionDest=thisInstance;
121 if(config.UberJmax>1) RhoReductionDest.idxU.y=0;
122 RhoReductionDest.setPO();
123 setMigratable(
false);
124 cookie=
new CkSectionInfo[rhoRsubplanes];
126 thisProxy[thisIndex].run();
134 void CP_State_RealSpacePlane::pup(PUP::er &p){
135 CBase_CP_State_RealSpacePlane::pup(p);
140 p|ibead_ind; p|kpoint_ind; p|itemper_ind;
150 PUParray(p,cookie,rhoRsubplanes);
161 void CP_State_RealSpacePlane::setNumPlanesToExpect(
int num){
162 rs.numPlanesToExpect = num;
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");
181 #ifdef _CP_SUBSTEP_TIMING_
183 if(forwardTimeKeep>0 && count == 0)
185 double rstart=CmiWallTimer();
186 CkCallback cb(CkIndex_TimeKeeper::collectStart(NULL),0,TimeKeeperProxy);
187 contribute(
sizeof(
double),&rstart,CkReduction::min_double, cb , forwardTimeKeep);
192 for(
int i=0;i<msg->size ;i++)
194 CkAssert(isnan(msg->data[i].re)==0);
195 CkAssert(isnan(msg->data[i].im)==0);
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;
209 int planeSize = rs.size;
234 if(config.conserveMemory && count==0){rs.allocate();}
235 complex *planeArr = rs.planeArr;
236 if(count==0){bzero(planeArr,planeSize*
sizeof(
complex));}
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],
242 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
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]);
251 planeArr[tranUnpack[Index][i]] = partiallyFFTd[i];
267 #ifdef _CP_DEBUG_STATER_VERBOSE_
268 ckout <<
"Real Space " << thisIndex.x <<
" " << thisIndex.y <<
" doing FFT" << endl;
272 #include "../class_defs/allclass_strip_cp.h"
273 double *occ = cpcoeffs_info->occ_up;
274 double *wght_kpt = cpcoeffs_info->wght_kpt;
276 double occ_now = occ[istate+1];
277 double wght_kpt_now = wght_kpt[kpoint_ind+1];
279 double wght_rho = occ_now*wght_kpt_now;
286 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
287 int nplane_x = sim->nplane_x;
288 complex *planeArr = rs.planeArr;
289 double *planeArrR = rs.planeArrR;
292 if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
294 #if CMK_TRACE_ENABLED
295 double StartTime=CmiWallTimer();
329 fftcache->getCacheMem(
"CP_State_RealSpacePlane::doFFT");
331 double *data = fftcache->tmpDataR;
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)];
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());
348 CmiNetworkProgress();
350 #if CMK_TRACE_ENABLED
351 traceUserBracketEvent(doRealFwFFT_, StartTime, CmiWallTimer());
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;
361 if(ees_nonlocal==1 && config.launchNLeesFromRho==0 && natm_nl>0){
363 int div = (config.nchareG / ngridc);
364 int rem = (config.nchareG % ngridc);
365 int ind = thisIndex.y+ngridc;
367 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
368 CkPrintf(
"NchareG too large for ngridc for launch Scheme\n");
369 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
373 if(thisIndex.y<config.nchareG){
374 UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).startNonLocalEes(iteration);
376 if((div==1) && (thisIndex.y<rem)){
377 UgSpaceDriverProxy[thisInstance.proxyOffset](thisIndex.x,ind).startNonLocalEes(iteration);
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");
395 if(config.doublePack){
396 bzero(planeArrR,(ngrida+2)*ngridb*
sizeof(
double));
398 bzero(planeArrR,(ngrida*ngridb*2)*
sizeof(
double))
400 fftcache->freeCacheMem(
"CP_State_RealSpacePlane::doFFT");
421 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
422 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
423 double *data = fftcache->tmpDataR;
425 #ifdef _CP_DEBUG_STATER_VERBOSE_
426 CkPrintf(
"In StateRSpacePlane[%d %d] doReduction %d\n", thisIndex.x, thisIndex.y,
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");
444 #if CMK_TRACE_ENABLED
445 double StartTime=CmiWallTimer();
451 int subSize = (ngridb/rhoRsubplanes);
452 int subRem = (ngridb % rhoRsubplanes);
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);
464 CkAssert(off==ngrida*ngridb);
466 CmiNetworkProgress();
468 #if CMK_TRACE_ENABLED
469 traceUserBracketEvent(DoFFTContribute_, StartTime, CmiWallTimer());
472 fftcache->freeCacheMem(
"CP_State_RealSpacePlane::doReduction");
473 #ifdef _CP_SUBSTEP_TIMING_
474 if(forwardTimeKeep>0)
476 double rend=CmiWallTimer();
477 CkCallback cb(CkIndex_TimeKeeper::collectEnd(NULL),0,TimeKeeperProxy);
478 contribute(
sizeof(
double),&rend,CkReduction::max_double, cb , forwardTimeKeep);
500 #include "../class_defs/allclass_strip_cp.h"
501 double *occ = cpcoeffs_info->occ_up;
502 double *wght_kpt = cpcoeffs_info->wght_kpt;
504 double occ_now = occ[istate+1];
505 double wght_kpt_now = wght_kpt[kpoint_ind+1];
507 double wght_rho = occ_now*wght_kpt_now;
514 #ifdef _CP_DEBUG_STATER_VERBOSE_
515 CkPrintf(
"In StateRSpacePlane[%d %d] doProd \n", thisIndex.x, thisIndex.y);
517 #ifdef _CP_SUBSTEP_TIMING_
518 if(backwardTimeKeep>0)
520 double rstart=CmiWallTimer();
521 CkCallback cb(CkIndex_TimeKeeper::collectStart(NULL),0,TimeKeeperProxy);
522 contribute(
sizeof(
double),&rstart,CkReduction::min_double, cb , backwardTimeKeep);
527 for(
int i=0;i<msg->datalen ;i++){
528 CkAssert(isnan(msg->data[i])==0);
537 double *vks_tmp = msg->data;
538 int mychare = msg->idx;
539 int mysize = msg->datalen;
540 int myindex = msg->subplane;
541 CkAssert(mychare==thisIndex.y);
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);
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;
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);
571 CmiNetworkProgress();
587 #ifdef _CP_DEBUG_STATER_VERBOSE_
588 CkPrintf(
"In RealSpacePlane[%d %d] doProduct %d\n",
589 thisIndex.x, thisIndex.y,CmiMemoryUsage());
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]);
609 #if CMK_TRACE_ENABLED
610 double StartTime=CmiWallTimer();
616 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
617 int nplane_x = sim->nplane_x;
618 complex *planeArr = rs.planeArr;
619 double *planeArrR = rs.planeArrR;
621 if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
627 #if CMK_TRACE_ENABLED
628 traceUserBracketEvent(doRealBwFFT_, StartTime, CmiWallTimer());
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;
667 if (config.useMssInsGP){mssInstance.beginIteration();}
669 if (config.useMssInsGP){ComlibBegin(gproxy,0);}
673 for (
int ic = 0; ic < nchareG; ic ++) {
675 int sendFFTDataSize = nlines_per_chareG[ic];
677 msg->size = sendFFTDataSize;
678 msg->offset = thisIndex.y;
681 if(config.prioFFTMsg){
682 CkSetQueueing(msg, CK_QUEUEING_IFIFO);
683 *(
int*)CkPriorityPtr(msg) = config.gsifftpriority+thisIndex.x*rs.ngrid_a;
686 for(
int i=0;i<sendFFTDataSize;i++){data[i] = vks_on_state[tranpack[ic][i]];}
687 gproxy(thisIndex.x, ic).acceptIFFT(msg);
688 CmiNetworkProgress();
694 if (config.useMssInsGP){mssInstance.endIteration();}
696 if (config.useMssInsGP){ComlibEnd(gproxy,0);}
705 if(config.conserveMemory){
708 #ifdef _CP_SUBSTEP_TIMING_
709 if(backwardTimeKeep>0)
711 double rend=CmiWallTimer();
712 CkCallback cb(CkIndex_TimeKeeper::collectEnd(NULL),0,TimeKeeperProxy);
713 contribute(
sizeof(
double),&rend,CkReduction::max_double, cb , backwardTimeKeep);
734 gproxy = UgSpacePlaneProxy[thisInstance.proxyOffset];
737 CkGetSectionInfo(cookie[msg->subplane], msg);
738 if(numCookies == config.rhoRsubplanes)
741 contribute(
sizeof(
int), &numCookies, CkReduction::sum_int,
742 CkCallback(CkIndex_InstanceController::doneInit(NULL),CkArrayIndex1D(thisInstance.proxyOffset),
instControllerProxy), thisInstance.proxyOffset);
746 if (config.useMssInsGP){
747 ComlibAssociateProxy(mssInstance,gproxy);
757 void CP_State_RealSpacePlane::ResumeFromSync(){
769 void CP_State_RealSpacePlane::printData() {
771 sprintf(str,
"RSP%dx%d.out", thisIndex.x, thisIndex.y);
772 FILE *outfile = fopen(str,
"w");
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");
holds the UberIndex and the offset for proxies
void doStpFFTRtoG_Rchare(complex *, double *, int, int, int, int)
////////////////////////////////////////////////////////////////////////////= ///////////////////////...
void doStpFFTGtoR_Rchare(complex *, double *, int, int, int, int)
CProxy_InstanceController instControllerProxy
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. ...
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)
void unpackProduct(ProductMsg *)
In this method, we receive vks from the density.
void unpackFFT(RSFFTMsg *)
CP_State_RealSpacePlane_SDAG_CODE CP_State_RealSpacePlane(int, int, int, int, int, int, int, UberCollection)