15 #include "CP_State_ParticlePlane.h"
17 #include "structure_factor/StructFactorCache.h"
22 #include "utility/matrix2file.h"
24 #include "ckmulticast.h"
26 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cpnonlocal.h"
27 #include "../../src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cplocal.h"
31 extern CProxy_main mainProxy;
32 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
33 extern CkVec <CProxy_AtomsCache> UatomsCacheProxy;
34 extern CkVec <CProxy_CP_State_ParticlePlane> UparticlePlaneProxy;
35 extern CkVec <CProxy_StructFactCache> UsfCacheProxy;
36 extern CkVec <CProxy_eesCache> UeesCacheProxy;
37 extern CkVec <CProxy_FFTcache> UfftCacheProxy;
38 extern CkVec <CProxy_CP_State_RealParticlePlane> UrealParticlePlaneProxy;
39 extern CkVec <MapType2> RPPImaptable;
41 extern ComlibInstanceHandle mssPInstance;
42 extern CkReduction::reducerType sumFastDoubleType;
63 double d = ((
double *)m->getData())[0];
64 itimeRed = m->getUserFlag();
67 FILE *temperScreenFile = UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch()->temperScreenFile;
68 int iteration= UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch()->iteration;
69 fprintf(temperScreenFile,
"Iter [%d] ENL(EES) = %5.8lf\n", iteration,d);
70 UgSpacePlaneProxy[thisInstance.proxyOffset](0,0).computeEnergies(ENERGY_ENL, d);
84 if(countEnl==1){itimeRed=itime_in;}
85 cp_enlTot += cp_enl_loc;
87 if(itimeRed!=itime_in){
88 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
89 CkPrintf(
"Yo dawg, ees nonlocal is racin' into the enl reduction\n");
90 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
94 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
95 CkPrintf(
"Enl contrib arrived from %d : %g %d %d %d\n",index,cp_enl_loc,countEnl,
100 if(countEnl==nstates){
101 CkPrintf(
"{%d} ENL(EES) = %5.8lf\n", thisInstance.proxyOffset, cp_enlTot);
102 UgSpacePlaneProxy[thisInstance.proxyOffset](0,0).computeEnergies(ENERGY_ENL,cp_enlTot);
117 CP_State_RealParticlePlane::CP_State_RealParticlePlane(
118 int ngridA_in,
int ngridB_in,
int ngridC_in,
119 int numIterNL_in,
int zmatSizeMax_in,
120 int Rstates_per_pe_in,
int nChareG_in,
122 thisInstance(_instance)
133 nChareG = nChareG_in;
134 Rstates_per_pe = Rstates_per_pe_in;
135 myPlane = thisIndex.y;
136 ibead_ind = thisInstance.idxU.x;
137 kpoint_ind = thisInstance.idxU.y;
138 itemper_ind = thisInstance.idxU.z;
140 if(config.doublePack){
141 planeSize = (ngridA+2)*ngridB;
142 planeSizeT = ngridA*ngridB;
143 csize = (ngridA+2)*ngridB/2;
145 planeSize = 2*ngridA*ngridB;
146 planeSizeT = 2*ngridA*ngridB;
147 csize = ngridA*ngridB;
149 CkAssert(csize*2==planeSize);
150 numIterNl = numIterNL_in;
151 zmatSizeMax = zmatSizeMax_in;
152 ees_nonlocal = ees_nonlocal_in;
162 registrationFlag = 0;
171 setMigratable(
false);
173 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
175 savedProjpsiCScr=NULL;
176 savedProjpsiRScr=NULL;
203 projPsiR =
reinterpret_cast<double*
> (projPsiC);
204 if(config.doublePack){
205 zmat = (
double*) fftw_malloc(zmatSizeMax*
sizeof(
double));
206 zmatScr = (
double*) fftw_malloc(zmatSizeMax*
sizeof(
double));
210 zmat =
reinterpret_cast<double*
> (zmatC);
211 zmatScr =
reinterpret_cast<double*
> (zmatScrC);
215 eesCache *eesData = UeesCacheProxy[thisInstance.proxyOffset].ckLocalBranch ();
223 int *red_pl =
new int[nstates];
225 int *usedProc=
new int[CkNumPes()];
226 memset(usedProc,0,
sizeof(
int)*CkNumPes());
227 int charperpe=nstates/CkNumPes();
228 if(nstates%CkNumPes()!=0) charperpe++;
229 if(charperpe<1) charperpe=1;
230 for(
int state=0; state<nstates;state++){
232 while(plane<nChareR){
234 int thisstateplaneproc=RPPImaptable[thisInstance.proxyOffset].get(state,plane)%CkNumPes();
235 if(usedProc[thisstateplaneproc]>=charperpe);
239 if(!used || (plane+1==nChareR)){
240 usedProc[thisstateplaneproc]++;
247 reductionPlaneNum = red_pl[thisIndex.x];
259 enlSectionComplete=
false;
260 planeRedSectionComplete=
false;
261 if(thisIndex.y==reductionPlaneNum){
263 CProxySection_CP_State_RealParticlePlane::ckNew(thisProxy.ckGetArrayID(),
264 thisIndex.x,thisIndex.x,1,
266 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
267 rPlaneSectProxy.ckDelegate(mcastGrp);
268 mcastGrp->setSection(rPlaneSectProxy);
270 rPlaneSectProxy.setPlaneRedCookie(emsg);
274 planeRedSectionComplete=
true;
282 if(thisIndex.y==reductionPlaneNum && thisIndex.x==0){
283 CkArrayIndexMax *elems =
new CkArrayIndexMax[nstates];
284 CkArrayIndex2D idx(0, reductionPlaneNum);
285 for (
int j = 0; j < nstates; j++) {
286 idx.index[0] = j; idx.index[1] = red_pl[j];
290 CProxySection_CP_State_RealParticlePlane::ckNew(thisProxy.ckGetArrayID(),
292 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
293 rPlaneENLProxy.ckDelegate(mcastGrp);
294 mcastGrp->setSection(rPlaneENLProxy);
296 rPlaneENLProxy.setEnlCookie(emsg);
302 for (
int j = 0; j < nstates; j++) {
303 if(thisIndex.x ==j && thisIndex.y== red_pl[j])
307 enlSectionComplete=
true;
315 gPP_proxy = UparticlePlaneProxy[thisInstance.proxyOffset];
317 if (config.useMssInsGPP){
318 ComlibAssociateProxy(mssPInstance,gPP_proxy);
333 enlSectionComplete=
true;
346 planeRedSectionComplete=
true;
360 if( enlSectionComplete && planeRedSectionComplete)
364 contribute(
sizeof(
int), &constructed, CkReduction::sum_int,
365 CkCallback(CkIndex_InstanceController::doneInit(NULL),
366 CkArrayIndex1D(thisInstance.proxyOffset),
380 if(config.doublePack){
411 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
412 CkPrintf(
"Yo dawg, ees nonlocal is off. RPP can't recvFromEesGPP\n");
413 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
419 for(
int i=0;i<msg->size ;i++)
421 CkAssert(finite(msg->data[i].re));
422 CkAssert(finite(msg->data[i].im));
428 int size = msg->size;
429 int iterNLNow = msg->step;
430 int Index = msg->senderIndex;
431 complex *partiallyFFTd = msg->data;
434 int nchareG = sim->nchareG;
435 int **tranUnpack = sim->index_tran_upackNL;
436 int *nline_per_chareG = sim->nlines_per_chareG;
440 if(iterNL==0 && count==1){itime++; cp_enl=0.0;}
447 bzero(projPsiR,planeSize*
sizeof(
double));
453 if (count > nchareG) {
454 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
456 "Mismatch in allowed # of NL-gspace chare arrays sending to NLR-chare: %d %d %d %d\n",
457 count,nchareG,thisIndex.x,thisIndex.y);
458 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
462 if(size!=nline_per_chareG[Index]){
463 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
464 CkPrintf(
"Dude, size %d != %d for NL-Rchare %d %d from G-chare %d\n",
465 size,nline_per_chareG[Index],thisIndex.y,Index,Index);
466 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
470 if(iterNLNow!=iterNL || recvBlock==1){
471 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
472 CkPrintf(
"Dude, iter count %d != %d for NL-Rchare %d %d %d\n",iterNLNow,iterNL,
473 thisIndex.y,Index,recvBlock);
474 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
491 for(
int i=0;i< size;i++){projPsiC[tranUnpack[Index][i]] = partiallyFFTd[i];}
497 if(count == nchareG) {
500 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
502 CkPrintf(
"HI, I am rPP %d %d in recvfromGpp : %d\n",thisIndex.x,thisIndex.y,iterNL);
506 thisProxy(thisIndex.x,thisIndex.y).FFTNLEesFwdR();
507 if(rhoRTime!=itime){CkPrintf(
"Badddd launchFFT.1\n");CkExit();}
509 if(iterNL!=1){CkPrintf(
"Badddd launchFFT.2\n");CkExit();}
528 int nplane_x = sim->nplane_x;
529 if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
533 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
535 CkPrintf(
"HI, I am rPP %d %d in FFTNL : %d %d %d %d\n",
536 thisIndex.x,thisIndex.y,iterNL,ngridA,ngridB,nplane_x);
539 #if CMK_TRACE_ENABLED
540 double StartTime=CmiWallTimer();
543 #ifdef _Glenn_DBG_KPT_
546 if(thisIndex.x==0 && thisIndex.y==0){
547 sprintf(junk,
"rpp%d.%d_beforeFFT.out",thisIndex.x,thisIndex.y);
548 fp = fopen(junk,
"w");
549 for(
int i=0;i<ngridB;i++){
550 for(
int j=i*ngridA,k=0;j<(i+1)*ngridA;j++,k++){
551 fprintf(fp,
"%d %d %.10g %.10g\n",i,k,projPsiC[j].re,projPsiC[j].im);
558 UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch()->doNlFFTGtoR_Rchare(projPsiC,projPsiR,
559 nplane_x,ngridA,ngridB,myPlane);
560 #ifdef _Glenn_DBG_KPT_
561 if(thisIndex.x==0 && thisIndex.y==0){
562 sprintf(junk,
"rpp%d.%d_afterFFT.out",thisIndex.x,thisIndex.y);
563 fp = fopen(junk,
"w");
564 for(
int i=0;i<ngridB;i++){
565 for(
int j=i*ngridA,k=0;j<(i+1)*ngridA;j++,k++){
566 fprintf(fp,
"%d %d %.10g %.10g\n",i,k,projPsiC[j].re,projPsiC[j].im);
573 #if CMK_TRACE_ENABLED
574 traceUserBracketEvent(doNlFFTGtoR_, StartTime, CmiWallTimer());
580 #ifdef _CP_GS_DUMP_VKS_
581 dumpMatrix(
"projPsiC",(
double *)projPsiC, 1, csize*2,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
584 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
588 if(savedprojpsiC==NULL){
589 savedprojpsiC=
new complex[csize];
590 loadMatrix(
"projPsiC",(
double *)savedprojpsiC, 1, csize*2,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
592 for(
int i=0;i<csize;i++){
593 if(fabs(projPsiC[i].re-savedprojpsiC[i].re)>0.0001){
594 fprintf(stderr,
"RPP [%d,%d] %d element projpsi %.10g not %.10g\n",thisIndex.x, thisIndex.y,i,
595 projPsiC[i].re, savedprojpsiC[i].re);
597 CkAssert(fabs(projPsiC[i].re-savedprojpsiC[i].re)<0.0001);
598 CkAssert(fabs(projPsiC[i].im-savedprojpsiC[i].im)<0.0001);
602 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
604 CkPrintf(
"HI, I am rPP %d %d in FFTNL.2 : %d %d %d %d\n",
605 thisIndex.x,thisIndex.y,iterNL,ngridA,ngridB,nplane_x);
613 if(registrationFlag==0 && iterNL!=1 || iterNL==0){
614 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
615 CkPrintf(
"Dude, iter count %d > 1 for NL-Rchare %d %d and no reg?\n",iterNL,
616 thisIndex.x,thisIndex.y);
617 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
634 int iterNL1 = iterNL-1;
635 int *nmem_zmat = sim->nmem_zmat;
636 int nZmat = nmem_zmat[iterNL1];
637 if(!config.doublePack){nZmat *=2;}
642 eesCache *eesData = UeesCacheProxy[thisInstance.proxyOffset].ckLocalBranch ();
643 int *allowedRppChares = eesData->allowedRppChares;
644 CkAssert(allowedRppChares[myPlane]==1);
648 int *plane_index = eesData->RppData[myPlane]->plane_index;
649 int **igrid = eesData->RppData[myPlane]->igrid;
650 double **mn = eesData->RppData[myPlane]->mn;
652 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
654 CkPrintf(
"HI, I am rPP %d %d in computeZmat : %d\n",thisIndex.x,thisIndex.y,iterNL);
660 #if CMK_TRACE_ENABLED
661 double StartTime=CmiWallTimer();
664 if(config.doublePack){
665 CPNONLOCAL::eesZmatRchare(projPsiR,iterNL,zmat,igrid,mn,
666 plane_index,thisIndex.x,myPlane);
668 CPNONLOCAL::eesZmatRchareC(projPsiC,iterNL,zmatC,igrid,mn,
669 plane_index,thisIndex.x,myPlane);
672 #if CMK_TRACE_ENABLED
673 traceUserBracketEvent(eesZmatR_, StartTime, CmiWallTimer());
679 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
681 CkPrintf(
"HI, I am rPP %d %d in send to zmat-red : %d %d %d d\n",
682 thisIndex.x,thisIndex.y,iterNL,reductionPlaneNum,nZmat,zmatSizeMax);
685 #define _FANCY_RED_METHOD_
686 #ifdef _FANCY_RED_METHOD_
687 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
688 CkCallback cb(CkIndex_CP_State_RealParticlePlane::recvZMatEes(NULL),
689 CkArrayIndex2D(thisIndex.x,reductionPlaneNum),
690 UrealParticlePlaneProxy[thisInstance.proxyOffset].ckGetArrayID());
691 mcastGrp->contribute((nZmat*
sizeof(
double)),zmat,sumFastDoubleType,
692 rPlaneRedCookie,cb, iterNL);
694 thisProxy(thisIndex.x,reductionPlaneNum).recvZMatEesSimp(nZmat,zmat,
695 thisIndex.x,thisIndex.y,iterNL);
709 int state,
int index,
int iterNL_in){
713 int iterNL1 = iterNL_in-1;
714 int *nmem_zmat = sim->nmem_zmat;
715 int nZmat = nmem_zmat[iterNL1];
716 if(!config.doublePack){nZmat *= 2;}
722 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
723 CkPrintf(
"Dude, size != nzmat : %d : %d %d : %d %d\n",
724 iterNL,thisIndex.x,thisIndex.y,state,index);
725 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
728 if(iterNL!=iterNL_in && iterNL!=iterNL_in-1){
729 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
730 CkPrintf(
"Dude, wrong iterNls : %d %d : %d %d : %d %d\n",
731 iterNL,iterNL_in,thisIndex.x,thisIndex.y,state,index);
732 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
735 if(state != thisIndex.x){
736 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
737 CkPrintf(
"Dude, you sent to the wrong state : %d %d : %d %d : %d %d\n",
738 iterNL,iterNL_in,thisIndex.x,thisIndex.y,state,index);
739 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
749 if(countZ==1){bzero(zmatScr,nZmat*
sizeof(
double));}
750 for(
int i=0;i<nZmat;i++){zmatScr[i]+=_zmat[i];}
756 if(iterNL != iterNL){
757 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
758 CkPrintf(
"Wrong iterNls strange racing: %d %d : %d %d : %d %d\n",
759 iterNL,iterNL_in,thisIndex.x,thisIndex.y,state,index);
760 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
763 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
764 CkPrintf(
"HI, I am rPP %d %d in recvZmatSimp blasting off to forces: %d %d\n",
765 thisIndex.x,thisIndex.y,iterNL,index);
768 for(
int i=0;i<nChareR;i++){
770 if(config.prioNLFFTMsg){
771 CkSetQueueing(rmsg, CK_QUEUEING_IFIFO);
772 *(
int*)CkPriorityPtr(rmsg) = config.gsNLfftpriority+thisIndex.x+iterNL_in;
774 rmsg->init(nZmat,zmatScr,iterNL_in);
775 thisProxy(thisIndex.x,i).computeAtmForcEes(rmsg);
793 int iterNL_in = msg->getUserFlag();
795 int iterNL1 = iterNL-1;
796 int *nmem_zmat = sim->nmem_zmat;
797 int nZmat = nmem_zmat[iterNL1];
798 if(!config.doublePack){nZmat *=2;}
803 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
805 CkPrintf(
"HI, I am rPP %d %d in recvZmat : %d\n",thisIndex.x,thisIndex.y,iterNL);
808 for(
int i=0;i<msg->getSize()/
sizeof(double) ;i++){
809 CkAssert(finite(((
double*) msg->getData())[i]));
816 CkAssert(msg->getSize() == nZmat*
sizeof(double));
817 double *realValues = (
double *) msg->getData();
818 for(
int i=0;i<nZmat;i++){zmat[i]=realValues[i];}
825 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
827 CkPrintf(
"HI, I am rPP %d %d in recvZmat sending to compute: %d\n",
828 thisIndex.x,thisIndex.y,iterNL);
831 if(config.prioNLFFTMsg){
832 CkSetQueueing(rmsg, CK_QUEUEING_IFIFO);
833 *(
int*)CkPriorityPtr(rmsg) = config.gsNLfftpriority+thisIndex.x+iterNL_in;
836 rmsg->init(nZmat,zmat,iterNL);
837 CkAssert(rmsg->iterNL>0);
838 rPlaneSectProxy.computeAtmForcEes(rmsg);
856 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
858 CkPrintf(
"HI, I am rPP %d %d in compteAtmforc : %d\n",thisIndex.x,thisIndex.y,iterNL);
861 int nZmat_in=msg->nZmat;
863 double *zmat_loc=msg->zmat;
864 int iterNL_in=msg->iterNL;
865 CkAssert(msg->iterNL>0);
867 int iterNL1 = iterNL-1;
868 int *nmem_zmat = sim->nmem_zmat;
869 int nZmat = nmem_zmat[iterNL1];
870 if(!config.doublePack){nZmat *=2;}
873 if(iterNL_in != iterNL || nZmat_in != nZmat){
874 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
875 CkPrintf(
"RPP [%d,%d] Dude, iteration mismatch : %d %d z %d %d\n",
876 thisIndex.x,thisIndex.y,
877 iterNL,iterNL_in,nZmat_in, nZmat );
878 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
882 CmiMemcpy(zmat,zmat_loc,
sizeof(
double)*nZmat_in);
887 eesCache *eesData = UeesCacheProxy[thisInstance.proxyOffset].ckLocalBranch ();
888 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
890 int *allowedRppChares = eesData->allowedRppChares;
891 CkAssert(allowedRppChares[myPlane]==1);
893 int *plane_index = eesData->RppData[myPlane]->plane_index;
894 int **igrid = eesData->RppData[myPlane]->igrid;
895 int *nBreakJ = eesData->RppData[myPlane]->nBreakJ;
896 int **sBreakJ = eesData->RppData[myPlane]->sBreakJ;
897 double **dmn_x = eesData->RppData[myPlane]->dmn_x;
898 double **dmn_y = eesData->RppData[myPlane]->dmn_y;
899 double **dmn_z = eesData->RppData[myPlane]->dmn_z;
900 double **mn = eesData->RppData[myPlane]->mn;
901 double *projPsiRScr = fftcache->tmpDataR;
902 complex *projPsiCScr = fftcache->tmpData;
903 fftcache->getCacheMem(
"CP_State_RealParticlePlane::computeAtmForcEes");
905 AtomsCache *ag = UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
910 int n_a, n_b, n_c, n_interp, nAtm;
911 CPNONLOCAL::getEesPrms(&n_a,&n_b,&n_c,&n_interp,&nAtm);
912 int n_interp2=n_interp*n_interp;
917 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
919 CkPrintf(
"HI, I am rPP %d %d in compteAtmforc : %d\n",thisIndex.x,thisIndex.y,iterNL);
922 #ifdef _CP_GS_DUMP_VKS_
923 #ifdef _INSANEO_PARANOID_COMPARE_THAT_EATS_HUGE_MEMORY_
924 dumpMatrix2DDouble(
"mn",mn, nAtm, n_interp2, thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
925 dumpMatrix2DDouble(
"dmn_x",dmn_x, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
926 dumpMatrix2DDouble(
"dmn_y",dmn_y, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
928 dumpMatrix2DDouble(
"dmn_z",dmn_z, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
929 dumpMatrix2DInt(
"igrid",igrid, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
933 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
937 if(savedprojpsiC==NULL)
939 savedprojpsiC=
new complex[csize];
940 loadMatrix(
"projPsiC",(
double *)savedprojpsiC, 1, csize*2,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
942 #ifdef _INSANEO_PARANOID_COMPARE_THAT_EATS_HUGE_MEMORY_
944 savedigrid = (
int **)fftw_malloc(nAtm*
sizeof(
int*));
946 savedmn = (
double **)fftw_malloc(nAtm*
sizeof(
double*));
947 saveddmn_x = (
double **)fftw_malloc(nAtm*
sizeof(
double*));
948 saveddmn_y = (
double **)fftw_malloc(nAtm*
sizeof(
double*));
949 saveddmn_z = (
double **)fftw_malloc(nAtm*
sizeof(
double*));
952 for(
int i=0;i<nAtm;i++){
953 savedigrid[i] = (
int *)fftw_malloc(n_interp2*
sizeof(
int))-1;
954 double *tmp = (
double *)fftw_malloc(4*n_interp2*
sizeof(
double));
959 savedmn[i] = &tmp[ioff]-1; ioff+=n_interp2;
960 saveddmn_x[i] = &tmp[ioff]-1; ioff+=n_interp2;
961 saveddmn_y[i] = &tmp[ioff]-1; ioff+=n_interp2;
962 saveddmn_z[i] = &tmp[ioff]-1;
965 loadMatrix2DDouble(
"mn",savedmn, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
966 loadMatrix2DDouble(
"dmn_x",saveddmn_x, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
967 loadMatrix2DDouble(
"dmn_y",saveddmn_y, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
968 loadMatrix2DDouble(
"dmn_z",saveddmn_z, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
969 loadMatrix2DInt(
"igrid",savedigrid, nAtm, n_interp2,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
972 for(
int i=0;i<nAtm;i++){
973 if(plane_index[i]!=0){
974 for(
int j=1;j<=n_interp2;j++){
975 if(fabs(mn[i][j]-savedmn[i][j])>0.0001){
976 fprintf(stderr,
"RPP [%d,%d] %d %d element mn %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,j,mn[i][j],savedmn[i][j]);
978 CkAssert(fabs(mn[i][j]-savedmn[i][j])<0.0001);
979 if(fabs(dmn_x[i][j]-saveddmn_x[i][j])>0.0001){
980 fprintf(stderr,
"RPP [%d,%d] %d %d element dmn_x %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,j,dmn_x[i][j],saveddmn_x[i][j]);
982 CkAssert(fabs(dmn_x[i][j]-saveddmn_x[i][j])<0.0001);
983 if(fabs(dmn_y[i][j]-saveddmn_y[i][j])>0.0001){
984 fprintf(stderr,
"RPP [%d,%d] %d %d element dmn_y %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,j,dmn_y[i][j],saveddmn_y[i][j]);
986 CkAssert(fabs(dmn_y[i][j]-saveddmn_y[i][j])<0.0001);
987 if(fabs(dmn_z[i][j]-saveddmn_z[i][j])>0.0001){
988 fprintf(stderr,
"RPP [%d,%d] %d %d element dmn_z %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,j,dmn_z[i][j],saveddmn_z[i][j]);
990 CkAssert(fabs(dmn_z[i][j]-saveddmn_z[i][j])<0.0001);
991 if(igrid[i][j]!=savedigrid[i][j]){
992 fprintf(stderr,
"RPP [%d,%d] %d %d element igrid %d not %d\n",thisIndex.x,thisIndex.y,i,j,igrid[i][j],savedigrid[i][j]);
994 CkAssert(igrid[i][j]==savedigrid[i][j]);
1004 #if CMK_TRACE_ENABLED
1005 double StartTime=CmiWallTimer();
1008 double cp_enl_now = 0.0;
1009 if(config.doublePack){
1010 CPNONLOCAL::eesEnergyAtmForcRchare(iterNL,&cp_enl_now,zmat,igrid,mn,dmn_x,dmn_y,dmn_z,
1011 projPsiR,projPsiRScr,plane_index,nBreakJ,sBreakJ,
1012 myPlane,thisIndex.x,kpoint_ind,fastAtoms);
1014 CPNONLOCAL::eesEnergyAtmForcRchareC(iterNL,&cp_enl_now,zmatC,igrid,mn,dmn_x,dmn_y,dmn_z,
1015 projPsiC,projPsiCScr,plane_index,nBreakJ,sBreakJ,
1016 myPlane,thisIndex.x,kpoint_ind,fastAtoms);
1018 cp_enl += cp_enl_now;
1020 #if CMK_TRACE_ENABLED
1021 traceUserBracketEvent(eesEnergyAtmForcR_, StartTime, CmiWallTimer());
1027 if(thisIndex.y==reductionPlaneNum && iterNL==numIterNl){
1028 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1030 CkPrintf(
"HI, I am rPP %d %d sending Enl : %d\n",thisIndex.x,thisIndex.y,iterNL);
1033 #ifdef _FANCY_RED_METHOD_
1034 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
1036 CkCallback cb(CkIndex_CP_State_RealParticlePlane::printEnlR(NULL),
1037 CkArrayIndex2D(0,reductionPlaneNum),
1038 UrealParticlePlaneProxy[thisInstance.proxyOffset].ckGetArrayID());
1039 mcastGrp->contribute(
sizeof(
double),(
void*) &cp_enl,
1040 CkReduction::sum_double,rEnlCookie, cb, itime);
1042 thisProxy(0,0).printEnlRSimp(cp_enl,thisIndex.x,itime);
1049 #ifdef _CP_GS_DUMP_VKS_
1050 dumpMatrix(
"zmat",(
double *)zmat, 1, nZmat_in,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
1051 dumpMatrix(
"projPsiRScr",(
double *)projPsiRScr, 1, planeSize,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1054 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
1059 savedzmat=
new double[nZmat_in];
1060 loadMatrix(
"zmat",(
double *)savedzmat, 1, nZmat_in,thisIndex.y,thisIndex.x,thisIndex.x,iterNL,
false);
1062 for(
int i=0;i<nZmat_in; i++)
1064 if(fabs(zmat[i]-savedzmat[i])>0.0001)
1066 fprintf(stderr,
"RPP [%d,%d] %d element projpsi %.10g not %.10g\n",thisIndex.x, thisIndex.y,i, zmat[i], savedzmat[i]);
1068 CkAssert(fabs(zmat[i]-savedzmat[i])<0.0001);
1071 if(savedProjpsiRScr==NULL)
1073 savedProjpsiRScr=
new double[planeSize];
1074 loadMatrix(
"projPsiRScr",(
double *)savedProjpsiRScr, 1, planeSize,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1076 for(
int i=0;i<planeSize;i++)
1078 if(fabs(projPsiRScr[i]-savedProjpsiRScr[i])>0.0001)
1080 fprintf(stderr,
"RPP [%d,%d] %d element projpsi %.10g not %.10g\n",thisIndex.x, thisIndex.y,i, projPsiRScr[i], savedProjpsiRScr[i]);
1081 dumpMatrix(
"badprojPsiRScr",(
double *)projPsiRScr, 1, planeSize,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1083 CkAssert(fabs(projPsiRScr[i]-savedProjpsiRScr[i])<0.0001);
1092 if(iterNL==numIterNl){
1117 if(iterNL!=1){CkPrintf(
"Badddd launchFFT.3\n");CkExit();}
1118 if(rhoRTime!=itime){CkPrintf(
"Badddd launchFFT.4\n");CkExit();}
1119 thisProxy(thisIndex.x,thisIndex.y).FFTNLEesFwdR();
1135 int nplane_x = sim->nplane_x;
1136 if(!config.doublePack){nplane_x = (nplane_x+1)/2;}
1138 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1140 CkPrintf(
"HI, I am rPP %d %d in FFTNLbck : %d %d %d %d\n",
1141 thisIndex.x,thisIndex.y,iterNL,ngridA,ngridB,nplane_x);
1144 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
1145 double *projPsiRScr = fftcache->tmpDataR;
1146 complex *projPsiCScr = fftcache->tmpData;
1151 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
1153 if(savedProjpsiRScr==NULL){
1154 savedProjpsiRScr=
new double[planeSize];
1155 loadMatrix(
"projPsiRScr",(
double *)savedProjpsiRScr, 1, planeSize,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1158 for(
int i=0;i<planeSize;i++){
1159 if(fabs(projPsiRScr[i]-savedProjpsiRScr[i])>0.0001){
1160 fprintf(stderr,
"RPP[%d,%d] %d element projpsi %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,projPsiRScr[i],savedProjpsiRScr[i]);
1162 CkAssert(fabs(projPsiRScr[i]-savedProjpsiRScr[i])<0.0001);
1163 CkAssert(fabs(projPsiRScr[i]-savedProjpsiRScr[i])<0.0001);
1170 #if CMK_TRACE_ENABLED
1171 double StartTime= CmiWallTimer();
1174 fftcache->
doNlFFTRtoG_Rchare(projPsiCScr,projPsiRScr,nplane_x,ngridA,ngridB,myPlane);
1176 #ifndef CMK_OPTIMIZE
1177 traceUserBracketEvent(doNlFFTRtoG_, StartTime, CmiWallTimer());
1183 #ifdef _CP_GS_DUMP_VKS_
1184 dumpMatrix(
"projPsiCScr",(
double *)projPsiCScr, 1, (ngridA+2)*ngridB,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1187 #ifdef _CP_GS_DEBUG_COMPARE_VKS_
1191 if(savedProjpsiCScr==NULL){
1192 savedProjpsiCScr=
new complex[csize];
1193 loadMatrix(
"projPsiCScr",(
double *)savedProjpsiCScr, 1, csize*2,thisIndex.y,thisIndex.x,thisIndex.x,0,
false);
1195 for(
int i=0;i<csize;i++){
1196 if(fabs(projPsiCScr[i].re-savedProjpsiCScr[i].re)>0.0001){
1197 fprintf(stderr,
"RPP [%d,%d] %d element projpsi %.10g not %.10g\n",thisIndex.x,thisIndex.y,i,
1198 projPsiCScr[i].re,savedProjpsiCScr[i].re);
1199 fprintf(stderr,
"HI, I am rPP %d %d in FFTNLbck : %d %d %d %d\n",
1200 thisIndex.x,thisIndex.y,iterNL,ngridA,ngridB,nplane_x);
1202 CkAssert(fabs(projPsiCScr[i].re-savedProjpsiCScr[i].re)<0.0001);
1203 CkAssert(fabs(projPsiCScr[i].im-savedProjpsiCScr[i].im)<0.0001);
1207 #if CMK_TRACE_ENABLED
1208 traceUserBracketEvent(doNlFFTRtoG_, StartTime, CmiWallTimer());
1230 FFTcache *fftcache = UfftCacheProxy[thisInstance.proxyOffset].ckLocalBranch();
1231 int nchareG = sim->nchareG;
1232 int **tranpack = sim->index_tran_upackNL;
1233 int *nlines_per_chareG = sim->nlines_per_chareG;
1234 complex *projPsiCScr = fftcache->tmpData;
1239 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1241 CkPrintf(
"HI, I am rPP %d %d in sendtoGPP : %d\n",thisIndex.x,thisIndex.y,iterNL);
1246 if(config.useMssInsGPP){mssPInstance.beginIteration();}
1252 for (
int ic=0;ic<nchareG;ic++) {
1253 int sendFFTDataSize = nlines_per_chareG[ic];
1255 msg->iterNL = iterNL;
1256 msg->size = sendFFTDataSize;
1257 msg->offset = thisIndex.y;
1259 if(config.prioNLFFTMsg){
1260 CkSetQueueing(msg, CK_QUEUEING_IFIFO);
1261 *(
int*)CkPriorityPtr(msg) = config.gsNLfftpriority+thisIndex.x;
1263 for(
int i=0;i<sendFFTDataSize;i++){data[i] = projPsiCScr[tranpack[ic][i]];}
1264 UparticlePlaneProxy[thisInstance.proxyOffset](thisIndex.x, ic).recvFromEesRPP(msg);
1269 if(config.useMssInsGPP){mssPInstance.endIteration();}
1281 if(iterNL==numIterNl){
1287 fftcache->freeCacheMem(
"CP_State_RealParticlePlane::sendToEesGPP");
1304 int nstatemax=nstates-1;
1305 int ncharemax=nChareR-1;
1306 int planeNum= (state %ncharemax);
1308 CkPrintf(
" PP [%d %d] calc nstatemax %d ncharemax %d state %d planenum %d\n",
1309 thisIndex.x, thisIndex.y,nstatemax, ncharemax, state, planeNum);
1327 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1329 CkPrintf(
"RPP[%d %d] gets rPlaneRedCookie\n",thisIndex.x, thisIndex.y);
1332 CkGetSectionInfo(rPlaneRedCookie,m);
1334 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
1335 CkCallback cb(CkIndex_CP_State_RealParticlePlane::planeRedSectDone(NULL),
1336 CkArrayIndex2D(thisIndex.x,reductionPlaneNum),
1337 UrealParticlePlaneProxy[thisInstance.proxyOffset].ckGetArrayID());
1338 mcastGrp->contribute(
sizeof(
int),&cookiedone,CkReduction::sum_int,
1339 rPlaneRedCookie,cb);
1341 if(thisIndex.y!=reductionPlaneNum)
1343 planeRedSectionComplete=
true;
1359 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1361 CkPrintf(
"RPP[%d %d] gets rEnlCookie\n",thisIndex.x, thisIndex.y);
1363 CkGetSectionInfo(rEnlCookie,m);
1365 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
1366 CkCallback cb(CkIndex_CP_State_RealParticlePlane::enlSectDone(NULL),
1367 CkArrayIndex2D(0,reductionPlaneNum),
1368 UrealParticlePlaneProxy[thisInstance.proxyOffset].ckGetArrayID());
1369 mcastGrp->contribute(
sizeof(
int), &cookiedone,
1370 CkReduction::sum_int,rEnlCookie, cb);
1372 if(thisIndex.y!=reductionPlaneNum || thisIndex.x!=0){
1373 enlSectionComplete=
true;
1388 #ifdef _CP_DEBUG_STATE_RPP_VERBOSE_
1390 CkPrintf(
"HI, I am realPPa %d %d \n",thisIndex.x,thisIndex.y);
1397 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
1398 CkPrintf(
"Homes, registeration must occur before the 1st time step in RPP\n");
1399 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
1410 void CP_State_RealParticlePlane::pup(PUP::er &p) {
1422 p|ibead_ind; p|kpoint_ind; p|itemper_ind;
1439 p|reductionPlaneNum;
1449 if(ees_nonlocal==1){
1450 int nZ = zmatSizeMax;
1451 if(config.doublePack){nZ *=2;}
1452 if (p.isUnpacking()) {
1454 projPsiR =
reinterpret_cast<double*
> (projPsiC);
1455 if(config.doublePack){
1456 zmat = (
double*) fftw_malloc(zmatSizeMax*
sizeof(
double));
1457 zmatScr = (
double*) fftw_malloc(zmatSizeMax*
sizeof(
double));
1461 zmat =
reinterpret_cast<double*
> (zmatC);
1462 zmatScr =
reinterpret_cast<double*
> (zmatScrC);
1467 p((
char*)projPsiC,csize *
sizeof(
complex));
void recvZMatEes(CkReductionMsg *)
Reduction client of zmat : Here everyone must have the same iteration ///////////////////////////////...
void doNlFFTRtoG_Rchare(complex *, double *, int, int, int, int)
non-local : Rchare : data(x,y,z) -> data(gx,gy,z) : backward ////////////////////////////////////////...
void planeRedSectDone(CkReductionMsg *m)
All cookies initialized for zmat plane reduction ////////////////////////////////////////////////////...
holds the UberIndex and the offset for proxies
void printEnlR(CkReductionMsg *m)
Energy reduction client for ees method! /////////////////////////////////////////////////////////////...
int calcReductionPlaneNum(int)
spread the reduction plane numbers around to minimize map collisions
void computeAtmForcEes(CompAtmForcMsg *msg)
Use Zmat and ProjPsi to get atmForces, Energy and psiforces /////////////////////////////////////////...
void init()
Post construction initialization.
CProxy_InstanceController instControllerProxy
void FFTNLEesBckR()
Do the FFT of projPsi(x,y,z) to get projPsi(gx,gy,z) ////////////////////////////////////////////////...
void sendToEesGPP()
Send the PsiForce NL FFT back to GparticlePlane.
void initComplete()
Initialization and registration done for this chare /////////////////////////////////////////////////...
void printEnlRSimp(double, int, int)
Energy reduction client for ees method! /////////////////////////////////////////////////////////////...
~CP_State_RealParticlePlane()
The destructor : never called directly but I guess migration needs it ///////////////////////////////...
void setPlaneRedCookie(EnlCookieMsg *)
Recv a dummy message, 1 integer, and set the cookie monster /////////////////////////////////////////...
void FFTNLEesFwdR()
Complete the Forward FFT of psi-projector sent from g-space chares //////////////////////////////////...
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 recvFromEesGPP(NLFFTMsg *)
Recv FFT data/psi-projector from CP_StateParticlePlane kicking things off for this Chare...
void queryCacheRPP(int, int, int)
= realParticlePlane Cache Management tool
void enlSectDone(CkReductionMsg *m)
All cookies initialized for enl section, only reduction root receives this //////////////////////////...
void recvZMatEesSimp(int, double *, int, int, int)
A chare can be behind by 1 iteration only.
Some basic data structures and the array map classes are defined here.
void launchFFTControl(int)
Control launch of FFT based on Rho having more of its act together //////////////////////////////////...
void registrationDone()
= Make sure everyone is registered on the 1st time step
Group Container class : Only allowed chare data classes have data.
void setEnlCookie(EnlCookieMsg *)
Recv a dummy message, 1 integer, and set the cookie monster /////////////////////////////////////////...
void computeZmatEes()
Compute the Zmat elements of this iteration : Spawn the section reduction ///////////////////////////...
void registerCacheRPP(int)
= realParticlePlane Cache Management tool