OpenAtom  Version1.5a
StructureFactor.C
Go to the documentation of this file.
1 /** \file StructureFactor.C
2  *
3  */
4 ///////////////////////////////////////////////////////////////////////////////=
5 
6 #include "utility/util.h"
7 #include "main/AtomsCache.h"
8 #include "main/energyGroup.h"
10 #include "StructureFactor.h"
11 #include "StructFactorCache.h"
12 #include "main/CPcharmParaInfoGrp.h"
13 #include "src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cpnonlocal.h"
14 #include "src_piny_physics_v1.0/include/class_defs/Interface_ctrl.h"
15 #include "main/PhysScratchCache.h"
16 
17 
18 ///////////////////////////////////////////////////////////////////////////////=
19 
20 extern CkVec <CProxy_StructureFactor> UsfCompProxy;
21 extern CkVec <CProxy_StructFactCache> UsfCacheProxy;
22 extern CkVec <CProxy_AtomsCache> UatomsCacheProxy;
23 extern CkVec <CProxy_EnergyGroup> UegroupProxy;
24 extern CProxy_PhysScratchCache pScratchProxy;
25 StructureFactor::StructureFactor(CkMigrateMessage *m){ }
26 
27 //#define _CP_DEBUG_SF_CALC_
28 
29 ///////////////////////////////////////////////////////////////////////////////=
30 
31 
32 ///////////////////////////////////////////////////////////////////////////////=
33 ///////////////////////////////////////////////////////////////////////////////c
34 ///////////////////////////////////////////////////////////////////////////////=
36 {
37  int iteration_src = msg->iteration_src;
38  delete msg; // prioritized trigger
39  CPcharmParaInfo *sim = CPcharmParaInfo::get();
40  if(sim->ees_nloc_on==1)
41  CkAbort("No structure factors under EES nonlocal\n");
42  // CkPrintf("[%d %d %d] compute %d\n",thisIndex.x,thisIndex.y,thisIndex.z,numdest);
43  // The guy who called us is up to date. Are we? The caller is one ahead
44  // of the energy dude and the atoms because it flipped its iteration counter
45  // at the top of the loop.
46  if(numdest){
47  if(UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch()->iteration !=
48  UegroupProxy[thisInstance.proxyOffset].ckLocalBranch()->iteration_gsp ||
49  UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch()->iteration != (iteration_src-1)){
50  CkPrintf("Flow of Control Warning in computeSF : atoms slow\n");
51  SFDummyMsg *newMsg = new(8*sizeof(int)) SFDummyMsg;
52  CkSetQueueing(newMsg, CK_QUEUEING_IFIFO);
53  *(int*)CkPriorityPtr(newMsg) = config.sfpriority;
54  newMsg->iteration_src = iteration_src;
55  UsfCompProxy[thisInstance.proxyOffset](thisIndex.x,thisIndex.y,thisIndex.z).computeSF(newMsg);
56  }//endif
57  }//endif
58 
59 ///////////////////////////////////////////////////////////////////////////////=
60  if(numdest){ //we have work to do
61  //----------------------------------------------------------------------------
62  // Manage memory and compute SF
63  CkAssert(gsSize>0);
64 #ifdef _CP_DEBUG_SF_CALC_
65  CkPrintf("[%d %d %d] compute\n",thisIndex.x,thisIndex.y,thisIndex.z);
66 #endif
67  // allow for clean slate
68  if(structFactor==NULL) {
69  structFactor = (complex *)fftw_malloc(natm_nl_grp_max*gsSize*sizeof(complex));
70  }//endif
71  if(structFactor_fx==NULL) {
72  structFactor_fx = (complex *)fftw_malloc(natm_nl_grp_max*gsSize*sizeof(complex));
73  structFactor_fy = (complex *)fftw_malloc(natm_nl_grp_max*gsSize*sizeof(complex));
74  structFactor_fz = (complex *)fftw_malloc(natm_nl_grp_max*gsSize*sizeof(complex));
75  }//endif
76  AtomsCache *ag = UatomsCacheProxy[thisInstance.proxyOffset].ckLocalBranch(); // find me the local copy
77  FastAtoms *fastAtoms = &(ag->fastAtoms);
78  CPNONLOCAL::CP_calc_Struct_Fact(gsSize,k_x, k_y,k_z,
79  structFactor,structFactor_fx,structFactor_fy,
80  structFactor_fz,fastAtoms, config.doublePack,
81  numSfGrps,thisIndex.x, pScratchProxy.ckLocalBranch()->psscratch);
82  //----------------------------------------------------------------------------
83  // Communicate the results
84  int totalsize=gsSize*natm_nl_grp_max;
85  for(int i=0;i<numdest;i++){
86  // create message
87 #ifdef _CP_DEBUG_SF_CALC_
88  CkPrintf("[%d %d %d] sending %d to %d\n",thisIndex.x,thisIndex.y,thisIndex.z,i,destinations[i]);
89 #endif
90  StructFactorMsg *msg = new (totalsize, totalsize, totalsize, totalsize, 8*sizeof(int)) StructFactorMsg;
91  CkSetQueueing(msg, CK_QUEUEING_IFIFO);
92  *(int*)CkPriorityPtr(msg) = config.sfpriority+thisIndex.x;
93  msg->datalen = totalsize;
94  msg->gsSize=gsSize;
95  msg->atmGrpIndex = thisIndex.x;
96  msg->planeIndex=thisIndex.y;
97  CmiMemcpy(msg->structFactor,structFactor,totalsize*sizeof(complex));
98  CmiMemcpy(msg->structFactor_fx,structFactor_fx,totalsize*sizeof(complex));
99  CmiMemcpy(msg->structFactor_fy,structFactor_fy,totalsize*sizeof(complex));
100  CmiMemcpy(msg->structFactor_fz,structFactor_fz,totalsize*sizeof(complex));
101  // send message
102  UsfCacheProxy[thisInstance.proxyOffset][destinations[i]].acceptStructFact(msg);
103  }//endfor
104 ///////////////////////////////////////////////////////////////////////////////=
105 /// no work to do
106  }else{
107 #ifdef _CP_DEBUG_SF_CALC_
108  CkPrintf("[%d %d %d] redundant\n",thisIndex.x,thisIndex.y,thisIndex.z);
109 #endif
110  }//endif
111 
112 ///////////////////////////////////////////////////////////////////////////////=
113  }//end routine
114 ///////////////////////////////////////////////////////////////////////////////=
115 
116 #include "structureFactor.def.h"
void computeSF(SFDummyMsg *msg)
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...