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

ProxyPatch Class Reference

#include <ProxyPatch.h>

Inheritance diagram for ProxyPatch:

Patch List of all members.

Public Member Functions

 ProxyPatch (PatchID pd)
virtual ~ProxyPatch (void)
void receiveAtoms (ProxyAtomsMsg *)
void receiveData (ProxyDataMsg *)
void receiveAll (ProxyDataMsg *)
void setSpanningTree (int, int *, int)
int getSpanningTreeParent ()
int getSpanningTreeChild (int *)
int getSpanningTreeNChild (void)
ProxyCombinedResultMsgdepositCombinedResultMsg (ProxyCombinedResultMsg *)

Protected Member Functions

virtual void boxClosed (int)

Constructor & Destructor Documentation

ProxyPatch::ProxyPatch PatchID  pd  ) 
 

Definition at line 27 of file ProxyPatch.C.

References DebugM, ProxyMgr::Object(), PROXYMSGNOTBUFFERED, and ProxyMgr::registerProxy().

00027                                  : 
00028   Patch(pd), proxyMsgBufferStatus(PROXYMSGNOTBUFFERED), 
00029   curProxyMsg(NULL), prevProxyMsg(NULL)
00030 {
00031   DebugM(4, "ProxyPatch(" << pd << ") at " << this << "\n");
00032   ProxyMgr::Object()->registerProxy(patchID);
00033   numAtoms = -1;
00034   parent = -1;
00035 
00036 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00037   /*numChild = 0;
00038   children = NULL;*/
00039 #else
00040   nChild = 0;
00041   child = new int[proxySpanDim];
00042 #endif
00043 
00044 #if CMK_PERSISTENT_COMM
00045   localphs = 0;
00046   localphs = CmiCreatePersistent(PatchMap::Object()->node(patchID), 300000);
00047 #endif
00048 
00049   // DMK - Atom Separation (water vs. non-water)
00050   #if NAMD_SeparateWaters != 0
00051     numWaterAtoms = -1;
00052   #endif
00053   
00054   #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
00055     depositLock = CmiCreateLock();
00056   #endif
00057 }

ProxyPatch::~ProxyPatch void   )  [virtual]
 

Definition at line 59 of file ProxyPatch.C.

References ResizeArray< Elem >::begin(), DebugM, ResizeArray< Elem >::end(), AtomMap::Object(), ProxyMgr::Object(), ResizeArray< Elem >::resize(), AtomMap::unregisterIDs(), and ProxyMgr::unregisterProxy().

00060 {
00061   DebugM(4, "ProxyPatch(" << patchID << ") deleted at " << this << "\n");
00062   ProxyMgr::Object()->unregisterProxy(patchID);
00063 
00064   // ProxyPatch may be freed because of load balancing if the compute object
00065   // it corresponds to no longer exist on this specific processor.
00066   CmiAssert(prevProxyMsg!=NULL);
00067   if(prevProxyMsg!=NULL) {
00068 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00069       AtomMap::Object()->unregisterIDs(patchID,positionPtrBegin, positionPtrEnd);
00070 #else
00071       AtomMap::Object()->unregisterIDs(patchID,p.begin(),p.end());
00072 #endif      
00073       delete prevProxyMsg;
00074       prevProxyMsg = NULL;
00075   }
00076 
00077 
00078 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00079   delete [] children;
00080   #ifdef USE_NODEPATCHMGR
00081   delete [] nodeChildren;  
00082   #endif
00083 #else
00084   delete [] child;
00085 #endif
00086 
00087   p.resize(0);
00088 
00089 #ifdef MEM_OPT_VERSION
00090   pExt.resize(0);
00091 #endif
00092 
00093 #if CMK_PERSISTENT_COMM
00094   CmiDestoryPersistent(localphs);
00095   localphs = 0;
00096 #endif
00097 }


Member Function Documentation

void ProxyPatch::boxClosed int   )  [protected, virtual]
 

Implements Patch.

Definition at line 99 of file ProxyPatch.C.

References DebugM, receiveAll(), and receiveData().

00100 {
00101   if ( box == 1 ) {     
00102     // Note: delay the deletion of proxyDataMsg (of the 
00103     // current step) until the next step. This is done 
00104     // for the sake of atom migration (ProxyDataMsg) 
00105     // as the ProxyPatch has to  unregister the atoms 
00106     // of the previous step in the AtomMap data structure. 
00107     sendResults();
00108   }
00109   if ( ! --boxesOpen ) {
00110     DebugM(2,patchID << ": " << "Checking message buffer.\n");    
00111     
00112     if(proxyMsgBufferStatus == PROXYALLMSGBUFFERED) {
00113           CmiAssert(curProxyMsg != NULL);
00114           DebugM(3,"Patch " << patchID << " processing buffered proxy ALL data.\n");
00115           receiveAll(curProxyMsg);          
00116     }else if(proxyMsgBufferStatus == PROXYDATAMSGBUFFERED) {
00117           CmiAssert(curProxyMsg != NULL);
00118           DebugM(3,"Patch " << patchID << " processing buffered proxy data.\n");
00119           receiveData(curProxyMsg);
00120     }
00121   } else {
00122        DebugM(3,"ProxyPatch " << patchID << ": " << boxesOpen << " boxes left to close.\n");
00123   }
00124 }

ProxyCombinedResultMsg * ProxyPatch::depositCombinedResultMsg ProxyCombinedResultMsg  ) 
 

Definition at line 358 of file ProxyPatch.C.

References ResizeArray< Elem >::add(), ResizeArray< Elem >::begin(), ResizeArray< Elem >::end(), ProxyCombinedResultMsg::forceList, and ProxyCombinedResultMsg::nodes.

Referenced by NodeProxyMgr::recvImmediateResults(), ProxyMgr::recvImmediateResults(), and ProxyMgr::sendResults().

00358                                                                                         {
00359 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
00360   CmiLock(depositLock);
00361 #endif
00362   nWait++;
00363   if (nWait == 1) msgCBuffer = msg;
00364   else {
00365     NodeIDList::iterator n_i, n_e;
00366     n_i = msg->nodes.begin();
00367     n_e = msg->nodes.end();
00368     for (; n_i!=n_e; ++n_i) msgCBuffer->nodes.add(*n_i);
00369     for ( int k = 0; k < Results::maxNumForces; ++k )
00370     {
00371     register ForceList::iterator r_i;
00372     r_i = msgCBuffer->forceList[k].begin();
00373     register ForceList::iterator f_i, f_e;
00374     f_i = msg->forceList[k].begin();
00375     f_e = msg->forceList[k].end();
00376     //    for ( ; f_i != f_e; ++f_i, ++r_i ) *r_i += *f_i;
00377 
00378     int nf = f_e - f_i;
00379 #ifdef ARCH_POWERPC
00380 #pragma disjoint (*f_i, *r_i)
00381 #pragma unroll(4)
00382 #endif
00383     for (int count = 0; count < nf; count++) {
00384       r_i[count].x += f_i[count].x;      
00385       r_i[count].y += f_i[count].y;      
00386       r_i[count].z += f_i[count].z;
00387     }
00388 
00389     }
00390     delete msg;
00391   }
00392 //CkPrintf("[%d:%d] wait: %d of %d (%d %d %d)\n", CkMyPe(), patchID, nWait, nChild+1, parent, child[0],child[1]);
00393 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00394   if(nWait == numChild+1) {
00395 #else
00396   if (nWait == nChild + 1) {
00397 #endif
00398     nWait = 0;
00399 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
00400     CmiUnlock(depositLock);
00401 #endif
00402     
00403     return msgCBuffer;
00404   }
00405 
00406 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
00407   CmiUnlock(depositLock);
00408 #endif
00409 
00410   return NULL;
00411 }

int ProxyPatch::getSpanningTreeChild int *   ) 
 

Definition at line 352 of file ProxyPatch.C.

Referenced by ProxyMgr::recvImmediateProxyAll(), and ProxyMgr::recvImmediateProxyData().

00352                                            { 
00353   for (int i=0; i<nChild; i++) c[i] = child[i];
00354   return nChild;
00355 }

int ProxyPatch::getSpanningTreeNChild void   )  [inline]
 

Definition at line 34 of file ProxyPatch.h.

Referenced by ProxyMgr::recvImmediateProxyAll(), and ProxyMgr::recvImmediateProxyData().

00034                                             {
00035         #ifdef NODEAWARE_PROXY_SPANNINGTREE
00036             return numChild;
00037         #else
00038             return nChild; 
00039         #endif
00040      }

int ProxyPatch::getSpanningTreeParent  )  [inline]
 

Definition at line 32 of file ProxyPatch.h.

Referenced by NodeProxyMgr::recvImmediateResults(), ProxyMgr::recvImmediateResults(), and ProxyMgr::sendResults().

00032 { return parent; }

void ProxyPatch::receiveAll ProxyDataMsg  ) 
 

Definition at line 194 of file ProxyPatch.C.

References ProxyDataMsg::avgPlLen, ProxyDataMsg::avgPositionList, ResizeArray< Elem >::begin(), DebugM, ResizeArray< Elem >::end(), ProxyDataMsg::flags, AtomMap::Object(), ProxyDataMsg::plExtLen, ProxyDataMsg::plLen, ProxyDataMsg::positionExtList, ProxyDataMsg::positionList, Patch::positionsReady(), ResizeArray< Elem >::resize(), and AtomMap::unregisterIDs().

Referenced by boxClosed(), and ProxyMgr::recvProxyAll().

00195 {
00196   DebugM(3, "receiveAll(" << patchID << ")\n");
00197 
00198   if ( boxesOpen )
00199   {
00200     proxyMsgBufferStatus = PROXYALLMSGBUFFERED;    
00201     curProxyMsg = msg;
00202     return;
00203   }  
00204 
00205   //The prevProxyMsg has to be deleted after this if-statement because
00206   // positionPtrBegin points to the space inside the prevProxyMsg
00207   if(prevProxyMsg!=NULL) {
00208 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00209       AtomMap::Object()->unregisterIDs(patchID,positionPtrBegin,positionPtrEnd);
00210 #else
00211       AtomMap::Object()->unregisterIDs(patchID, p.begin(), p.end());
00212 #endif
00213   }
00214   //Now delete the ProxyDataMsg of the previous step
00215   delete prevProxyMsg;
00216   curProxyMsg = msg;
00217   prevProxyMsg = curProxyMsg;
00218 
00219   flags = msg->flags;
00220 
00221 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00222   //We could set them to 0 for the sake of easy debugging
00223   //if there are something wrong in the "reuse position arrays" code
00224   //--Chao Mei
00225   //p.resize(0);
00226   //p_avg.resize(0);  
00227   positionPtrBegin = msg->positionList;
00228   positionPtrEnd = msg->positionList + msg->plLen;
00229 #else
00230   p.resize(msg->plLen);
00231   memcpy(p.begin(), msg->positionList, sizeof(CompAtom)*(msg->plLen));
00232 #endif
00233 
00234   numAtoms = msg->plLen;
00235   //numAtoms = p.size();
00236   
00237   avgPositionPtrBegin = msg->avgPositionList;
00238   avgPositionPtrEnd = msg->avgPositionList + msg->avgPlLen;
00239 
00240 #ifdef MEM_OPT_VERSION
00241   //We cannot reuse the CompAtomExt list inside the msg because
00242   //the information is needed at every step. In the current implementation
00243   //scheme, the ProxyDataMsg msg will be deleted for every step.
00244   //In order to keep this information, we have to do the extra copy. But
00245   //this overhead is amortized among the steps that atoms don't migrate
00246   // --Chao Mei
00247   pExt.resize(msg->plExtLen);
00248   memcpy(pExt.begin(), msg->positionExtList, sizeof(CompAtomExt)*(msg->plExtLen));
00249 #endif
00250 
00251   // DMK - Atom Separation (water vs. non-water)
00252   #if NAMD_SeparateWaters != 0
00253     numWaterAtoms = msg->numWaterAtoms;
00254   #endif
00255 
00256   positionsReady(1);
00257 }

void ProxyPatch::receiveAtoms ProxyAtomsMsg  ) 
 

Definition at line 126 of file ProxyPatch.C.

References ProxyAtomsMsg::atomIDList, DebugM, and ResizeArray< Elem >::size().

00127 {
00128   DebugM(3, "receiveAtoms(" << patchID << ")\n");
00129   numAtoms = msg->atomIDList.size();
00130   delete msg;
00131 }

void ProxyPatch::receiveData ProxyDataMsg  ) 
 

Definition at line 133 of file ProxyPatch.C.

References ProxyDataMsg::avgPlLen, ProxyDataMsg::avgPositionList, ResizeArray< Elem >::begin(), DebugM, ProxyDataMsg::flags, ProxyDataMsg::plExtLen, ProxyDataMsg::plLen, ProxyDataMsg::positionExtList, ProxyDataMsg::positionList, Patch::positionsReady(), and ResizeArray< Elem >::resize().

Referenced by boxClosed(), and ProxyMgr::recvProxyData().

00134 {
00135   DebugM(3, "receiveData(" << patchID << ")\n");
00136 
00137   //delete the ProxyDataMsg of the previous step
00138   delete prevProxyMsg;
00139   prevProxyMsg = NULL;
00140 
00141   if ( boxesOpen )
00142   {
00143       proxyMsgBufferStatus = PROXYDATAMSGBUFFERED;
00144     // store message in queue (only need one element, though)
00145     curProxyMsg = msg;
00146     return;
00147   }
00148 
00149   //Reuse position arrays inside proxyDataMsg --Chao Mei
00150   curProxyMsg = msg;
00151   prevProxyMsg = curProxyMsg;
00152   flags = msg->flags;
00153 
00154 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
00155   //We could set them to 0 for the sake of easy debugging
00156   //if there are something wrong in the "reuse position arrays" code
00157   //--Chao Mei
00158   //p.resize(0);
00159   //p_avg.resize(0);  
00160   positionPtrBegin = msg->positionList;
00161   positionPtrEnd = msg->positionList + msg->plLen;
00162 #else
00163   p.resize(msg->plLen);
00164   memcpy(p.begin(), msg->positionList, sizeof(CompAtom)*(msg->plLen));
00165 #endif
00166   
00167   avgPositionPtrBegin = msg->avgPositionList;
00168   avgPositionPtrEnd = msg->avgPositionList + msg->avgPlLen;
00169 
00170   
00171   if ( numAtoms == -1 ) { // for new proxies since receiveAtoms is not called
00172       //numAtoms = p.size();
00173       numAtoms = msg->plLen;
00174 
00175 #ifdef MEM_OPT_VERSION
00176       //Retrieve the CompAtomExt list
00177       CmiAssert(msg->plExtLen!=0);
00178       pExt.resize(msg->plExtLen);
00179       memcpy(pExt.begin(), msg->positionExtList, sizeof(CompAtomExt)*(msg->plExtLen));
00180 #endif
00181 
00182 
00183     // DMK - Atom Separation (water vs. non-water)
00184     #if NAMD_SeparateWaters != 0
00185       numWaterAtoms = msg->numWaterAtoms;
00186     #endif
00187 
00188     positionsReady(1);
00189   } else {
00190     positionsReady(0);
00191   }
00192 }

void ProxyPatch::setSpanningTree int  ,
int *  ,
int 
 

Definition at line 346 of file ProxyPatch.C.

Referenced by ProxyMgr::recvNodeAwareSpanningTree(), ProxyMgr::recvNodeAwareSTParent(), and ProxyMgr::recvSpanningTree().

00346                                                      { 
00347   parent=p; nChild = n; nWait = 0;
00348   for (int i=0; i<n; i++) child[i] = c[i];
00349 //CkPrintf("setSpanningTree: [%d:%d] %d %d:%d %d\n", CkMyPe(), patchID, parent, nChild, child[0], child[1]);
00350 }


The documentation for this class was generated from the following files:
Generated on Fri Sep 5 04:07:19 2008 for NAMD by  doxygen 1.3.9.1