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

ComputePatchPair.C

Go to the documentation of this file.
00001 
00007 #include "WorkDistrib.decl.h"
00008 #include "Node.h"
00009 #include "ComputePatchPair.h"
00010 #include "Priorities.h"
00011 #include "PatchMap.inl"
00012 #include "Patch.h"
00013 
00014 //#define DEBUGM
00015 #define MIN_DEBUG_LEVEL 4
00016 #include "Debug.h"
00017 
00018 ComputePatchPair::ComputePatchPair(ComputeID c, PatchID p[], int t[]) 
00019     : Compute(c) {
00020 
00021   setNumPatches(2);
00022 
00023   for (int i=0; i<2; i++) {
00024       patchID[i] = p[i];
00025       trans[i] = t[i];
00026       patch[i] = NULL;
00027       positionBox[i] = NULL;
00028       forceBox[i] = NULL;
00029   }
00030 }
00031 
00032 ComputePatchPair::~ComputePatchPair() {
00033   DebugM(4, "~ComputePatchPair("<<cid<<") numAtoms("<<patchID[0]<<") = " 
00034     << numAtoms[0] 
00035     << " numAtoms("<<patchID[1]<<") = " << numAtoms[1] << "\n" );
00036   DebugM(4, "~ComputePatchPair("<<cid<<") addr("<<patchID[0]<<") = " 
00037     << PatchMap::Object()->patch(patchID[0]) << " addr("<<patchID[1]<<") = "
00038     << PatchMap::Object()->patch(patchID[1]) << "\n");
00039   for (int i=0; i<2; i++) {
00040     if (positionBox[i] != NULL) {
00041       PatchMap::Object()->patch(patchID[i])->unregisterPositionPickup(cid,
00042          &positionBox[i]);
00043     }
00044     if (forceBox[i] != NULL) {
00045       PatchMap::Object()->patch(patchID[i])->unregisterForceDeposit(cid,
00046                 &forceBox[i]);
00047     }
00048   }
00049 
00050 }
00051 
00052 void ComputePatchPair::initialize() {
00053     // How can we tell if BoxOwner has packed up and left?  Need a mechanism
00054     // to handle this or do we assume the Boxes have been dumped?
00055 
00056     for (int i=0; i<2; i++) {
00057         if (positionBox[i] == NULL) { // We have yet to get boxes
00058             if (!(patch[i] = PatchMap::Object()->patch(patchID[i]))) {
00059               DebugM(5,"invalid patch(" << patchID[i] 
00060                    << ")  pointer!\n");
00061             }
00062             positionBox[i] = patch[i]->registerPositionPickup(cid,trans[i]);
00063             forceBox[i] = patch[i]->registerForceDeposit(cid);
00064         }
00065         numAtoms[i] = patch[i]->getNumAtoms();
00066     }
00067 
00068   DebugM(4, "initialize("<<cid<<") numAtoms("<<patchID[0]<<") = " 
00069     << numAtoms[0] 
00070     << " numAtoms(" <<patchID[1]<<") = " << numAtoms[1] << "\n" );
00071 
00072     Compute::initialize();
00073 
00074     // proxies are more urgent (lower priority) than patches
00075     int myNode = CkMyPe();
00076     int p0 = PATCH_PRIORITY(patchID[0]);
00077     if ( PatchMap::Object()->node(patchID[0]) == myNode ) {
00078       p0 += COMPUTE_HOME_PRIORITY;
00079     } else {
00080       p0 += COMPUTE_PROXY_PRIORITY;
00081     }
00082     int p1 = PATCH_PRIORITY(patchID[1]);
00083     if ( PatchMap::Object()->node(patchID[1]) == myNode ) {
00084       p1 += COMPUTE_HOME_PRIORITY;
00085     } else {
00086       p1 += COMPUTE_PROXY_PRIORITY;
00087     }
00088     basePriority = ((p0<p1)?p0:p1);   // most urgent wins
00089 
00090 }
00091 
00092 void ComputePatchPair::atomUpdate() {
00093     // How can we tell if BoxOwner has packed up and left?  Need a mechanism
00094     // to handle this or do we assume the Boxes have been dumped?
00095 
00096     // DebugM(4,"atomUpdate() - positionBox[0] is " << positionBox[0] << "\n");
00097     for (int i=0; i<2; i++) {
00098 
00099         numAtoms[i] = patch[i]->getNumAtoms();
00100 
00101         // DMK - Atom Separation (water vs. non-water)
00102         #if NAMD_SeparateWaters != 0
00103           numWaterAtoms[i] = patch[i]->getNumWaterAtoms();
00104         #endif
00105     }
00106 
00107 
00108 
00109     // Compute::atomUpdate();
00110 }
00111 
00112 
00113 #ifdef MEM_OPT_VERSION
00114 void ComputePatchPair::doForce(CompAtom* p[2], CompAtomExt* pExt[2], Results* r[2])
00115 #else
00116 void ComputePatchPair::doForce(CompAtom* p[2], Results* r[2])
00117 #endif
00118 {
00119     CkPrintf("ComputePatchPair::doForce() - Dummy eval was sent\n");
00120     CkPrintf(" %d patch 1 atoms and %d patch 2 atoms\n", numAtoms[0], numAtoms[1] );
00121 }
00122 
00123 //---------------------------------------------------------------------
00124 // Where the actual computation is invoked.  doForce is 
00125 // overloaded with specific calculation
00126 //---------------------------------------------------------------------
00127 void ComputePatchPair::doWork() {
00128   CompAtom* p[2];
00129   Results* r[2];
00130   int i;
00131 
00132   // Open up positionBox, forceBox, and atomBox
00133   for (i=0; i<2; i++) {
00134       p[i] = positionBox[i]->open();
00135       r[i] = forceBox[i]->open();
00136   }
00137 
00138   // Pass pointers to doForce
00139 #ifdef MEM_OPT_VERSION
00140 
00141   //Just for debugging
00142 /*
00143   Patch *patch0 = positionBox[0]->getOwner();
00144   Patch *patch1 = positionBox[1]->getOwner();
00145   CmiAssert(patch0 == patch[0]);
00146   CmiAssert(patch1 == patch[1]);
00147 */
00148 
00149   CompAtomExt *pExt[2];
00150   pExt[0] = patch[0]->getCompAtomExtInfo();
00151   pExt[1] = patch[1]->getCompAtomExtInfo();
00152   doForce(p, pExt, r);
00153 #else
00154   doForce(p,r);
00155 #endif
00156 
00157   // Close up boxes
00158   for (i=0; i<2; i++) {
00159       positionBox[i]->close(&p[i]);
00160       forceBox[i]->close(&r[i]);
00161   }
00162 }
00163 

Generated on Sat Aug 30 04:07:39 2008 for NAMD by  doxygen 1.3.9.1