6 #include "InstanceController.h"
13 extern CkVec < CkVec <int> > UplaneUsedByNLZ;
14 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
15 extern CkVec <CProxy_GSpaceDriver> UgSpaceDriverProxy;
16 extern CkVec <CProxy_CP_State_ParticlePlane> UparticlePlaneProxy;
17 extern CkVec <CProxy_CP_State_RealParticlePlane> UrealParticlePlaneProxy;
18 extern CkVec <CProxy_CP_State_RealSpacePlane> UrealSpacePlaneProxy;
19 extern CkVec <CProxy_CP_Rho_RealSpacePlane> UrhoRealProxy;
20 extern CkVec <CProxy_CP_Rho_GSpacePlane> UrhoGProxy;
21 extern CkVec <CProxy_CP_Rho_RHartExt> UrhoRHartExtProxy;
22 extern CkVec <CProxy_CP_Rho_GHartExt> UrhoGHartExtProxy;
23 extern CkVec <CProxy_AtomsCache> UatomsCacheProxy;
24 extern CkVec <CProxy_AtomsCompute> UatomsComputeProxy;
25 extern CkVec <CProxy_EnergyGroup> UegroupProxy;
26 extern CkVec <CProxy_FFTcache> UfftCacheProxy;
27 extern CkVec <CProxy_StructFactCache> UsfCacheProxy;
28 extern CkVec <CProxy_StructureFactor> UsfCompProxy;
29 extern CkVec <CProxy_eesCache> UeesCacheProxy;
30 extern CkVec <CProxy_OrthoHelper> UorthoHelperProxy;
31 extern CProxy_TimeKeeper TimeKeeperProxy;
33 extern CkVec <UberCollection> UberAlles;
34 extern CProxy_ENL_EKE_Collector ENLEKECollectorProxy;
39 InstanceController::InstanceController() {
41 done_init=0;Timer=CmiWallTimer(); numKpointforces=0;
45 if((config.UberMmax >1 || config.UberJmax>1) && instance.idxU.y==0 && instance.idxU.s==0)
48 CkVec <CkArrayIndex1D> elems;
49 for(
int kp =0; kp<config.UberJmax; kp++)
52 for(
int spin =0; spin<config.UberMmax; spin++)
56 elems.push_back(CkArrayIndex1D(instance.proxyOffset));
60 CProxySection_InstanceController sectProxy=CProxySection_InstanceController::ckNew(thisProxy.ckGetArrayID(),elems.getVec(),elems.size());
61 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
62 sectProxy.ckSectionDelegate(mcastGrp);
64 sectProxy.initCookie(cookieme);
71 void InstanceController::init(){
74 if((config.UberImax >1 || config.UberKmax>1) && instance.idxU.x==0 && instance.idxU.z==0)
77 int numDestinations=config.UberImax*config.UberKmax;
78 CkArrayID *beadArrayIds=
new CkArrayID[numDestinations];
79 CkArrayIndex **elems =
new CkArrayIndex*[numDestinations];
80 int *naelems =
new int[numDestinations];
81 for(
int bead =0; bead<config.UberImax; bead++)
84 for(
int temper =0; temper<config.UberKmax; temper++)
86 int index=bead*config.UberKmax+temper;
87 elems[index]=
new CkArrayIndex2D[1];
89 instance.idxU.z=temper;
91 CkPrintf(
"fmag sync section adding bead %d temper %d index %d proxyOffset %d\n",bead, temper, index, instance.proxyOffset);
92 beadArrayIds[index]=UgSpacePlaneProxy[instance.proxyOffset].ckGetArrayID();
93 elems[index][0]=CkArrayIndex2D(0,0);
97 gTemperBeadProxy=CProxySection_CP_State_GSpacePlane(numDestinations, beadArrayIds, elems, naelems);
98 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
99 gTemperBeadProxy.ckSectionDelegate(mcastGrp);
101 CkCallback *cb =
new CkCallback(CkIndex_InstanceController::fmagMinTest(NULL),CkArrayIndex1D(0),thisProxy);
102 mcastGrp->setReductionClient(gTemperBeadProxy,cb);
103 gTemperBeadProxy.initBeadCookie(cookieme);
112 void InstanceController::fmagMinTest(CkReductionMsg *m){
115 int result=( (
int *) (m->getData()) )[0];
120 gTemperBeadProxy.minimizeSync(out);
186 void InstanceController::doneInit(CkReductionMsg *msg){
188 CkPrintf(
"{%d} Done_init for %d userflag %d\n",thisIndex, (
int)((
int *)msg->getData())[0],msg->getUserFlag());
192 CkAssert(msg->getUserFlag()==thisIndex);
194 if(CPcharmParaInfo::get()->ees_nloc_on==1)
197 double newtime=CmiWallTimer();
198 CkAssert(done_init<numPhases+1);
200 if(done_init<numPhases){
201 CkPrintf(
"{%d} Completed chare instantiation phase %d in %g\n",thisIndex,done_init+1,newtime-Timer);
205 if(thisIndex==0) init();
207 if(thisInstance.idxU.y==0)
209 UrhoRealProxy[thisIndex].init();
210 UrhoGProxy[thisIndex].init();
211 UrhoGHartExtProxy[thisIndex].init();
213 {UrhoRHartExtProxy[thisIndex].init();}
218 if(CPcharmParaInfo::get()->ees_nloc_on==1)
219 {UrealParticlePlaneProxy[thisIndex].init();}
221 CkPrintf(
"{%d} Initiating import of states\n",thisIndex);
222 CkPrintf(
"{%d} IC uGSpacePlaneProxy[%d] is %d\n",thisIndex,thisIndex, CkGroupID(UgSpacePlaneProxy[thisIndex].ckGetArrayID()).idx);
223 for(
int s=0;s<nstates;s++) {
224 UgSpacePlaneProxy[thisIndex](s,UplaneUsedByNLZ[thisIndex][s]).readFile();
228 if (done_init == 5 && CPcharmParaInfo::get()->ees_nloc_on==1){
229 CkPrintf(
"{%d} Completed chare data acquisition phase %d in %g\n",thisIndex, done_init+1,newtime-Timer);
230 UrealParticlePlaneProxy[thisIndex].registrationDone();
233 if (done_init >= numPhases) {
234 if (done_init == numPhases){
236 CkPrintf(
"{%d} Chare array launch and initialization complete \n",thisIndex);
237 if(CPcharmParaInfo::get()->cp_min_opt==1){
238 CkPrintf(
"{%d} Running Open Atom CP Minimization: \n",thisIndex);
240 CkPrintf(
"{%d} Running Open Atom CP Dynamics: \n",thisIndex);
244 UgSpaceDriverProxy[thisIndex].startControl();
256 void InstanceController::initCookie(
ICCookieMsg *msg){
257 CkGetSectionInfo(allKPcookie, msg);
266 void InstanceController::printEnergyHart(CkReductionMsg *msg){
269 void *data=msg->getData();
270 double ehart = ((
double *)data)[0];
271 double eext = ((
double *)data)[1];
272 double ewd = ((
double *)data)[2];
273 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
274 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
275 fprintf(temperScreenFile,
"Iter [%d] EHART = %5.8lf\n", iteration, ehart);
276 fprintf(temperScreenFile,
"Iter [%d] EExt = %5.8lf\n", iteration, eext);
277 fprintf(temperScreenFile,
"Iter [%d] EWALD_recip = %5.8lf\n", iteration, ewd);
279 UgSpacePlaneProxy[thisIndex](0, 0).computeEnergies(ENERGY_EHART, ehart);
280 UgSpacePlaneProxy[thisIndex](0, 0).computeEnergies(ENERGY_EEXT, eext);
281 UgSpacePlaneProxy[thisIndex](0, 0).computeEnergies(ENERGY_EWD, ewd);
293 void InstanceController::printEnergyEexc(CkReductionMsg *msg){
298 void *data=msg->getData();
299 eexc += ((
double *)data)[0];
300 egga += ((
double *)data)[1];
301 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
302 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
304 fprintf(temperScreenFile,
"Iter [%d] EEXC = %5.8lf\n", iteration, eexc);
305 fprintf(temperScreenFile,
"Iter [%d] EGGA = %5.8lf\n", iteration, egga);
306 fprintf(temperScreenFile,
"Iter [%d] EEXC+EGGA = %5.8lf\n", iteration, eexc+egga);
308 UgSpacePlaneProxy[thisIndex](0, 0).computeEnergies(ENERGY_EEXC, eexc);
309 UgSpacePlaneProxy[thisIndex](0, 0).computeEnergies(ENERGY_EGGA, egga);
311 #define _GLENN_STUFF_OFF_
313 CkPrintf(
"exiting in printEnergyEexc\n");CkExit();
328 double d = ((
double *)m->getData())[0];
330 #ifdef _CP_DEBUG_SFNL_OFF_
331 CkPrintf(
"EKE = OFF FOR DEBUGGING\n");
334 if(config.UberKmax>1)
335 ENLEKECollectorProxy[thisInstance.idxU.z].acceptEKE(d);
336 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
337 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
338 fprintf(temperScreenFile,
"Iter [%d] EKE = %5.8lf\n", iteration, d);
339 fflush(temperScreenFile);
340 UgSpacePlaneProxy[thisIndex](0,0).computeEnergies(ENERGY_EKE, d);
353 double d0 = ((
double *)m->getData())[0];
354 double d1 = ((
double *)m->getData())[1];
355 double d2 = ((
double *)m->getData())[2];
356 double d3 = ((
double *)m->getData())[3];
357 double d4 = ((
double *)m->getData())[4];
360 if(CPcharmParaInfo::get()->cp_min_opt==0){
361 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
362 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
364 fprintf(temperScreenFile,
"Iter [%d] Fict Temp = %.10g K\n", iteration, d0);
365 fprintf(temperScreenFile,
"Iter [%d] Fict Eke = %.10g K\n", iteration, d2);
366 fprintf(temperScreenFile,
"Iter [%d] Fict TempNHC= %.10g K\n", iteration, d1);
367 fprintf(temperScreenFile,
"Iter [%d] Fict EkeNHC = %.10g K\n", iteration, d3);
368 fprintf(temperScreenFile,
"Iter [%d] Fict PotNHC = %.10g K\n", iteration, d4);
369 fprintf(temperScreenFile,
"Iter [%d] Fict EConv = %.10g K\n", iteration, d2+d3+d4);
371 UgSpacePlaneProxy[thisIndex](0,0).computeEnergies(ENERGY_FICTEKE, d0);
400 if(config.UberJmax>1 || config.UberMmax >1 )
404 long unsigned int foo(1);
407 int offset=instance.calcPO();
409 CkMulticastMgr *mcastGrp = CProxy_CkMulticastMgr(
mCastGrpId).ckLocalBranch();
410 CkCallback cb(CkIndex_InstanceController::allDoneCPForcesAllKPoint(NULL),CkArrayIndex1D(offset),thisProxy);
411 mcastGrp->contribute(
sizeof(
long unsigned int),&foo,CkReduction::sum_int, allKPcookie, cb);
415 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
416 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
418 fprintf(temperScreenFile,
"Iter [%d] allDoneCPForces bead %d\n",iteration,thisInstance.idxU.x);
419 UatomsComputeProxy[thisIndex].startRealSpaceForces();
430 void InstanceController::allDoneCPForcesAllKPoint(CkReductionMsg *m){
432 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
433 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
435 fprintf(temperScreenFile,
"Iter [%d] allDoneCPForces bead %d\n",iteration,thisInstance.idxU.x);
436 UatomsComputeProxy[thisIndex].startRealSpaceForces();
445 FILE *temperScreenFile = UatomsCacheProxy[thisIndex].ckLocalBranch()->temperScreenFile;
446 int iteration= UatomsCacheProxy[thisIndex].ckLocalBranch()->iteration;
447 fprintf(temperScreenFile,
"Iter [%d] called cleanExit\n",iteration);
450 contribute(
sizeof(
int), &exited, CkReduction::sum_int,
451 CkCallback(CkIndex_InstanceController::cleanExitAll(NULL),CkArrayIndex1D(0),thisProxy), 0);
458 void InstanceController::acceptNewTemperature(
double temperature){
464 for(
int integral=0; integral< config.UberImax; integral++)
466 anIndex.idxU.x=integral;
467 for(
int kpoint=0; kpoint< config.UberJmax; kpoint++)
469 anIndex.idxU.y=kpoint;
470 for(
int spin=0; spin< config.UberMmax; spin++) {
473 thisProxy[anIndex.proxyOffset].useNewTemperature(temperature);
484 void InstanceController::useNewTemperature(
double temperature){
489 UatomsComputeProxy[thisIndex].acceptNewTemperature(temperature);
490 UgSpacePlaneProxy[thisIndex].acceptNewTemperature(temperature);
499 void InstanceController::atomsDoneNewTemp(CkReductionMsg *m)
503 UegroupProxy[thisIndex].resumeFromTemper();
510 void InstanceController::gspDoneNewTemp(CkReductionMsg *m)
514 UegroupProxy[thisIndex].resumeFromTemper();
525 CkPrintf(
"********************************************************************************\n");
526 CkPrintf(
"\n"); CkPrintf(
"\n");
527 CkPrintf(
"********************************************************************************\n");
528 CkPrintf(
" Open Atom Simulation Complete \n");
529 CkPrintf(
"********************************************************************************\n");
533 #include "instanceController.def.h"
holds the UberIndex and the offset for proxies
Accepts reduction of forces from AtomsCache, integrates forces to produce new coordinates, distributes new coordinates to AtomsCache.
void allDoneCPForces(CkReductionMsg *m)
When ALL the cp forces are done, you can integrate the atoms.
void printEnergyEke(CkReductionMsg *m)
Print out Quantum KE and put all the energies into the message group ////////////////////////////////...
CkGroupID mCastGrpId
Multicast manager group that handles many mcast/redns in the code. Grep for info. ...
Some basic data structures and the array map classes are defined here.
void cleanExit(CkReductionMsg *m)
When the simulation is done on each instance, make a clean exit this gets called by each instance...
void cleanExitAll(CkReductionMsg *m)
When the simulation is done, make a clean exit this gets called on the 0th element when everyone call...
void printFictEke(CkReductionMsg *msg)
Print out Fict CP KE and send it to the energy group ////////////////////////////////////////////////...