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

Generated on Fri Sep 22 01:17:11 2017 for NAMD by  doxygen 1.4.7