OpenAtom  Version1.5a
GSpaceDriver.C
1 #include "GSpaceDriver.h"
2 #include "CP_State_GSpacePlane.h"
3 #include "CP_State_ParticlePlane.h"
4 #include "main/TimeKeeper.h"
5 
6 extern int nstates;
7 extern Config config;
8 
9 extern CProxy_TimeKeeper TimeKeeperProxy;
10 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
11 extern CkVec <CProxy_CP_State_ParticlePlane> UparticlePlaneProxy;
12 extern CkVec <CProxy_StructureFactor> UsfCompProxy;
13 extern CProxy_InstanceController instControllerProxy;
14 
15 /** @addtogroup GSpaceState
16  @{
17 */
18 /// Constructor
20  thisInstance(_thisInstance),
21  myGSpaceObj(0),
22  isFirstStep(true),
23  isPsiVupdateNeeded(false)
24 {
25  #ifdef DEBUG_CP_GSPACE_CREATION
26  CkPrintf("GSpaceDriver[%d,%d] born\n",thisIndex.x,thisIndex.y);
27  #endif
28  /// Initialize flags and counters that record the control
29  /// state
30  CPcharmParaInfo *sim = CPcharmParaInfo::get();
31  ees_nonlocal = sim->ees_nloc_on;
32  natm_nl = sim->natm_nl;
33  cp_min_opt = sim->cp_min_opt;
34  gen_wave = sim->gen_wave;
35  ndump_frq = sim->ndump_frq;
36 }//end routine
37 
38 
39 
40 
41 ///
42 GSpaceDriver::GSpaceDriver(CkMigrateMessage *msg):
43  myGSpaceObj(0)
44 {}
45 
46 
47 
48 
49 /// PUP method
50 void GSpaceDriver::pup(PUP::er &p)
51 {
52  __sdag_pup(p);
53  p|isFirstStep;
54  p|ees_nonlocal;
55  p|natm_nl;
56  p|cp_min_opt;
57  p|gen_wave;
58  p|ndump_frq;
59  p|isPsiVupdateNeeded;
61 }
62 
63 
64 
65 
66 /** Creates a structure factor array section proxy that is used later in releaseSFComputeZ.
67  * @todo: When is the earliest that you can do this? Can we do this upon construction? Probably not, as we have no guarantee that
68  * UsfCompProxy is up and ready.
69  */
71 {
72  /// If EES nonlocals are off, each state=0 driver chare
73  /// creates a structure factor array section
74  if(thisIndex.x==0 && ees_nonlocal==0)
75  {
76  /// numDups must be less than the number of states because thats the maximum number of times you can duplicate a plane
77  int numSfDups = config.numSfDups;
78  if(numSfDups > nstates)
79  numSfDups = nstates;
80  /// Create a list of SF chares in this section
81  CkVec <CkArrayIndex3D> sfelems;
82  for(int dup=0; dup<numSfDups; dup++)
83  for(int atm=0;atm<config.numSfGrps; atm++)
84  sfelems.push_back(CkArrayIndex3D(atm,thisIndex.y,dup));
85  /// Create the SF array section
86  sfCompSectionProxy = CProxySection_StructureFactor::ckNew( UsfCompProxy[thisInstance.proxyOffset].ckGetArrayID(),
87  (CkArrayIndexMax*)sfelems.getVec(), sfelems.size());
88  }
89 }
90 
91 
92 
93 
94 /** Called from InstanceController::doneInit which is a reduction client invoked by all (state,plane)
95  * objects after completion of CP_State_GspacePlane::initGSpace
96  */
98 {
99  /// Get hold of the (local) GSpacePlane and ParticlePlane objects that we'll be working with
100  myGSpaceObj = UgSpacePlaneProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).ckLocal();
101  CkAssert(myGSpaceObj);
102  myParticlePlaneObj = UparticlePlaneProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).ckLocal();
103  CkAssert(myParticlePlaneObj);
104  /// Do other initialization chores
105  init();
106  /// Call the SDAG method in charge of control flow
107  driveGSpace();
108 }
109 
110 
111 
112 /// Ortho notifies us that GSpace needs a tolerance update (velocity rotation)
114 {
115  isPsiVupdateNeeded = true;
116  // Once all driver chares are notified, restart Ortho's backward path
117  int foo=1;
118  contribute( sizeof(int), &foo, CkReduction::min_int, CkCallback(CkIndex_Ortho::resumeV(NULL), myGSpaceObj->myOrtho) );
119 }
120 
121 /// Trigger the nonlocal computations
122 void GSpaceDriver::startNonLocalEes(int iteration_loc)
123 {
124  if(iteration_loc!=myGSpaceObj->iteration)
125  CkAbort("GSpaceDriver::startNonLocalEes - Iteration mismatch between GSpace and someone else who asked to launch NL computations\n");
126 
127  /// Set to false, just before I spawn the nonlocal work
128 
129  if(natm_nl!=0){
130  #define _NLEES_PRIO_START_
131  #ifdef _NLEES_PRIO_START_OFF_
132  myParticlePlaneObj->startNLEes(iteration);
133  #else
134  NLDummyMsg *msg = new(8*sizeof(int)) NLDummyMsg;
135  CkSetQueueing(msg, CK_QUEUEING_IFIFO);
136  *(int*)CkPriorityPtr(msg) = config.sfpriority;
137  msg->iteration = myGSpaceObj->iteration;
138  UparticlePlaneProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y).lPrioStartNLEes(msg);
139  #endif
140  }//endif
141 }
142 
143 
144 
145 
146 #include "structure_factor/StructureFactorMessages.h"
147 
149 {
150  #ifdef _CP_DEBUG_SF_CACHE_
151  CkPrintf("GSpaceDriver[%d,%d] Releasing SF computations\n",thisIndex.x,thisIndex.y);
152  #endif
153  #ifdef _CP_DEBUG_STATE_GPP_VERBOSE_
154  CkPrintf("GSpaceDriver[%d,%d] Releasing SF computations\n",thisIndex.x,thisIndex.y);
155  #endif
156 
157  /// Set to false, just before I spawn the nonlocal work
158  /// Tell the structure factor chares to do their work
159  if(thisIndex.x==0)
160  {
161  /// Multicast to all states of our plane and dups using the section proxy
162  SFDummyMsg *msg = new(8*sizeof(int)) SFDummyMsg;
163  CkSetQueueing(msg, CK_QUEUEING_IFIFO);
164  *(int*)CkPriorityPtr(msg) = config.sfpriority;
165  msg->iteration_src = myGSpaceObj->iteration;
166  sfCompSectionProxy.computeSF(msg);
167  }
168  /// Call on corresponding particle plane chare to launch all the Z matrix computations
170 }
171 /*@}*/
172 #include "gSpaceDriver.def.h"
CProxySection_StructureFactor sfCompSectionProxy
Array section of the structure factor chares that I will be triggering.
Definition: GSpaceDriver.h:85
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
GSpaceDriver_SDAG_CODE GSpaceDriver()
Constructors.
Definition: GSpaceDriver.h:39
void releaseSFComputeZ()
Triggers nonlocal energy computations.
Definition: GSpaceDriver.C:148
CProxy_InstanceController instControllerProxy
Definition: cpaimd.ci:236
entry void driveGSpace()
SDAG method for flow control of the Driver and its associated GSpace object.
Definition: gspace.ci:60
void startControl()
Entry Method. Creates and invokes the SDAG that controls GSpace execution.
Definition: GSpaceDriver.C:97
CProxy_Ortho myOrtho
A proxy for the my ortho chare array so I can interact with it.
const UberCollection thisInstance
A handle to the local copy of the config parameters (refresh on migration)
Definition: GSpaceDriver.h:83
CP_State_GSpacePlane * myGSpaceObj
Pointer to the GSpacePlane object that I am driving (controlling)
Definition: GSpaceDriver.h:76
bool isFirstStep
True if this is the first step.
Definition: GSpaceDriver.h:59
A place to collect substep times.
void init()
Initializer.
Definition: GSpaceDriver.C:70
void pup(PUP::er &p)
PUP method.
Definition: GSpaceDriver.C:50
void startNonLocalEes(int iteration_loc)
Entry Method. Triggers nonlocal energy computations.
Definition: GSpaceDriver.C:122
void startNLEes(int)
= The entry point to the Euler Exponential Spline non-local method.
CP_State_ParticlePlane * myParticlePlaneObj
Pointer to the ParticlePlane object that I am driving (controlling)
Definition: GSpaceDriver.h:78
void needUpdatedPsiV()
Entry Method. Ortho notifies us that GSpace needs a tolerance update (velocity rotation) ...
Definition: GSpaceDriver.C:113
void launchComputeZs()
Entry Method. GSpaceDriver calls this to trigger the launch of the computeZ()s to compute the Z matri...