10 #include "StructFactorCache.h"
11 #include "gParticlePlane.decl.h"
12 #include "src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cpnonlocal.h"
13 extern CkVec <CProxy_CP_State_ParticlePlane> UparticlePlaneProxy;
19 int StructFactCache::existStructFact(
int planeIndex) {
20 for(
int i=0; i<planeCountList.length(); i++){
22 if(thisCount.plane == planeIndex) {
26 #ifdef _CP_DEBUG_SF_CACHE_
27 CkPrintf(
"[%d] lacks plane %d\n",CkMyPe(),planeIndex);
37 int StructFactCache::existStructFactGrp(
int planeIndex,
int atmGrp) {
38 for(
int i=0; i<planeCountList.length(); i++){
40 if(thisCount.plane == planeIndex) {
41 if(structFactorAtmGrps[i][atmGrp]==1)
43 #ifdef _CP_DEBUG_SF_CACHE_
44 CkPrintf(
"[%d] has plane %d atom %d\n",CkMyPe(),planeIndex,atmGrp);
50 #ifdef _CP_DEBUG_SF_CACHE_
51 CkPrintf(
"[%d] lacks plane %d atom %d\n",CkMyPe(),planeIndex,atmGrp);
61 int StructFactCache::incCountStructFact(
int planeIndex) {
63 for(
int i=0; i<planeCountList.length(); i++){
65 if(thisCount->plane == planeIndex) {
67 return thisCount->count;
71 planeCountList.insert(planeCountList.length(),
PlaneCount(planeIndex, 1, 1));
80 int StructFactCache::decCountStructFact(
int planeIndex) {
81 for(
int i=0; i<planeCountList.length(); i++){
83 if(thisCount->plane == planeIndex) {
85 if(thisCount->count < 0) {
87 CkPrintf(
"Over Decrementing counters!!!\n");
89 return thisCount->count;
92 CkPrintf(
"Trying to Decrement non-existing counters!!!\n");
101 void StructFactCache::printCountStructFact() {
102 CkPrintf(
"/////////////////////////////////////\n");
103 for(
int i=0; i<planeCountList.length(); i++){
105 CkPrintf(
" plane -- %d, count -- %d\n", thisCount.plane, thisCount.count);
107 CkPrintf(
"/////////////////////////////////////\n");
115 void StructFactCache::setZero(
int planeIndex) {
116 int i = existStructFact(planeIndex);
119 #ifdef _CP_DEBUG_SF_CACHE_
120 CkPrintf(
"[%d] zeros plane %d\n",CkMyPe(),planeIndex);
122 planeCountList[i].updated = 0;
123 for(
int j=0;j<numSfGrps;j++)
124 structFactorAtmGrps[i][j]=0;
134 int StructFactCache::getStructFact(
int planeIndex,
int atmGrpIndex,
complex** sf,
136 int i = existStructFact(planeIndex);
138 int arroffset=structFactorSize[i]*atmGrpIndex*natm_nl_grp_max;
139 *sf = structFactorList[i]+arroffset;
140 *sf_x = structFactorfxList[i]+arroffset;
141 *sf_y = structFactorfyList[i]+arroffset;
142 *sf_z = structFactorfzList[i]+arroffset;
150 void StructFactCache::getStructFactIdx(
int sfindex,
int atmGrpIndex,
complex** sf,
152 int arroffset=structFactorSize[sfindex]*atmGrpIndex*natm_nl_grp_max;
153 *sf = structFactorList[sfindex]+arroffset;
154 *sf_x = structFactorfxList[sfindex]+arroffset;
155 *sf_y = structFactorfyList[sfindex]+arroffset;
156 *sf_z = structFactorfzList[sfindex]+arroffset;
165 int atmIndex=msg->atmGrpIndex;
166 int planeIndex=msg->planeIndex;
167 int arroffset=msg->gsSize*atmIndex*natm_nl_grp_max;
168 int sfindex=existStructFact(planeIndex);
169 #ifdef _CP_DEBUG_SF_CACHE_
170 CkPrintf(
"[%d] received SF for plane %d atom %d\n",CkMyPe(),planeIndex, atmIndex);
176 incCountStructFact(planeIndex);
177 int structSize=msg->gsSize*numSfGrps*natm_nl_grp_max;
182 int *atmGrpArrive =
new int[numSfGrps];
183 bzero(atmGrpArrive, numSfGrps*
sizeof(
int));
184 structFactorAtmGrps.insert(structFactorAtmGrps.length(),atmGrpArrive);
185 structFactorList.insert(structFactorList.length(),structFactor);
186 structFactorfxList.insert(structFactorfxList.length(), structFactor_fx);
187 structFactorfyList.insert(structFactorfyList.length(), structFactor_fy);
188 structFactorfzList.insert(structFactorfzList.length(), structFactor_fz);
189 structFactorSize.insert(structFactorSize.length(), msg->gsSize);
191 sfindex=existStructFact(planeIndex);
192 #ifdef _CP_DEBUG_SF_CACHE_
193 CkPrintf(
"[%d] created SF entry %d for plane %d atom %d\n",CkMyPe(),sfindex, planeIndex, atmIndex);
196 CkAssert(sfindex>=0);
197 planeCountList[sfindex].updated = 1;
198 structFactorAtmGrps[sfindex][atmIndex] = 1;
199 CmiMemcpy(structFactorList[sfindex]+arroffset,msg->structFactor,msg->datalen*
sizeof(
complex));
200 CmiMemcpy(structFactorfxList[sfindex]+arroffset,msg->structFactor_fx,msg->datalen*
sizeof(
complex));
201 CmiMemcpy(structFactorfyList[sfindex]+arroffset,msg->structFactor_fy,msg->datalen*
sizeof(
complex));
202 CmiMemcpy(structFactorfzList[sfindex]+arroffset,msg->structFactor_fz,msg->datalen*
sizeof(
complex));
206 if((ppregindex=existsPP(planeIndex,atmIndex))>=0)
209 CkArrayIndex2D idx2d;
210 for(
int i=0;i<regPPs.particles.length();i++)
221 idx2d=regPPs.particles[i];
224 pmsg->atmGrp=atmIndex;
225 pmsg->sfindex=sfindex;
226 CkSetQueueing(pmsg, CK_QUEUEING_IFIFO);
227 *(
int*)CkPriorityPtr(pmsg) = config.sfpriority+atmIndex+numSfGrps;
228 UparticlePlaneProxy[thisInstance.proxyOffset](idx2d.index[0], idx2d.index[1]).computeZ(pmsg);
235 snprintf(out, 100,
"[%d] accepted SF for %d %d without any registered particles",CkMyPe(), planeIndex, atmIndex);
251 CkArrayIndex2D idx2d(state,plane);
252 for(
int i=0; i<ppList.length(); i++){
255 ppList[i].particles.push_back(idx2d);
256 #ifdef _CP_DEBUG_SF_CACHE_
257 CkPrintf(
"[%d] registers PP[%d,%d] atom %d at %d\n",CkMyPe(),state,plane,atom, ppList[i].particles.length()-1);
263 ppList.push_back(pa);
264 ppList[ppList.length()-1].particles.push_back(idx2d);
265 #ifdef _CP_DEBUG_SF_CACHE_
266 CkPrintf(
"SFC [%d] registers PP[%d,%d] atom %d at %d\n",CkMyPe(),state,plane,atom,ppList[ppList.length()-1].particles.length()-1);
268 return ppList.length()-1;
272 int StructFactCache::existsPP(
int plane,
int atom) {
275 for(
int i=0; i<ppList.length(); i++)
284 void StructFactCache::removeAll() {
286 for(
int i=structFactorList.length()-1; i>=0; i--){
287 fftw_free(structFactorList[i]);
288 fftw_free(structFactorfxList[i]);
289 fftw_free(structFactorfyList[i]);
290 fftw_free(structFactorfzList[i]);
291 delete []structFactorAtmGrps[i];
294 structFactorList.removeAll();
295 structFactorfxList.removeAll();
296 structFactorfyList.removeAll();
297 structFactorfzList.removeAll();
298 structFactorSize.removeAll();
299 gSpaceSlabs.removeAll();
303 #include "structureFactorCache.def.h"
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...
int registerPP(int state, int plane, int atmGrp)
local particle planes register themselves with the cache so they can be launched by the arrival of an...