Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Patch.C

Go to the documentation of this file.
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 //#define  DEBUGM
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),      // BEGIN LA, END LA
00037    positionBox(this,&Patch::positionBoxClosed,pd,0),
00038    avgPositionBox(this,&Patch::avgPositionBoxClosed,pd,3),
00039    velocityBox(this,&Patch::velocityBoxClosed,pd,4), // BEGIN LA, END LA
00040    psiSumBox(this,&Patch::psiSumBoxClosed,pd,5), // begin gbis
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), //end gbis
00045    lcpoTypeBox(this,&Patch::lcpoTypeBoxClosed,pd,10),
00046    forceBox(this,&Patch::forceBoxClosed,pd,1),
00047    boxesOpen(0), _hasNewAtoms(0)
00048 
00049    // DMK - Atom Separation (water vs. non-water)
00050    #if NAMD_SeparateWaters != 0
00051      ,numWaterAtoms(-1)
00052    #endif
00053 {
00054   //CkPrintf("GBIS: PatchCreated\n");
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    //DebugM(4, "registerPositionPickupa("<<patchID<<") from " << cid->cid << "\n");
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    //DebugM(4, "registerAvgPositionPickup("<<patchID<<") from " << cid->cid << "\n");
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 // BEGIN LA
00106 Box<Patch,CompAtom>* Patch::registerVelocityPickup(Compute *cid)
00107 {
00108    //DebugM(4, "registerVelocityPickup("<<patchID<<") from " << cid->cid << "\n");
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 // END LA
00119 
00120 //begin gbis
00121 //deposit, not pickup
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 //LCPO
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 //end gbis
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    //positionPtrBegin = 0;
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 // BEGIN LA
00228 void Patch::velocityBoxClosed(void)
00229 {
00230    DebugM(4, "patchID("<<patchID<<") velocityBoxClosed! call\n");
00231    velocityPtrBegin = 0;
00232    this->boxClosed(4);  // ?? Don't know about number
00233 }
00234 // END LA
00235 
00236 // void Patch::boxClosed(int box) is virtual
00237 
00238 // begin gbis
00239 void Patch::psiSumBoxClosed(void) {
00240   this->boxClosed(5);
00241 }
00242 void Patch::intRadBoxClosed(void) {
00243    //dHdrPrefixPtr = 0;
00244    this->boxClosed(6);
00245 }
00246 void Patch::bornRadBoxClosed(void) {
00247    //bornRadPtr = 0;
00248    this->boxClosed(7);
00249 }
00250 void Patch::dEdaSumBoxClosed(void) {
00251    //dEdaSumPtr = 0;
00252    this->boxClosed(8);
00253 }
00254 void Patch::dHdrPrefixBoxClosed(void) {
00255    //dHdrPrefixPtr = 0;
00256    this->boxClosed(9);
00257 }
00258 // end gbis
00259 
00260 //LCPO
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 // #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00271 //       AtomMap::Object()->registerIDs(patchID,positionPtrBegin,positionPtrEnd);       
00272 // #else
00273        atomMapper->registerIDsCompAtomExt(pExt.begin(),pExt.end());
00274 // #endif
00275 
00276    }
00277 
00278    boxesOpen = 2;
00279    if ( flags.doMolly ) boxesOpen++;
00280    // BEGIN LA
00281    if (flags.doLoweAndersen) {
00282        DebugM(4, "Patch::positionsReady, flags.doMolly = " << flags.doMolly << "\n");
00283        boxesOpen++;
00284    }
00285    // END LA
00286    _hasNewAtoms = (doneMigration != 0);
00287 
00288 #if CMK_BLUEGENEL
00289    CmiNetworkProgressAfter (0);
00290 #endif
00291 
00292    // Give all position pickup boxes access to positions
00293    //positionPtrBegin = p.begin();
00294 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00295    positionBox.open(positionPtrBegin);
00296 #else
00297    positionBox.open(p.begin());
00298 #endif
00299    if ( flags.doMolly ) {
00300      //avgPositionPtrBegin = p_avg.begin();
00301      avgPositionBox.open(avgPositionPtrBegin);
00302    }
00303    
00304    // BEGIN LA
00305    if (flags.doLoweAndersen) {
00306        velocityBox.open(velocityPtrBegin);
00307    }
00308    // END LA
00309    // begin gbis
00310     if (flags.doGBIS) {
00311       boxesOpen += 5;
00312       //intRad should already be taken care of
00313       intRadBox.open(intRad.begin());
00314       psiSum.resize(numAtoms);//resize array
00315       psiSum.setall(0);
00316       psiSumBox.open(psiSum.begin());
00317       psiFin.resize(numAtoms);//has no box
00318       psiFin.setall(0);
00319       bornRad.resize(numAtoms);
00320       bornRad.setall(0);
00321       bornRadBox.open(bornRad.begin());
00322       dEdaSum.resize(numAtoms);//resize array
00323       dEdaSum.setall(0);
00324       dEdaSumBox.open(dEdaSum.begin());
00325       dHdrPrefix.resize(numAtoms);
00326       dHdrPrefix.setall(0);
00327       dHdrPrefixBox.open(dHdrPrefix.begin());
00328     }
00329    // end gbis
00330 
00331   //LCPO
00332   if (flags.doLCPO) {
00333     boxesOpen++;
00334     lcpoTypeBox.open(lcpoType.begin());
00335   }
00336 
00337 #if CMK_BLUEGENEL
00338    CmiNetworkProgressAfter (0);
00339 #endif
00340    
00341    // Give all force deposit boxes access to forces
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    // Iterate over compute objects that need to be informed we are ready
00353    ComputePtrListIter cid(positionComputeList);
00354    int seq = flags.sequence;
00355    // gzheng
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 // begin gbis
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 //end gbis

Generated on Fri May 25 04:07:16 2012 for NAMD by  doxygen 1.3.9.1