OpenAtom  Version1.5a
CP_State_GSpacePlane.h
1 #include "debug_flags.h"
2 #include "charm++.h"
3 #include "ckcomplex.h"
4 #include "gStatePlane.decl.h"
5 #include "pcCommManager.h"
6 #include "uber/Uber.h"
8 struct EnergyStruct; /// @warning: Forward declarations of structs seem to choke the ci parser. It doesnt recognize the keyword struct.
9 #include "paircalc/ckPairCalculator.h"
10 #include "cpaimd.decl.h"
11 #include "utility/matrix2file.h"
12 
13 using namespace cp::gspace; // note: Should be temporary until GSpace chares live within namespace gspace
14 
15 #ifndef CP_STATE_GSPACE_PLANE_H
16 #define CP_STATE_GSPACE_PLANE_H
17 /** @addtogroup GSpaceState
18  @{
19 */
20 
21 /// Forward declarations
22 class GStateSlab;
23 class RDMApair_GSP_PC;
24 template <class tokenType> class RDMASetupConfirmationMsg;
25 
26 
28 {
29  public:
30  int size;
31  int offset;
32  complex *data;
33 };
34 
35 
36 
37 
39 {
40  public:
41  int size;
42  int senderIndex;
43  complex *data;
44 };
45 
46 
47 
48 
50 {
51  public:
52  int size;
53  int senderIndex;
54  complex *data;
55  complex *vdata;
56  int *k_x;
57  int *k_y;
58  int *k_z;
59 };
60 
61 
62 
63 
64 class RSFFTMsg: public CMessage_RSFFTMsg {
65 public:
66  int size;
67  int senderIndex;
68  int senderJndex;
69  int senderKndex;
70  int numPlanes;
71  complex *data;
72 };
73 
74 
75 
76 /**
77  * @brief 2D chare array [\ref nchareG][\ref nstates] Handles the
78  * electronic structure in Fourier space (referred to as GSpace). Due
79  * to spherical cutoff sparsity, GSpace is rearranged into
80  * approximately equal size chunks \re nchareg. The number of chunks
81  * is a free parameter selected at runtime.
82  * A 2D chare array [\ref nchareG][\ref nstates] holding the
83  * electronic structure in Fourier space (referred to as GSpace). Due
84  * to spherical cutoff sparsity, GSpace is rearranged into
85  * approximately equal size chunks \re nchareg. The number of chunks
86  * is a free parameter selected at runtime.
87  *
88  * This is a description of the 'life' of a CP_State_GSpacePlane
89  * object. At the beginning of the program, the constructor
90  * CP_State_GSpacePlane() is called, to initialize the
91  * CP_State_GSpacePlane array. The GSpaceSlab within the
92  * CP_State_GSpacePlane is initialized using the initGSpace(...)
93  * method.
94  *
95  * To start off an iteration of program execution, the method doFFT()
96  * is called. As part of this method, the CP_State_GSpacePlane object
97  * does a forward 1-D fft on its slab of data, and sends off this data
98  * to the next stage in the computational loop. After this, the
99  * CP_State_GSpacePlane is idle, waiting for a message to trigger some
100  * computation/communication.
101  *
102  * The idle period of the CP_State_GSpacePlane is terminated by a called to
103  * the method doIFFT(). In this method, the CP_State_GSpacePlane receives the
104  * partially processed data from the CP_State_RealSpacePlanes and performs
105  * 1-D inverse FFT on its slab of data. Then the calculation of the "S"
106  * matrix is started by calling the sendPsi() method
107  *
108  * After the forces are calculated using the inverse FFT, a check is done
109  * to see if the forces from the particle calculations are ready. If so, the
110  * forces are added up. The sendPsi() method is not called until the forces
111  * from the particle calculations and the forces from the quantum computation
112  * are ready.
113  *
114  * The object is idle until the corrected g-space data from orthonormalization
115  * is received through the acceptNewPsi() method.
116  */
117 
119 {
120  public:
121  CP_State_GSpacePlane_SDAG_CODE
122  friend class CP_State_ParticlePlane;
123  // ----------- Flags and counters used in the GSpace driver code -----------
124  /// My state index
126  /// My plane index
128  int ibead_ind,kpoint_ind, itemper_ind,ispin_ind;
129  ///
130  int iteration;
131  ///
132  int iRecvRedPsi;
133  ///
134  int cleanExitCalled;
135  ///
136  bool doneDoingIFFT;
137  /// A proxy for the my ortho chare array so I can interact with it
138  CProxy_Ortho myOrtho;
139 
140  int halfStepEvolve;
141  int redPlane;
142  int registrationFlag;
143  int nrotation;
144  int exitFlag;
145  int exitFlagMin;
146  int outputFlag;
147  int iRecvRedPsiV;
148  int iSentRedPsi;
149  int iSentRedPsiV;
150  int finishedCpIntegrate;
151  int numRecvRedPsi;
152  int iterRotation;
153  int myBeadIndex;
154  int myKptIndex;
155  int myTemperIndex;
156  int mySpinIndex;
157 
158  double ake_old;
159 
160  bool acceptedVPsi;
161  CP_State_GSpacePlane( int, int, int, int,int, int, UberCollection);
162  CP_State_GSpacePlane(CkMigrateMessage *m);
164  /// Gets called from the PairCalc data receivers to confirm the setup of an RDMA link
165  void completeRDMAhandshake(RDMASetupConfirmationMsg<RDMApair_GSP_PC> *msg);
166  void pup(PUP::er &);
167 
168  void acceptPairCalcAIDs(pcSetupMsg *msg);
169  void initGSpace(int, complex *,int ,complex *,int,int,int,int,int,int,int);
170  void launchAtoms();
171  void launchOrthoT();
172  void doFFT();
173  void startNewIter ();
174  void sendPsi();
175  void sendPsiV();
176  void screenOutputPsi(int);
177  void sendLambda();
178  void makePCproxies();
179  void doneRedPsiIntegrate();
180  void sendRedPsi();
181  void combineForcesGetEke();
182  void integrateModForce();
183  void contributeFileOutput();
184  void unpackFileOutput(GStateOutMsg* msg);
185  void writeOutputFile();
186  /// @entry This is used to receive data from all the corresponding RealSpacePlanes, upon which the inverse FFTs are triggered
187  void unpackIFFT(GSIFFTMsg *);
188  void doIFFT();
189  void unpackNewPsi(CkReductionMsg *msg);
190  void unpackNewPsi(partialResultMsg *msg);
191  void doNewPsi();
192  void collectFileOutput(GStateOutMsg *msg);
193  void unpackNewPsiV(CkReductionMsg *msg);
194  void unpackNewPsiV(partialResultMsg *msg);
195  void doNewPsiV();
196  void psiCgOvlap(CkReductionMsg *msg);
197  void unpackLambda(CkReductionMsg *msg);
198  void unpackLambda(partialResultMsg *msg);
199  void doLambda();
200  void unpackRedPsi(GSRedPsiMsg *msg);
201 
202  void initBeadCookie(ICCookieMsg *m);
203  void minimizeSync(ICCookieMsg *m);
204  void computeCgOverlap();
205  void sendFFTData ();
206  void setExitFlag();
207  void readFile();
208  void computeEnergies(int p, double d);
209  void startFFT(CkReductionMsg *msg);
210  void sendRedPsiV();
211  void unpackRedPsiV(GSRedPsiMsg *msg);
212  void doneRedPsiVIntegrate();
213  void screenPrintWallTimes();
214  void acceptNewTemperature(double temp);
215  const UberCollection thisInstance;
216  CkSectionInfo beadCookie;
217  private:
218  FILE *temperScreenFile;
219  double *wallTimeArr;//only used on [0,0]
220  int gotHandles;
221  int forwardTimeKeep;
222  int backwardTimeKeep;
223  int ireset_cg;
224  int numReset_cg;
225  int istart_typ_cp;
226  int countIFFT;
227  int countFileOut;
228  int countRedPsi;
229  int countRedPsiV;
230  int ecount;
231  int countPsi;
232  int countVPsi;
233  int countLambda;
234  int *countPsiO;
235  int *countVPsiO;
236  int *countLambdaO;
237  int AllPsiExpected;
238  int AllLambdaExpected;
239  /// The number of symmetric and asymmetric PCs that communicate with me
240  int numRDMAlinksSymm, numRDMAlinksAsymm;
241  int itemp;
242  int jtemp;
243  bool initialized;
244  bool acceptedPsi;
245  bool allAcceptedVPsi;
246  bool doneNewIter;
247  bool acceptedLambda;
248  double ehart_total;
249  double enl_total;
250  double eke_total;
251  double fictEke_total;
252  double fmagPsi_total;
253  double fmagPsi_total_old;
254  double fmagPsi_total0;
255  double fovlap;
256  double fovlap_old;
257  double egga_total;
258  double eexc_total;
259  double eext_total;
260  double ewd_total;
261  double total_energy;
262  double cpuTimeNow;
263  int gSpaceNumPoints;
264  GStateSlab gs;
265  int *tk_x,*tk_y,*tk_z; // Temp memory for output (size could be 0)
266  complex *tpsi; // Temp memory for output (needs careful pup)
267  complex *tvpsi; // Temp memory for output
268  CProxy_CP_State_RealSpacePlane real_proxy;
269  CProxySection_PairCalculator *lambdaproxy;
270  CProxySection_PairCalculator *lambdaproxyother;
271  CProxySection_PairCalculator *psiproxy;
272  CProxySection_PairCalculator *psiproxyother;
273  /// Manages communication with the symmetric paircalc array
275  /// Manages communication with the asymmetric paircalc array
277  #ifdef _CP_GS_DEBUG_COMPARE_VKS_
278  complex *savedvksBf;
279  complex *savedforceBf;
280  #endif
281  #ifdef _CP_GS_DEBUG_COMPARE_PSI_
282  // place to keep data loaded from files for comparison
283  complex *savedpsiBfp;
284  complex *savedpsiBf;
285  complex *savedpsiAf;
286  complex *savedlambdaBf;
287  complex *savedlambdaAf;
288  #endif
289 #if USE_PERSISTENT
290  PersistentHandle *fftHandler;
291  void setupFFTPersistent();
292 #endif
293 };
294 /*@}*/
295 #endif // CP_STATE_GSPACE_PLANE_H
296 
297 
void pup(PUP::er &)
pup for migration /////////////////////////////////////////////////////////////////////////// ///////...
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
PCCommManager asymmPCmgr
Manages communication with the asymmetric paircalc array.
int istate_ind
My state index.
CProxy_Ortho myOrtho
A proxy for the my ortho chare array so I can interact with it.
2D chare array [nchareG][nstates] Handles the electronic structure in Fourier space (referred to as G...
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...
paircalc::CreationManager returns relevant chare array handles via this msg
int iplane_ind
My plane index.
Manages communication with a single paircalc array.
Definition: pcCommManager.h:31
A (hopefully) tiny token that is unique to every data sender-receiver pair, and is shared by them dur...
Definition: RDMAMessages.h:94
PCCommManager symmPCmgr
Manages communication with the symmetric paircalc array.
Useful debugging flags.
Reply from data receiver to the data sender indicating completion of setup on the receiver side...
int numRDMAlinksSymm
The number of symmetric and asymmetric PCs that communicate with me.