00001
00007 #include "InfoStream.h"
00008 #include "Patch.h"
00009 #include "PatchMap.h"
00010 #include "Compute.h"
00011
00012 #include "AtomMap.h"
00013 #include "ComputeMap.h"
00014 #include "Node.h"
00015 #include "Molecule.h"
00016 #include "SimParameters.h"
00017 #include "ResizeArrayPrimIter.h"
00018
00019 #include "Sync.h"
00020
00021 typedef ResizeArrayPrimIter<Compute*> ComputePtrListIter;
00022
00023
00024
00025 #define MIN_DEBUG_LEVEL 4
00026 #include "Debug.h"
00027
00028 Patch::~Patch() {
00029 delete atomMapper;
00030 }
00031
00032 Patch::Patch(PatchID pd) :
00033 lattice(flags.lattice),
00034 patchID(pd), numAtoms(0), numFixedAtoms(0),
00035 avgPositionPtrBegin(0), avgPositionPtrEnd(0),
00036 velocityPtrBegin(0), velocityPtrEnd(0),
00037 positionBox(this,&Patch::positionBoxClosed,pd,0),
00038 avgPositionBox(this,&Patch::avgPositionBoxClosed,pd,3),
00039 velocityBox(this,&Patch::velocityBoxClosed,pd,4),
00040 psiSumBox(this,&Patch::psiSumBoxClosed,pd,5),
00041 intRadBox(this,&Patch::intRadBoxClosed,pd,6),
00042 bornRadBox(this,&Patch::bornRadBoxClosed,pd,7),
00043 dEdaSumBox(this,&Patch::dEdaSumBoxClosed,pd,8),
00044 dHdrPrefixBox(this,&Patch::dHdrPrefixBoxClosed,pd,9),
00045 lcpoTypeBox(this,&Patch::lcpoTypeBoxClosed,pd,10),
00046 forceBox(this,&Patch::forceBoxClosed,pd,1),
00047 boxesOpen(0), _hasNewAtoms(0)
00048
00049
00050 #if NAMD_SeparateWaters != 0
00051 ,numWaterAtoms(-1)
00052 #endif
00053 {
00054
00055 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00056 positionPtrBegin = 0;
00057 positionPtrEnd = 0;
00058 #endif
00059
00060 nChild = 0;
00061 child = NULL;
00062 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00063 #ifdef USE_NODEPATCHMGR
00064 nodeChildren = NULL;
00065 numNodeChild = 0;
00066 #endif
00067 #endif
00068
00069 lattice = Node::Object()->simParameters->lattice;
00070 atomMapper = new AtomMapper(pd);
00071 }
00072
00073 Box<Patch,CompAtom>* Patch::registerPositionPickup(Compute *cid)
00074 {
00075
00076 if (positionComputeList.add(cid) < 0)
00077 {
00078 DebugM(7, "registerPositionPickup() failed for cid " << cid->cid << std::endl);
00079 return NULL;
00080 }
00081 return positionBox.checkOut(cid->cid);
00082 }
00083
00084 void Patch::unregisterPositionPickup(Compute *cid, Box<Patch,CompAtom> **const box)
00085 {
00086 DebugM(4, "UnregisterPositionPickup from " << cid->cid << "\n");
00087 positionComputeList.del(cid);
00088 positionBox.checkIn(*box);
00089 *box = 0;
00090 }
00091
00092 Box<Patch,CompAtom>* Patch::registerAvgPositionPickup(Compute *cid)
00093 {
00094
00095 return avgPositionBox.checkOut(cid->cid);
00096 }
00097
00098 void Patch::unregisterAvgPositionPickup(Compute *cid, Box<Patch,CompAtom> **const box)
00099 {
00100 DebugM(4, "UnregisterAvgPositionPickup from " << cid->cid << "\n");
00101 avgPositionBox.checkIn(*box);
00102 *box = 0;
00103 }
00104
00105
00106 Box<Patch,CompAtom>* Patch::registerVelocityPickup(Compute *cid)
00107 {
00108
00109 return velocityBox.checkOut(cid->cid);
00110 }
00111
00112 void Patch::unregisterVelocityPickup(Compute *cid, Box<Patch,CompAtom> **const box)
00113 {
00114 DebugM(4, "UnregisterVelocityPickup from " << cid->cid << "\n");
00115 velocityBox.checkIn(*box);
00116 *box = 0;
00117 }
00118
00119
00120
00121
00122 Box<Patch,GBReal>* Patch::registerPsiSumDeposit(Compute *cid) {
00123
00124 if (psiSumComputeList.add(cid) < 0) {
00125 DebugM(7, "registerPsiSumDeposit() failed for cid " << cid->cid << std::endl);
00126 DebugM(7, " size of psiSumCompueList " << psiSumComputeList.size() << std::endl);
00127 return NULL;
00128 }
00129 return psiSumBox.checkOut(cid->cid);
00130 }
00131
00132 void Patch::unregisterPsiSumDeposit(Compute *cid,Box<Patch,GBReal> **const box) {
00133 psiSumComputeList.del(cid);
00134 psiSumBox.checkIn(*box);
00135 *box = 0;
00136 }
00137 Box<Patch,Real>* Patch::registerIntRadPickup(Compute *cid) {
00138 return intRadBox.checkOut(cid->cid);
00139 }
00140 void Patch::unregisterIntRadPickup(Compute *cid,Box<Patch,Real> **const box) {
00141 intRadBox.checkIn(*box);
00142 *box = 0;
00143 }
00144
00145
00146 Box<Patch,int>* Patch::registerLcpoTypePickup(Compute *cid) {
00147 return lcpoTypeBox.checkOut(cid->cid);
00148 }
00149 void Patch::unregisterLcpoTypePickup(Compute *cid,Box<Patch,int> **const box) {
00150 lcpoTypeBox.checkIn(*box);
00151 *box = 0;
00152 }
00153
00154 Box<Patch,Real>* Patch::registerBornRadPickup(Compute *cid) {
00155 return bornRadBox.checkOut(cid->cid);
00156 }
00157 void Patch::unregisterBornRadPickup(Compute *cid,Box<Patch,Real> **const box) {
00158 bornRadBox.checkIn(*box);
00159 *box = 0;
00160 }
00161
00162 Box<Patch,GBReal>* Patch::registerDEdaSumDeposit(Compute *cid) {
00163 if (dEdaSumComputeList.add(cid) < 0) {
00164 DebugM(7, "registerDEdaSumDeposit() failed for cid " << cid->cid << std::endl);
00165 DebugM(7, " size of dEdaSumCompueList " << dEdaSumComputeList.size() << std::endl);
00166 return NULL;
00167 }
00168 return dEdaSumBox.checkOut(cid->cid);
00169 }
00170 void Patch::unregisterDEdaSumDeposit(Compute *cid,Box<Patch,GBReal> **const box){
00171 dEdaSumComputeList.del(cid);
00172 dEdaSumBox.checkIn(*box);
00173 *box = 0;
00174 }
00175
00176 Box<Patch,Real>* Patch::registerDHdrPrefixPickup(Compute *cid)
00177 {
00178 return dHdrPrefixBox.checkOut(cid->cid);
00179 }
00180 void Patch::unregisterDHdrPrefixPickup(Compute *cid,Box<Patch,Real> **const box) {
00181 dHdrPrefixBox.checkIn(*box);
00182 *box = 0;
00183 }
00184
00185
00186 Box<Patch,Results>* Patch::registerForceDeposit(Compute *cid)
00187 {
00188 if (forceComputeList.add(cid) < 0)
00189 {
00190 DebugM(7, "registerForceDeposit() failed for cid " << cid->cid << std::endl);
00191 DebugM(7, " size of forceCompueList " << forceComputeList.size() << std::endl);
00192 return NULL;
00193 }
00194 return forceBox.checkOut(cid->cid);
00195 }
00196
00197 void Patch::unregisterForceDeposit(Compute *cid, Box<Patch,Results> **const box)
00198 {
00199 DebugM(4, "unregisterForceDeposit() computeID("<<cid<<")"<<std::endl);
00200 forceComputeList.del(cid);
00201 forceBox.checkIn(*box);
00202 *box = 0;
00203 }
00204
00205 void Patch::positionBoxClosed(void)
00206 {
00207
00208 this->boxClosed(0);
00209 }
00210
00211 void Patch::forceBoxClosed(void)
00212 {
00213 DebugM(4, "patchID("<<patchID<<") forceBoxClosed! call\n");
00214 for (int j = 0; j < Results::maxNumForces; ++j )
00215 {
00216 results.f[j] = 0;
00217 }
00218 this->boxClosed(1);
00219 }
00220
00221 void Patch::avgPositionBoxClosed(void)
00222 {
00223 avgPositionPtrBegin = 0;
00224 this->boxClosed(3);
00225 }
00226
00227
00228 void Patch::velocityBoxClosed(void)
00229 {
00230 DebugM(4, "patchID("<<patchID<<") velocityBoxClosed! call\n");
00231 velocityPtrBegin = 0;
00232 this->boxClosed(4);
00233 }
00234
00235
00236
00237
00238
00239 void Patch::psiSumBoxClosed(void) {
00240 this->boxClosed(5);
00241 }
00242 void Patch::intRadBoxClosed(void) {
00243
00244 this->boxClosed(6);
00245 }
00246 void Patch::bornRadBoxClosed(void) {
00247
00248 this->boxClosed(7);
00249 }
00250 void Patch::dEdaSumBoxClosed(void) {
00251
00252 this->boxClosed(8);
00253 }
00254 void Patch::dHdrPrefixBoxClosed(void) {
00255
00256 this->boxClosed(9);
00257 }
00258
00259
00260
00261 void Patch::lcpoTypeBoxClosed(void) {
00262 this->boxClosed(10);
00263 }
00264
00265 void Patch::positionsReady(int doneMigration)
00266 {
00267 DebugM(4,"Patch::positionsReady() - patchID(" << patchID <<")"<<std::endl );
00268
00269 if ( doneMigration ){
00270
00271
00272
00273 atomMapper->registerIDsCompAtomExt(pExt.begin(),pExt.end());
00274
00275
00276 }
00277
00278 boxesOpen = 2;
00279 if ( flags.doMolly ) boxesOpen++;
00280
00281 if (flags.doLoweAndersen) {
00282 DebugM(4, "Patch::positionsReady, flags.doMolly = " << flags.doMolly << "\n");
00283 boxesOpen++;
00284 }
00285
00286 _hasNewAtoms = (doneMigration != 0);
00287
00288 #if CMK_BLUEGENEL
00289 CmiNetworkProgressAfter (0);
00290 #endif
00291
00292
00293
00294 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00295 positionBox.open(positionPtrBegin);
00296 #else
00297 positionBox.open(p.begin());
00298 #endif
00299 if ( flags.doMolly ) {
00300
00301 avgPositionBox.open(avgPositionPtrBegin);
00302 }
00303
00304
00305 if (flags.doLoweAndersen) {
00306 velocityBox.open(velocityPtrBegin);
00307 }
00308
00309
00310 if (flags.doGBIS) {
00311 boxesOpen += 5;
00312
00313 intRadBox.open(intRad.begin());
00314 psiSum.resize(numAtoms);
00315 psiSum.setall(0);
00316 psiSumBox.open(psiSum.begin());
00317 psiFin.resize(numAtoms);
00318 psiFin.setall(0);
00319 bornRad.resize(numAtoms);
00320 bornRad.setall(0);
00321 bornRadBox.open(bornRad.begin());
00322 dEdaSum.resize(numAtoms);
00323 dEdaSum.setall(0);
00324 dEdaSumBox.open(dEdaSum.begin());
00325 dHdrPrefix.resize(numAtoms);
00326 dHdrPrefix.setall(0);
00327 dHdrPrefixBox.open(dHdrPrefix.begin());
00328 }
00329
00330
00331
00332 if (flags.doLCPO) {
00333 boxesOpen++;
00334 lcpoTypeBox.open(lcpoType.begin());
00335 }
00336
00337 #if CMK_BLUEGENEL
00338 CmiNetworkProgressAfter (0);
00339 #endif
00340
00341
00342 Force *forcePtr;
00343 for ( int j = 0; j < Results::maxNumForces; ++j )
00344 {
00345 f[j].resize(numAtoms);
00346 forcePtr = f[j].begin();
00347 memset (forcePtr, 0, sizeof (Force) * numAtoms);
00348 results.f[j] = forcePtr;
00349 }
00350 forceBox.open(&results);
00351
00352
00353 ComputePtrListIter cid(positionComputeList);
00354 int seq = flags.sequence;
00355
00356 if (Sync::Object()->holdComputes(patchID, cid, doneMigration, seq))
00357 return;
00358
00359 int compute_count = 0;
00360 for(cid = cid.begin(); cid != cid.end(); cid++)
00361 {
00362 compute_count++;
00363 (*cid)->patchReady(patchID,doneMigration,seq);
00364 }
00365 if (compute_count == 0 && PatchMap::Object()->node(patchID) != CkMyPe()) {
00366 iout << iINFO << "PATCH_COUNT: Patch " << patchID
00367 << " on PE " << CkMyPe() <<" home patch "
00368 << PatchMap::Object()->node(patchID)
00369 << " does not have any computes\n"
00370 << endi;
00371 }
00372 }
00373
00374
00375
00376 void Patch::gbisP2Ready() {
00377 ComputePtrListIter cid(positionComputeList);
00378
00379 int compute_count = 0;
00380 int seq = flags.sequence;
00381 for(cid = cid.begin(); cid != cid.end(); cid++) {
00382 if ( (*cid)->type() == computeNonbondedSelfType ||
00383 (*cid)->type() == computeNonbondedPairType ||
00384 (*cid)->type() == computeNonbondedCUDAType) {
00385 compute_count++;
00386 (*cid)->gbisP2PatchReady(patchID,seq);
00387 }
00388 }
00389 }
00390
00391 void Patch::gbisP3Ready() {
00392
00393 ComputePtrListIter cid(positionComputeList);
00394
00395 int compute_count = 0;
00396 int seq = flags.sequence;
00397 for(cid = cid.begin(); cid != cid.end(); cid++) {
00398 if ( (*cid)->type() == computeNonbondedSelfType ||
00399 (*cid)->type() == computeNonbondedPairType ||
00400 (*cid)->type() == computeNonbondedCUDAType) {
00401 compute_count++;
00402 (*cid)->gbisP3PatchReady(patchID,seq);
00403 }
00404 }
00405 }
00406
00407