00001
00007 #include "InfoStream.h"
00008 #include "ProcessorPrivate.h"
00009
00010
00011 #define MIN_DEBUG_LEVEL 1
00012 #include "Debug.h"
00013
00014 #include "BOCgroup.h"
00015 #include "ComputeMgr.decl.h"
00016 #include "ComputeMgr.h"
00017 #include "ProxyMgr.decl.h"
00018 #include "ProxyMgr.h"
00019
00020 #include "Node.h"
00021 #include "ComputeMap.h"
00022 #include "PatchMap.h"
00023 #include "PatchMap.inl"
00024
00025 #include "Compute.h"
00026 #include "ComputeNonbondedUtil.h"
00027 #include "ComputeNonbondedSelf.h"
00028 #include "ComputeNonbondedPair.h"
00029 #include "ComputeNonbondedCUDA.h"
00030 #include "ComputeAngles.h"
00031 #include "ComputeDihedrals.h"
00032 #include "ComputeImpropers.h"
00033 #include "ComputeThole.h"
00034 #include "ComputeAniso.h"
00035 #include "ComputeCrossterms.h"
00036 #include "ComputeBonds.h"
00037 #include "ComputeNonbondedCUDAExcl.h"
00038 #include "ComputeFullDirect.h"
00039 #include "ComputeGlobal.h"
00040 #include "ComputeGlobalMsgs.h"
00041 #include "ComputeExt.h"
00042 #include "ComputeGBISser.h"
00043 #include "ComputeLCPO.h"
00044 #include "ComputeMsmSerial.h"
00045 #include "ComputeMsmMsa.h"
00046 #include "ComputeMsm.h"
00047 #include "ComputeDPMTA.h"
00048 #include "ComputeDPME.h"
00049 #include "ComputeDPMEMsgs.h"
00050 #include "ComputePme.h"
00051 #include "OptPme.h"
00052 #include "ComputeEwald.h"
00053 #include "ComputeEField.h"
00054
00055 #include "ComputeGridForce.h"
00056
00057 #include "ComputeStir.h"
00058 #include "ComputeSphericalBC.h"
00059 #include "ComputeCylindricalBC.h"
00060 #include "ComputeTclBC.h"
00061 #include "ComputeRestraints.h"
00062 #include "ComputeConsForce.h"
00063 #include "ComputeConsForceMsgs.h"
00064 #include "WorkDistrib.h"
00065
00066 #include "LdbCoordinator.h"
00067
00068
00069 #include "FreeEnergyEnums.h"
00070 #include "FreeEnergyAssert.h"
00071 #include "FreeEnergyGroup.h"
00072 #include "FreeEnergyVector.h"
00073 #include "FreeEnergyRestrain.h"
00074 #include "FreeEnergyRMgr.h"
00075 #include "FreeEnergyLambda.h"
00076 #include "FreeEnergyLambdMgr.h"
00077
00078 #include "GlobalMasterTest.h"
00079 #include "GlobalMasterIMD.h"
00080 #include "GlobalMasterTcl.h"
00081 #include "GlobalMasterSMD.h"
00082 #include "GlobalMasterTMD.h"
00083 #include "GlobalMasterSymmetry.h"
00084 #include "GlobalMasterEasy.h"
00085 #include "GlobalMasterMisc.h"
00086 #include "GlobalMasterFreeEnergy.h"
00087 #include "GlobalMasterColvars.h"
00088
00089 ComputeMgr::ComputeMgr()
00090 {
00091 CkpvAccess(BOCclass_group).computeMgr = thisgroup;
00092 computeGlobalObject = 0;
00093 computeDPMEObject = 0;
00094 computeEwaldObject = 0;
00095 computeNonbondedCUDAObject = 0;
00096 computeNonbondedWorkArrays = new ComputeNonbondedWorkArrays;
00097 skipSplitting = 0;
00098 }
00099
00100 ComputeMgr::~ComputeMgr(void)
00101 {
00102 delete computeNonbondedWorkArrays;
00103 }
00104
00105 void ComputeMgr::updateComputes(int ep, CkGroupID chareID)
00106 {
00107 updateComputesReturnEP = ep;
00108 updateComputesReturnChareID = chareID;
00109 updateComputesCount = CkNumPes();
00110
00111 if (CkMyPe())
00112 {
00113 iout << iPE << iERRORF << "updateComputes signaled on wrong Pe!\n" << endi;
00114 CkExit();
00115 return;
00116 }
00117
00118 CkStartQD(CkIndex_ComputeMgr::updateComputes2((CkQdMsg*)0),&thishandle);
00119 }
00120
00121 void ComputeMgr::updateComputes2(CkQdMsg *msg)
00122 {
00123 delete msg;
00124
00125 CProxy_WorkDistrib wd(CkpvAccess(BOCclass_group).workDistrib);
00126 WorkDistrib *workDistrib = wd.ckLocalBranch();
00127 workDistrib->saveComputeMapChanges(CkIndex_ComputeMgr::updateComputes3(),thisgroup);
00128 }
00129
00130 void ComputeMgr::updateComputes3()
00131 {
00132 if ( skipSplitting ) {
00133 CProxy_ComputeMgr(thisgroup).updateLocalComputes();
00134 } else {
00135 CProxy_ComputeMgr(thisgroup).splitComputes();
00136 skipSplitting = 1;
00137 }
00138 }
00139
00140 void ComputeMgr::splitComputes()
00141 {
00142 if ( ! CkMyRank() ) {
00143 ComputeMap *computeMap = ComputeMap::Object();
00144 const int nc = computeMap->numComputes();
00145
00146 for (int i=0; i<nc; i++) {
00147 int nnp = computeMap->newNumPartitions(i);
00148 if ( nnp > 0 ) {
00149 if ( computeMap->numPartitions(i) != 1 ) {
00150 CkPrintf("Warning: unable to partition compute %d\n", i);
00151 computeMap->setNewNumPartitions(i,0);
00152 continue;
00153 }
00154
00155 computeMap->setNumPartitions(i,nnp);
00156 if (computeMap->newNode(i) == -1) {
00157 computeMap->setNewNode(i,computeMap->node(i));
00158 }
00159 for ( int j=1; j<nnp; ++j ) {
00160 int newcid = computeMap->cloneCompute(i,j);
00161
00162 }
00163 }
00164 }
00165 computeMap->extendPtrs();
00166 }
00167
00168 if (!CkMyPe())
00169 {
00170 CkStartQD(CkIndex_ComputeMgr::splitComputes2((CkQdMsg*)0), &thishandle);
00171 }
00172 }
00173
00174 void ComputeMgr::splitComputes2(CkQdMsg *msg)
00175 {
00176 delete msg;
00177 CProxy_ComputeMgr(thisgroup).updateLocalComputes();
00178 }
00179
00180 void ComputeMgr::updateLocalComputes()
00181 {
00182 ComputeMap *computeMap = ComputeMap::Object();
00183 CProxy_ProxyMgr pm(CkpvAccess(BOCclass_group).proxyMgr);
00184 ProxyMgr *proxyMgr = pm.ckLocalBranch();
00185 LdbCoordinator *ldbCoordinator = LdbCoordinator::Object();
00186
00187 computeFlag.resize(0);
00188
00189 const int nc = computeMap->numComputes();
00190 for (int i=0; i<nc; i++) {
00191
00192 if ( computeMap->node(i) == CkMyPe() &&
00193 computeMap->newNumPartitions(i) > 1 ) {
00194 Compute *c = computeMap->compute(i);
00195 ldbCoordinator->Migrate(c->ldObjHandle,CkMyPe());
00196 delete c;
00197 computeMap->registerCompute(i,NULL);
00198 if ( computeMap->newNode(i) == CkMyPe() ) computeFlag.add(i);
00199 } else
00200 if (computeMap->newNode(i) == CkMyPe() && computeMap->node(i) != CkMyPe())
00201 {
00202 computeFlag.add(i);
00203 for (int n=0; n < computeMap->numPids(i); n++)
00204 {
00205 proxyMgr->createProxy(computeMap->pid(i,n));
00206 }
00207 }
00208 else if (computeMap->node(i) == CkMyPe() &&
00209 (computeMap->newNode(i) != -1 && computeMap->newNode(i) != CkMyPe() ))
00210 {
00211
00212 delete computeMap->compute(i);
00213 computeMap->registerCompute(i,NULL);
00214 }
00215 }
00216
00217 if (!CkMyPe())
00218 {
00219 CkStartQD(CkIndex_ComputeMgr::updateLocalComputes2((CkQdMsg*)0), &thishandle);
00220 }
00221 }
00222
00223 void
00224 ComputeMgr::updateLocalComputes2(CkQdMsg *msg)
00225 {
00226 delete msg;
00227 CProxy_ComputeMgr(thisgroup).updateLocalComputes3();
00228 }
00229
00230 void
00231 ComputeMgr::updateLocalComputes3()
00232 {
00233 ComputeMap *computeMap = ComputeMap::Object();
00234 CProxy_ProxyMgr pm(CkpvAccess(BOCclass_group).proxyMgr);
00235 ProxyMgr *proxyMgr = pm.ckLocalBranch();
00236
00237 ProxyMgr::nodecount = 0;
00238
00239 const int nc = computeMap->numComputes();
00240
00241 if ( ! CkMyRank() ) {
00242 for (int i=0; i<nc; i++) {
00243 computeMap->setNewNumPartitions(i,0);
00244 if (computeMap->newNode(i) != -1) {
00245 computeMap->setNode(i,computeMap->newNode(i));
00246 computeMap->setNewNode(i,-1);
00247 }
00248 }
00249 }
00250
00251 for(int i=0; i<computeFlag.size(); i++) createCompute(computeFlag[i], computeMap);
00252 computeFlag.clear();
00253
00254 proxyMgr->removeUnusedProxies();
00255
00256 if (!CkMyPe())
00257 {
00258 CkStartQD(CkIndex_ComputeMgr::updateLocalComputes4((CkQdMsg*)0), &thishandle);
00259 }
00260 }
00261
00262 void
00263 ComputeMgr::updateLocalComputes4(CkQdMsg *msg)
00264 {
00265 delete msg;
00266 CProxy_ComputeMgr(thisgroup).updateLocalComputes5();
00267
00268
00269 SimParameters *simParams = Node::Object()->simParameters;
00270 if (simParams->storeComputeMap) {
00271 ComputeMap *computeMap = ComputeMap::Object();
00272 computeMap->saveComputeMap(simParams->computeMapFilename);
00273 }
00274 }
00275
00276 #if 0
00277 int firstphase = 1;
00278 #endif
00279
00280 void
00281 ComputeMgr::updateLocalComputes5()
00282 {
00283 if ( ! CkMyRank() ) {
00284 ComputeMap::Object()->checkMap();
00285 PatchMap::Object()->checkMap();
00286 }
00287
00288
00289
00290 if (proxySendSpanning || proxyRecvSpanning)
00291 ProxyMgr::Object()->buildProxySpanningTree2();
00292
00293
00294
00295
00296 #if 0
00297 if (proxySendSpanning || proxyRecvSpanning)
00298 {
00299 if (firstphase)
00300 ProxyMgr::Object()->buildProxySpanningTree2();
00301 else
00302 if (CkMyPe() == 0)
00303 ProxyMgr::Object()->sendSpanningTrees();
00304
00305 firstphase = 0;
00306 }
00307 #endif
00308
00309 if (!CkMyPe())
00310 CkStartQD(CkIndex_ComputeMgr::doneUpdateLocalComputes(), &thishandle);
00311 }
00312
00313 void ComputeMgr::doneUpdateLocalComputes()
00314 {
00315
00316
00317 DebugM(4, "doneUpdateLocalComputes on Pe("<<CkMyPe()<<")\n");
00318 void *msg = CkAllocMsg(0,0,0);
00319 CkSendMsgBranch(updateComputesReturnEP,msg,0,updateComputesReturnChareID);
00320
00321 }
00322
00323
00324 void
00325 ComputeMgr::createCompute(ComputeID i, ComputeMap *map)
00326 {
00327 Compute *c;
00328 PatchID pid2[2];
00329 PatchIDList pids;
00330 int trans2[2];
00331 SimParameters *simParams = Node::Object()->simParameters;
00332
00333 PatchID pid8[8];
00334 int trans8[8];
00335
00336 switch ( map->type(i) )
00337 {
00338 case computeNonbondedSelfType:
00339 #ifdef NAMD_CUDA
00340 register_cuda_compute_self(i,map->computeData[i].pids[0].pid);
00341 #else
00342 c = new ComputeNonbondedSelf(i,map->computeData[i].pids[0].pid,
00343 computeNonbondedWorkArrays,
00344 map->partition(i),map->partition(i)+1,
00345 map->numPartitions(i));
00346 map->registerCompute(i,c);
00347 c->initialize();
00348 #endif
00349 break;
00350 case computeLCPOType:
00351 for (int j = 0; j < 8; j++) {
00352 pid8[j] = map->computeData[i].pids[j].pid;
00353 trans8[j] = map->computeData[i].pids[j].trans;
00354 }
00355 c = new ComputeLCPO(i,pid8,trans8,
00356 computeNonbondedWorkArrays,
00357 map->partition(i),map->partition(i)+1,
00358 map->numPartitions(i), 8);
00359 map->registerCompute(i,c);
00360 c->initialize();
00361
00362 break;
00363 case computeNonbondedPairType:
00364 pid2[0] = map->computeData[i].pids[0].pid;
00365 trans2[0] = map->computeData[i].pids[0].trans;
00366 pid2[1] = map->computeData[i].pids[1].pid;
00367 trans2[1] = map->computeData[i].pids[1].trans;
00368 #ifdef NAMD_CUDA
00369 register_cuda_compute_pair(i,pid2,trans2);
00370 #else
00371 c = new ComputeNonbondedPair(i,pid2,trans2,
00372 computeNonbondedWorkArrays,
00373 map->partition(i),map->partition(i)+1,
00374 map->numPartitions(i));
00375 map->registerCompute(i,c);
00376 c->initialize();
00377 #endif
00378 break;
00379 #ifdef NAMD_CUDA
00380 case computeNonbondedCUDAType:
00381 c = computeNonbondedCUDAObject = new ComputeNonbondedCUDA(i,this);
00382 map->registerCompute(i,c);
00383 c->initialize();
00384 break;
00385 #endif
00386 case computeExclsType:
00387 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00388 c = new ComputeExcls(i,pids);
00389 map->registerCompute(i,c);
00390 c->initialize();
00391 break;
00392 case computeBondsType:
00393 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00394 c = new ComputeBonds(i,pids);
00395 map->registerCompute(i,c);
00396 c->initialize();
00397 break;
00398 case computeAnglesType:
00399 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00400 c = new ComputeAngles(i,pids);
00401 map->registerCompute(i,c);
00402 c->initialize();
00403 break;
00404 case computeDihedralsType:
00405 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00406 c = new ComputeDihedrals(i,pids);
00407 map->registerCompute(i,c);
00408 c->initialize();
00409 break;
00410 case computeImpropersType:
00411 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00412 c = new ComputeImpropers(i,pids);
00413 map->registerCompute(i,c);
00414 c->initialize();
00415 break;
00416 case computeTholeType:
00417 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00418 c = new ComputeThole(i,pids);
00419 map->registerCompute(i,c);
00420 c->initialize();
00421 break;
00422 case computeAnisoType:
00423 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00424 c = new ComputeAniso(i,pids);
00425 map->registerCompute(i,c);
00426 c->initialize();
00427 break;
00428 case computeCrosstermsType:
00429 PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
00430 c = new ComputeCrossterms(i,pids);
00431 map->registerCompute(i,c);
00432 c->initialize();
00433 break;
00434 case computeSelfExclsType:
00435 c = new ComputeSelfExcls(i,map->computeData[i].pids[0].pid);
00436 map->registerCompute(i,c);
00437 c->initialize();
00438 break;
00439 case computeSelfBondsType:
00440 c = new ComputeSelfBonds(i,map->computeData[i].pids[0].pid);
00441 map->registerCompute(i,c);
00442 c->initialize();
00443 break;
00444 case computeSelfAnglesType:
00445 c = new ComputeSelfAngles(i,map->computeData[i].pids[0].pid);
00446 map->registerCompute(i,c);
00447 c->initialize();
00448 break;
00449 case computeSelfDihedralsType:
00450 c = new ComputeSelfDihedrals(i,map->computeData[i].pids[0].pid);
00451 map->registerCompute(i,c);
00452 c->initialize();
00453 break;
00454 case computeSelfImpropersType:
00455 c = new ComputeSelfImpropers(i,map->computeData[i].pids[0].pid);
00456 map->registerCompute(i,c);
00457 c->initialize();
00458 break;
00459 case computeSelfTholeType:
00460 c = new ComputeSelfThole(i,map->computeData[i].pids[0].pid);
00461 map->registerCompute(i,c);
00462 c->initialize();
00463 break;
00464 case computeSelfAnisoType:
00465 c = new ComputeSelfAniso(i,map->computeData[i].pids[0].pid);
00466 map->registerCompute(i,c);
00467 c->initialize();
00468 break;
00469 case computeSelfCrosstermsType:
00470 c = new ComputeSelfCrossterms(i,map->computeData[i].pids[0].pid);
00471 map->registerCompute(i,c);
00472 c->initialize();
00473 break;
00474 #ifdef DPMTA
00475 case computeDPMTAType:
00476 c = new ComputeDPMTA(i);
00477 map->registerCompute(i,c);
00478 c->initialize();
00479 break;
00480 #endif
00481 #ifdef DPME
00482 case computeDPMEType:
00483 c = computeDPMEObject = new ComputeDPME(i,this);
00484 map->registerCompute(i,c);
00485 c->initialize();
00486 break;
00487 #endif
00488 case optPmeType:
00489 c = new OptPmeCompute(i);
00490 map->registerCompute(i,c);
00491 c->initialize();
00492 break;
00493 case computePmeType:
00494 c = new ComputePme(i,map->computeData[i].pids[0].pid);
00495 map->registerCompute(i,c);
00496 c->initialize();
00497 break;
00498 case computeEwaldType:
00499 c = computeEwaldObject = new ComputeEwald(i,this);
00500 map->registerCompute(i,c);
00501 c->initialize();
00502 break;
00503 case computeFullDirectType:
00504 c = new ComputeFullDirect(i);
00505 map->registerCompute(i,c);
00506 c->initialize();
00507 break;
00508 case computeGlobalType:
00509 c = computeGlobalObject = new ComputeGlobal(i,this);
00510 map->registerCompute(i,c);
00511 c->initialize();
00512 break;
00513 case computeStirType:
00514 c = new ComputeStir(i,map->computeData[i].pids[0].pid);
00515 map->registerCompute(i,c);
00516 c->initialize();
00517 break;
00518 case computeExtType:
00519 c = new ComputeExt(i);
00520 map->registerCompute(i,c);
00521 c->initialize();
00522 break;
00523 case computeGBISserType:
00524 c = new ComputeGBISser(i);
00525 map->registerCompute(i,c);
00526 c->initialize();
00527 break;
00528 case computeMsmSerialType:
00529 c = new ComputeMsmSerial(i);
00530 map->registerCompute(i,c);
00531 c->initialize();
00532 break;
00533 #ifdef CHARM_HAS_MSA
00534 case computeMsmMsaType:
00535 c = new ComputeMsmMsa(i);
00536 map->registerCompute(i,c);
00537 c->initialize();
00538 break;
00539 #endif
00540 case computeMsmType:
00541 c = new ComputeMsm(i);
00542 map->registerCompute(i,c);
00543 c->initialize();
00544 break;
00545 case computeEFieldType:
00546 c = new ComputeEField(i,map->computeData[i].pids[0].pid);
00547 map->registerCompute(i,c);
00548 c->initialize();
00549 break;
00550
00551 case computeGridForceType:
00552 c = new ComputeGridForce(i,map->computeData[i].pids[0].pid);
00553 map->registerCompute(i,c);
00554 c->initialize();
00555 break;
00556
00557 case computeSphericalBCType:
00558 c = new ComputeSphericalBC(i,map->computeData[i].pids[0].pid);
00559 map->registerCompute(i,c);
00560 c->initialize();
00561 break;
00562 case computeCylindricalBCType:
00563 c = new ComputeCylindricalBC(i,map->computeData[i].pids[0].pid);
00564 map->registerCompute(i,c);
00565 c->initialize();
00566 break;
00567 case computeTclBCType:
00568 c = new ComputeTclBC(i);
00569 map->registerCompute(i,c);
00570 c->initialize();
00571 break;
00572 case computeRestraintsType:
00573 c = new ComputeRestraints(i,map->computeData[i].pids[0].pid);
00574 map->registerCompute(i,c);
00575 c->initialize();
00576 break;
00577 case computeConsForceType:
00578 c = new ComputeConsForce(i,map->computeData[i].pids[0].pid);
00579 map->registerCompute(i,c);
00580 c->initialize();
00581 break;
00582 case computeConsTorqueType:
00583 c = new ComputeConsTorque(i,map->computeData[i].pids[0].pid);
00584 map->registerCompute(i,c);
00585 c->initialize();
00586 break;
00587 default:
00588 NAMD_bug("Unknown compute type in ComputeMgr::createCompute().");
00589 break;
00590 }
00591 }
00592
00593 void registerUserEventsForAllComputeObjs()
00594 {
00595 #ifdef TRACE_COMPUTE_OBJECTS
00596 ComputeMap *map = ComputeMap::Object();
00597 PatchMap *pmap = PatchMap::Object();
00598 char user_des[50];
00599 int p1, p2;
00600 int adim, bdim, cdim;
00601 int t1, t2;
00602 int x1, y1, z1, x2, y2, z2;
00603 int dx, dy, dz;
00604 for (int i=0; i<map->numComputes(); i++)
00605 {
00606 memset(user_des, 0, 50);
00607 switch ( map->type(i) )
00608 {
00609 case computeNonbondedSelfType:
00610 sprintf(user_des, "computeNonBondedSelfType_%d_pid_%d", i, map->pid(i,0));
00611 break;
00612 case computeLCPOType:
00613 sprintf(user_des, "computeLCPOType_%d_pid_%d", i, map->pid(i,0));
00614 break;
00615 case computeNonbondedPairType:
00616 adim = pmap->gridsize_a();
00617 bdim = pmap->gridsize_b();
00618 cdim = pmap->gridsize_c();
00619 p1 = map->pid(i, 0);
00620 t1 = map->trans(i, 0);
00621 x1 = pmap->index_a(p1) + adim * Lattice::offset_a(t1);
00622 y1 = pmap->index_b(p1) + bdim * Lattice::offset_b(t1);
00623 z1 = pmap->index_c(p1) + cdim * Lattice::offset_c(t1);
00624 p2 = map->pid(i, 1);
00625 t2 = map->trans(i, 1);
00626 x2 = pmap->index_a(p2) + adim * Lattice::offset_a(t2);
00627 y2 = pmap->index_b(p2) + bdim * Lattice::offset_b(t2);
00628 z2 = pmap->index_c(p2) + cdim * Lattice::offset_c(t2);
00629 dx = abs(x1-x2);
00630 dy = abs(y1-y2);
00631 dz = abs(z1-z2);
00632 sprintf(user_des, "computeNonBondedPairType_%d(%d,%d,%d)", i, dx,dy,dz);
00633 break;
00634 case computeExclsType:
00635 sprintf(user_des, "computeExclsType_%d", i);
00636 break;
00637 case computeBondsType:
00638 sprintf(user_des, "computeBondsType_%d", i);
00639 break;
00640 case computeAnglesType:
00641 sprintf(user_des, "computeAnglesType_%d", i);
00642 break;
00643 case computeDihedralsType:
00644 sprintf(user_des, "computeDihedralsType_%d", i);
00645 break;
00646 case computeImpropersType:
00647 sprintf(user_des, "computeImpropersType_%d", i);
00648 break;
00649 case computeTholeType:
00650 sprintf(user_des, "computeTholeType_%d", i);
00651 break;
00652 case computeAnisoType:
00653 sprintf(user_des, "computeAnisoType_%d", i);
00654 break;
00655 case computeCrosstermsType:
00656 sprintf(user_des, "computeCrosstermsType_%d", i);
00657 break;
00658 case computeSelfExclsType:
00659 sprintf(user_des, "computeSelfExclsType_%d", i);
00660 break;
00661 case computeSelfBondsType:
00662 sprintf(user_des, "computeSelfBondsType_%d", i);
00663 break;
00664 case computeSelfAnglesType:
00665 sprintf(user_des, "computeSelfAnglesType_%d", i);
00666 break;
00667 case computeSelfDihedralsType:
00668 sprintf(user_des, "computeSelfDihedralsType_%d", i);
00669 break;
00670 case computeSelfImpropersType:
00671 sprintf(user_des, "computeSelfImpropersType_%d", i);
00672 break;
00673 case computeSelfTholeType:
00674 sprintf(user_des, "computeSelfTholeType_%d", i);
00675 break;
00676 case computeSelfAnisoType:
00677 sprintf(user_des, "computeSelfAnisoType_%d", i);
00678 break;
00679 case computeSelfCrosstermsType:
00680 sprintf(user_des, "computeSelfCrosstermsType_%d", i);
00681 break;
00682 #ifdef DPMTA
00683 case computeDPMTAType:
00684 sprintf(user_des, "computeDPMTAType_%d", i);
00685 break;
00686 #endif
00687 #ifdef DPME
00688 case computeDPMEType:
00689 sprintf(user_des, "computeDPMEType_%d", i);
00690 break;
00691 #endif
00692 case computePmeType:
00693 sprintf(user_des, "computePMEType_%d", i);
00694 break;
00695 case computeEwaldType:
00696 sprintf(user_des, "computeEwaldType_%d", i);
00697 break;
00698 case computeFullDirectType:
00699 sprintf(user_des, "computeFullDirectType_%d", i);
00700 break;
00701 case computeGlobalType:
00702 sprintf(user_des, "computeGlobalType_%d", i);
00703 break;
00704 case computeStirType:
00705 sprintf(user_des, "computeStirType_%d", i);
00706 break;
00707 case computeExtType:
00708 sprintf(user_des, "computeExtType_%d", i);
00709 break;
00710 case computeEFieldType:
00711 sprintf(user_des, "computeEFieldType_%d", i);
00712 break;
00713
00714 case computeGridForceType:
00715 sprintf(user_des, "computeGridForceType_%d", i);
00716 break;
00717
00718 case computeSphericalBCType:
00719 sprintf(user_des, "computeSphericalBCType_%d", i);
00720 break;
00721 case computeCylindricalBCType:
00722 sprintf(user_des, "computeCylindricalBCType_%d", i);
00723 break;
00724 case computeTclBCType:
00725 sprintf(user_des, "computeTclBCType_%d", i);
00726 break;
00727 case computeRestraintsType:
00728 sprintf(user_des, "computeRestraintsType_%d", i);
00729 break;
00730 case computeConsForceType:
00731 sprintf(user_des, "computeConsForceType_%d", i);
00732 break;
00733 case computeConsTorqueType:
00734 sprintf(user_des, "computeConsTorqueType_%d", i);
00735 break;
00736 default:
00737 NAMD_bug("Unknown compute type in ComputeMgr::registerUserEventForAllComputeObjs().");
00738 break;
00739 }
00740 int user_des_len = strlen(user_des);
00741 char *user_des_cst = new char[user_des_len+1];
00742 memcpy(user_des_cst, user_des, user_des_len);
00743 user_des_cst[user_des_len] = 0;
00744
00745
00746
00747
00748 int reEvenId = traceRegisterUserEvent(user_des_cst, TRACE_COMPOBJ_IDOFFSET+i);
00749
00750 }
00751 #else
00752 return;
00753 #endif
00754 }
00755
00756 void
00757 ComputeMgr::createComputes(ComputeMap *map)
00758 {
00759 Node *node = Node::Object();
00760 SimParameters *simParams = node->simParameters;
00761 int myNode = node->myid();
00762
00763 ComputeNonbondedUtil::select();
00764
00765 if ( simParams->globalForcesOn && !myNode )
00766 {
00767 DebugM(4,"Mgr running on Node "<<CkMyPe()<<"\n");
00768
00769 masterServerObject = new GlobalMasterServer(this,
00770 PatchMap::Object()->numNodesWithPatches());
00771
00772
00773
00774 if (simParams->tclForcesOn)
00775 masterServerObject->addClient(new GlobalMasterTcl());
00776 if (simParams->IMDon && ! simParams->IMDignore)
00777 masterServerObject->addClient(new GlobalMasterIMD());
00778
00779 if (simParams->SMDOn)
00780 masterServerObject->addClient(
00781 new GlobalMasterSMD(simParams->SMDk, simParams->SMDk2,
00782 simParams->SMDVel,
00783 simParams->SMDDir, simParams->SMDOutputFreq,
00784 simParams->firstTimestep, simParams->SMDFile,
00785 node->molecule->numAtoms)
00786 );
00787
00788 if (simParams->symmetryOn &&
00789 (simParams->firstTimestep < simParams->symmetryLastStep ||
00790 simParams->symmetryLastStep == -1))
00791 masterServerObject->addClient(new GlobalMasterSymmetry());
00792 if (simParams->TMDOn)
00793 masterServerObject->addClient(new GlobalMasterTMD());
00794 if (simParams->miscForcesOn)
00795 masterServerObject->addClient(new GlobalMasterMisc());
00796 if ( simParams->freeEnergyOn )
00797 masterServerObject->addClient(new GlobalMasterFreeEnergy());
00798 if ( simParams->colvarsOn )
00799 masterServerObject->addClient(new GlobalMasterColvars());
00800
00801 }
00802
00803 if ( !myNode && simParams->IMDon && simParams->IMDignore ) {
00804
00805 new GlobalMasterIMD();
00806 }
00807
00808 #ifdef NAMD_CUDA
00809 bool deviceIsMine = ( cuda_device_pe() == CkMyPe() );
00810 #endif
00811
00812 for (int i=0; i < map->nComputes; i++)
00813 {
00814 if ( ! ( i % 100 ) )
00815 {
00816 }
00817 #ifdef NAMD_CUDA
00818 switch ( map->type(i) )
00819 {
00820 case computeNonbondedSelfType:
00821 case computeNonbondedPairType:
00822 if ( ! deviceIsMine ) continue;
00823 if ( ! cuda_device_shared_with_pe(map->computeData[i].node) ) continue;
00824 break;
00825 case computeNonbondedCUDAType:
00826 if ( ! deviceIsMine ) continue;
00827 default:
00828 if ( map->computeData[i].node != myNode ) continue;
00829 }
00830 #else
00831 if ( map->computeData[i].node != myNode ) continue;
00832 #endif
00833 DebugM(1,"Compute " << i << '\n');
00834 DebugM(1," node = " << map->computeData[i].node << '\n');
00835 DebugM(1," type = " << map->computeData[i].type << '\n');
00836 DebugM(1," numPids = " << map->computeData[i].numPids << '\n');
00837 DebugM(1," numPidsAllocated = " << map->computeData[i].numPidsAllocated << '\n');
00838 for (int j=0; j < map->computeData[i].numPids; j++)
00839 {
00840
00841 if (!((j+1) % 6))
00842 DebugM(1,'\n');
00843 }
00844 DebugM(1,"\n---------------------------------------");
00845 DebugM(1,"---------------------------------------\n");
00846
00847 createCompute(i, map);
00848
00849 }
00850
00851 #ifdef NAMD_CUDA
00852 if ( computeNonbondedCUDAObject ) {
00853 computeNonbondedCUDAObject->assignPatches();
00854 }
00855 #endif
00856
00857 }
00858
00859 #if 0
00860 void ComputeMgr:: sendComputeGlobalConfig(ComputeGlobalConfigMsg *msg)
00861 {
00862 (CProxy_ComputeMgr(CkpvAccess(BOCclass_group).computeMgr)).recvComputeGlobalConfig(msg);
00863 }
00864
00865 void ComputeMgr:: recvComputeGlobalConfig(ComputeGlobalConfigMsg *msg)
00866 {
00867 if ( computeGlobalObject )
00868 {
00869 computeGlobalObject->recvConfig(msg);
00870 }
00871 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00872 else NAMD_die("ComputeMgr::computeGlobalObject is NULL!");
00873 }
00874 #endif
00875
00876 void ComputeMgr:: sendComputeGlobalData(ComputeGlobalDataMsg *msg)
00877 {
00878 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
00879 cm[0].recvComputeGlobalData(msg);
00880 }
00881
00882 void ComputeMgr:: recvComputeGlobalData(ComputeGlobalDataMsg *msg)
00883 {
00884 if (masterServerObject)
00885 {
00886 masterServerObject->recvData(msg);
00887 }
00888 else NAMD_die("ComputeMgr::masterServerObject is NULL!");
00889 }
00890
00891 void ComputeMgr:: sendComputeGlobalResults(ComputeGlobalResultsMsg *msg)
00892 {
00893 (CProxy_ComputeMgr(CkpvAccess(BOCclass_group).computeMgr)).recvComputeGlobalResults(msg);
00894 }
00895
00896 void ComputeMgr:: recvComputeGlobalResults(ComputeGlobalResultsMsg *msg)
00897 {
00898 if ( computeGlobalObject )
00899 {
00900 CmiEnableUrgentSend(1);
00901 computeGlobalObject->recvResults(msg);
00902 CmiEnableUrgentSend(0);
00903 }
00904 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00905 else NAMD_die("ComputeMgr::computeGlobalObject is NULL!");
00906 }
00907
00908
00909
00910
00911 void ComputeMgr:: sendComputeEwaldData(ComputeEwaldMsg *msg)
00912 {
00913 if (computeEwaldObject)
00914 {
00915 int node = computeEwaldObject->getMasterNode();
00916 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
00917 cm[node].recvComputeEwaldData(msg);
00918 }
00919 else if (!PatchMap::Object()->numHomePatches())
00920 {
00921 CkPrintf("skipping message on Pe(%d)\n", CkMyPe());
00922 delete msg;
00923 }
00924 else NAMD_die("ComputeMgr::computeEwaldObject is NULL!");
00925 }
00926
00927 void ComputeMgr:: recvComputeEwaldData(ComputeEwaldMsg *msg)
00928 {
00929 if (computeEwaldObject)
00930 computeEwaldObject->recvData(msg);
00931 else NAMD_die("ComputeMgr::computeEwaldObject in recvData is NULL!");
00932 }
00933
00934 void ComputeMgr:: sendComputeEwaldResults(ComputeEwaldMsg *msg)
00935 {
00936 (CProxy_ComputeMgr(CkpvAccess(BOCclass_group).computeMgr)).recvComputeEwaldResults(msg);
00937 }
00938
00939 void ComputeMgr::recvComputeEwaldResults(ComputeEwaldMsg *msg)
00940 {
00941 if (computeEwaldObject) {
00942 CmiEnableUrgentSend(1);
00943 computeEwaldObject->recvResults(msg);
00944 CmiEnableUrgentSend(0);
00945 }
00946 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00947 else NAMD_die("ComputeMgr::computeEwaldObject in recvResults is NULL!");
00948 }
00949
00950 void ComputeMgr:: sendComputeDPMEData(ComputeDPMEDataMsg *msg)
00951 {
00952 if ( computeDPMEObject )
00953 {
00954 #ifdef DPME
00955 int node = computeDPMEObject->getMasterNode();
00956 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
00957 cm.recvComputeDPMEData(msg,node);
00958 #endif
00959 }
00960 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00961 else NAMD_die("ComputeMgr::computeDPMEObject is NULL!");
00962 }
00963
00964 void ComputeMgr:: recvComputeDPMEData(ComputeDPMEDataMsg *msg)
00965 {
00966 if ( computeDPMEObject )
00967 {
00968 #ifdef DPME
00969 computeDPMEObject->recvData(msg);
00970 #endif
00971 }
00972 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00973 else NAMD_die("ComputeMgr::computeDPMEObject is NULL!");
00974 }
00975
00976 void ComputeMgr:: sendComputeDPMEResults(ComputeDPMEResultsMsg *msg, int node)
00977 {
00978 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
00979 cm[node].recvComputeDPMEResults(msg);
00980 }
00981
00982 void ComputeMgr:: recvComputeDPMEResults(ComputeDPMEResultsMsg *msg)
00983 {
00984 if ( computeDPMEObject )
00985 {
00986 #ifdef DPME
00987 computeDPMEObject->recvResults(msg);
00988 #endif
00989 }
00990 else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
00991 else NAMD_die("ComputeMgr::computeDPMEObject is NULL!");
00992 }
00993
00994 void ComputeMgr::recvComputeConsForceMsg(ComputeConsForceMsg *msg)
00995 {
00996 Molecule *m = Node::Object()->molecule;
00997 delete [] m->consForceIndexes;
00998 delete [] m->consForce;
00999 int n = msg->aid.size();
01000 if (n > 0)
01001 {
01002 m->consForceIndexes = new int32[m->numAtoms];
01003 m->consForce = new Vector[n];
01004 int i;
01005 for (i=0; i<m->numAtoms; i++) m->consForceIndexes[i] = -1;
01006 for (i=0; i<msg->aid.size(); i++)
01007 {
01008 m->consForceIndexes[msg->aid[i]] = i;
01009 m->consForce[i] = msg->f[i];
01010 }
01011 }
01012 else
01013 {
01014 m->consForceIndexes = NULL;
01015 m->consForce = NULL;
01016 }
01017 delete msg;
01018 }
01019
01020 void ComputeMgr::sendYieldDevice(int pe) {
01021 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
01022 cm[pe].recvYieldDevice(CkMyPe());
01023 }
01024
01025 void ComputeMgr::recvYieldDevice(int pe) {
01026 #ifdef NAMD_CUDA
01027 computeNonbondedCUDAObject->recvYieldDevice(pe);
01028 #endif
01029 }
01030
01031 void ComputeMgr::sendBuildCudaForceTable() {
01032 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
01033 int pe = CkNodeFirst(CkMyNode());
01034 int end = pe + CkNodeSize(CkMyNode());
01035 for( ; pe != end; ++pe ) {
01036 cm[pe].recvBuildCudaForceTable();
01037 }
01038 }
01039
01040 #ifdef NAMD_CUDA
01041 void build_cuda_force_table();
01042 #endif
01043
01044 void ComputeMgr::recvBuildCudaForceTable() {
01045 #ifdef NAMD_CUDA
01046 build_cuda_force_table();
01047 #endif
01048 }
01049
01050 class NonbondedCUDASlaveMsg : public CMessage_NonbondedCUDASlaveMsg {
01051 public:
01052 int index;
01053 ComputeNonbondedCUDA *master;
01054 };
01055
01056 void ComputeMgr::sendCreateNonbondedCUDASlave(int pe, int index) {
01057 NonbondedCUDASlaveMsg *msg = new NonbondedCUDASlaveMsg;
01058 msg->master = computeNonbondedCUDAObject;
01059 msg->index = index;
01060 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
01061 cm[pe].recvCreateNonbondedCUDASlave(msg);
01062 }
01063
01064 void ComputeMgr::recvCreateNonbondedCUDASlave(NonbondedCUDASlaveMsg *msg) {
01065 #ifdef NAMD_CUDA
01066 new ComputeNonbondedCUDA(msg->master->cid,this,msg->master,msg->index);
01067 #endif
01068 }
01069
01070 void ComputeMgr::sendNonbondedCUDASlaveReady(int pe, int np, int ac, int seq) {
01071 CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
01072 cm[pe].recvNonbondedCUDASlaveReady(np,ac,seq);
01073 }
01074
01075 void ComputeMgr::recvNonbondedCUDASlaveReady(int np, int ac, int seq) {
01076 for ( int i=0; i<np; ++i ) {
01077 computeNonbondedCUDAObject->patchReady(-1,ac,seq);
01078 }
01079 }
01080
01081 void ComputeMgr::sendNonbondedCUDASlaveEnqueue(ComputeNonbondedCUDA *c, int pe, int seq, int prio, int ws) {
01082 if ( ws == 2 && c->localHostedPatches.size() == 0 ) return;
01083 LocalWorkMsg *msg = ( ws == 1 ? c->localWorkMsg : c->localWorkMsg2 );
01084 msg->compute = c;
01085 int type = c->type();
01086 int cid = c->cid;
01087 SET_PRIORITY(msg,seq,prio);
01088 CProxy_WorkDistrib wdProxy(CkpvAccess(BOCclass_group).workDistrib);
01089 wdProxy[pe].enqueueCUDA(msg);
01090 }
01091
01092 #include "ComputeMgr.def.h"
01093