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 void ComputePatchPair::doForce(CompAtom* p[2], CompAtomExt* pExt[2], Results* r[2])
00114 {
00115     CkPrintf("ComputePatchPair::doForce() - Dummy eval was sent\n");
00116     CkPrintf(" %d patch 1 atoms and %d patch 2 atoms\n", numAtoms[0], numAtoms[1] );
00117 }
00118 
00119 //---------------------------------------------------------------------
00120 // Where the actual computation is invoked.  doForce is 
00121 // overloaded with specific calculation
00122 //---------------------------------------------------------------------
00123 void ComputePatchPair::doWork() {
00124   CompAtom* p[2];
00125   Results* r[2];
00126   int i;
00127 
00128   // Open up positionBox, forceBox, and atomBox
00129   for (i=0; i<2; i++) {
00130       p[i] = positionBox[i]->open();
00131       r[i] = forceBox[i]->open();
00132   }
00133 
00134   // Pass pointers to doForce
00135 
00136   //Just for debugging
00137 /*
00138   Patch *patch0 = positionBox[0]->getOwner();
00139   Patch *patch1 = positionBox[1]->getOwner();
00140   CmiAssert(patch0 == patch[0]);
00141   CmiAssert(patch1 == patch[1]);
00142 */
00143 
00144   CompAtomExt *pExt[2];
00145   pExt[0] = patch[0]->getCompAtomExtInfo();
00146   pExt[1] = patch[1]->getCompAtomExtInfo();
00147   doForce(p, pExt, r);
00148 
00149   // Close up boxes
00150   for (i=0; i<2; i++) {
00151       positionBox[i]->close(&p[i]);
00152       forceBox[i]->close(&r[i]);
00153   }
00154 }
00155 

Generated on Tue Nov 24 04:07:43 2009 for NAMD by  doxygen 1.3.9.1