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<ComputeID> ComputeIDListIter;
00022
00023
00024 #define MIN_DEBUG_LEVEL 4
00025 #include "Debug.h"
00026
00027 Patch::Patch(PatchID pd) :
00028 lattice(flags.lattice),
00029 patchID(pd), numAtoms(0), numFixedAtoms(0),
00030 avgPositionPtrBegin(0), avgPositionPtrEnd(0),
00031 positionBox(this,&Patch::positionBoxClosed),
00032 avgPositionBox(this,&Patch::avgPositionBoxClosed),
00033 forceBox(this,&Patch::forceBoxClosed),
00034 boxesOpen(0), _hasNewAtoms(0)
00035
00036
00037 #if NAMD_SeparateWaters != 0
00038 ,numWaterAtoms(-1)
00039 #endif
00040 {
00041 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00042 positionPtrBegin = 0;
00043 positionPtrEnd = 0;
00044 #endif
00045
00046 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00047 numChild = 0;
00048 children = NULL;
00049 #ifdef USE_NODEPATCHMGR
00050 nodeChildren = NULL;
00051 numNodeChild = 0;
00052 #endif
00053 #endif
00054
00055 lattice = Node::Object()->simParameters->lattice;
00056 }
00057
00058 Box<Patch,CompAtom>* Patch::registerPositionPickup(ComputeID cid, int trans)
00059 {
00060
00061 if (positionComputeList.add(cid) < 0)
00062 {
00063 DebugM(7, "registerPositionPickup() failed for cid " << cid << std::endl);
00064 return NULL;
00065 }
00066 return positionBox.checkOut();
00067 }
00068
00069 void Patch::unregisterPositionPickup(ComputeID cid, Box<Patch,CompAtom> **const box)
00070 {
00071 DebugM(4, "UnregisterPositionPickup from " << cid << "\n");
00072 positionComputeList.del(cid);
00073 positionBox.checkIn(*box);
00074 *box = 0;
00075 }
00076
00077 Box<Patch,CompAtom>* Patch::registerAvgPositionPickup(ComputeID cid, int trans)
00078 {
00079
00080 return avgPositionBox.checkOut();
00081 }
00082
00083 void Patch::unregisterAvgPositionPickup(ComputeID cid, Box<Patch,CompAtom> **const box)
00084 {
00085 DebugM(4, "UnregisterAvgPositionPickup from " << cid << "\n");
00086 avgPositionBox.checkIn(*box);
00087 *box = 0;
00088 }
00089
00090 Box<Patch,Results>* Patch::registerForceDeposit(ComputeID cid)
00091 {
00092 if (forceComputeList.add(cid) < 0)
00093 {
00094 DebugM(7, "registerForceDeposit() failed for cid " << cid << std::endl);
00095 DebugM(7, " size of forceCompueList " << forceComputeList.size() << std::endl);
00096 return NULL;
00097 }
00098 return forceBox.checkOut();
00099 }
00100
00101 void Patch::unregisterForceDeposit(ComputeID cid, Box<Patch,Results> **const box)
00102 {
00103 DebugM(4, "unregisterForceDeposit() computeID("<<cid<<")"<<std::endl);
00104 forceComputeList.del(cid);
00105 forceBox.checkIn(*box);
00106 *box = 0;
00107 }
00108
00109 void Patch::positionBoxClosed(void)
00110 {
00111
00112 this->boxClosed(0);
00113 }
00114
00115 void Patch::forceBoxClosed(void)
00116 {
00117 DebugM(4, "patchID("<<patchID<<") forceBoxClosed! call\n");
00118 for (int j = 0; j < Results::maxNumForces; ++j )
00119 {
00120 results.f[j] = 0;
00121 }
00122 this->boxClosed(1);
00123 }
00124
00125 void Patch::avgPositionBoxClosed(void)
00126 {
00127 avgPositionPtrBegin = 0;
00128 this->boxClosed(3);
00129 }
00130
00131
00132
00133 void Patch::positionsReady(int doneMigration)
00134 {
00135 DebugM(4,"Patch::positionsReady() - patchID(" << patchID <<")"<<std::endl );
00136 ComputeMap *computeMap = ComputeMap::Object();
00137
00138 if ( doneMigration ){
00139
00140
00141
00142 AtomMap::Object()->registerIDs(patchID,pExt.begin(),pExt.end());
00143
00144 }
00145
00146 boxesOpen = 2;
00147 if ( flags.doMolly ) boxesOpen++;
00148 _hasNewAtoms = (doneMigration != 0);
00149
00150 #if CMK_BLUEGENEL
00151 CmiNetworkProgressAfter (0);
00152 #endif
00153
00154
00155
00156 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00157 positionBox.open(positionPtrBegin);
00158 #else
00159 positionBox.open(p.begin());
00160 #endif
00161 if ( flags.doMolly ) {
00162
00163 avgPositionBox.open(avgPositionPtrBegin);
00164 }
00165
00166 #if CMK_BLUEGENEL
00167 CmiNetworkProgressAfter (0);
00168 #endif
00169
00170
00171 Force *forcePtr;
00172 for ( int j = 0; j < Results::maxNumForces; ++j )
00173 {
00174 f[j].resize(numAtoms);
00175 forcePtr = f[j].begin();
00176 memset (forcePtr, 0, sizeof (Force) * numAtoms);
00177 results.f[j] = forcePtr;
00178 }
00179 forceBox.open(&results);
00180
00181
00182 ComputeIDListIter cid(positionComputeList);
00183
00184 if (useSync) {
00185 if (Sync::Object()->holdComputes(patchID, cid, doneMigration))
00186 return;
00187 }
00188
00189 int compute_count = 0;
00190 int seq = flags.sequence;
00191 for(cid = cid.begin(); cid != cid.end(); cid++)
00192 {
00193 compute_count++;
00194 computeMap->compute(*cid)->patchReady(patchID,doneMigration,seq);
00195 }
00196 if (compute_count == 0 && PatchMap::Object()->node(patchID) != CkMyPe()) {
00197 iout << iINFO << "PATCH_COUNT: Patch " << patchID
00198 << " on PE " << CkMyPe() <<" home patch "
00199 << PatchMap::Object()->node(patchID)
00200 << " does not have any computes\n"
00201 << endi;
00202 }
00203 }
00204
00205