ParallelIOMgr Class Reference

#include <ParallelIOMgr.h>

List of all members.

Public Member Functions

 ParallelIOMgr ()
 ~ParallelIOMgr ()
void initialize (Node *node)
void readPerAtomInfo ()
void migrateAtomsMGrp ()
void recvAtomsMGrp (MoveInputAtomsMsg *msg)
void integrateMigratedAtoms ()
void updateMolInfo ()
void recvMolInfo (MolInfoMsg *msg)
void bcastMolInfo (MolInfoMsg *msg)
void recvHydroBasedCounter (HydroBasedMsg *msg)
void bcastHydroBasedCounter (HydroBasedMsg *msg)
void calcAtomsInEachPatch ()
void recvAtomsCntPerPatch (AtomsCntPerPatchMsg *msg)
void sendAtomsToHomePatchProcs ()
void ackAtomsToHomePatchProcs ()
void recvAtomsToHomePatchProcs (MovePatchAtomsMsg *msg)
void createHomePatches ()
void freeMolSpace ()
int getNumOutputProcs ()
bool isOutputProcessor (int pe)
void recvClusterSize (ClusterSizeMsg *msg)
void integrateClusterSize ()
void recvFinalClusterSize (ClusterSizeMsg *msg)
void receivePositions (CollectVectorVarMsg *msg)
void receiveVelocities (CollectVectorVarMsg *msg)
void receiveForces (CollectVectorVarMsg *msg)
void disposePositions (int seq, double prevT)
void disposeVelocities (int seq, double prevT)
void disposeForces (int seq, double prevT)
void wrapCoor (int seq, Lattice lat)
void recvClusterCoor (ClusterCoorMsg *msg)
void recvFinalClusterCoor (ClusterCoorMsg *msg)

Public Attributes

CthThread sendAtomsThread
int numAcksOutstanding


Detailed Description

Definition at line 152 of file ParallelIOMgr.h.


Constructor & Destructor Documentation

ParallelIOMgr::ParallelIOMgr (  ) 

Definition at line 29 of file ParallelIOMgr.C.

References sendAtomsThread, Vector::x, Vector::y, and Vector::z.

00030 {
00031     CkpvAccess(BOCclass_group).ioMgr = thisgroup;
00032 
00033     numInputProcs=-1;
00034     inputProcArray = NULL;
00035     numOutputProcs=-1;
00036     outputProcArray = NULL;
00037 
00038     procsReceived=0;
00039     hydroMsgRecved=0;
00040 
00041     totalMV.x = totalMV.y = totalMV.z = 0.0;
00042     totalMass = 0.0;
00043     totalCharge = 0.0;
00044     numTotalExclusions = 0;
00045     numCalcExclusions = 0;
00046     numCalcFullExclusions = 0;
00047 
00048     isOKToRecvHPAtoms = false;
00049     hpAtomsList = NULL;
00050 
00051     clusterID = NULL;
00052     clusterSize = NULL;
00053 
00054 #ifdef MEM_OPT_VERSION
00055     midCM = NULL;
00056 #endif
00057 
00058     isWater = NULL;
00059 
00060     numCSMAck = 0;
00061     numReqRecved = 0;
00062 
00063     sendAtomsThread = 0;
00064 
00065 #if COLLECT_PERFORMANCE_DATA
00066     numFixedAtomLookup = 0;
00067 #endif
00068 }

ParallelIOMgr::~ParallelIOMgr (  ) 

Definition at line 70 of file ParallelIOMgr.C.

00071 {
00072     delete [] inputProcArray;
00073     delete [] outputProcArray;
00074     delete [] clusterID;
00075     delete [] clusterSize;
00076 
00077 #ifdef MEM_OPT_VERSION
00078     delete midCM;
00079 #endif
00080 
00081     delete [] isWater;
00082 }


Member Function Documentation

void ParallelIOMgr::ackAtomsToHomePatchProcs (  ) 

Definition at line 1350 of file ParallelIOMgr.C.

References numAcksOutstanding, and sendAtomsThread.

01351 {
01352   --numAcksOutstanding;
01353   if ( sendAtomsThread ) {
01354     CthAwaken(sendAtomsThread);
01355     sendAtomsThread = 0;
01356   }
01357 }

void ParallelIOMgr::bcastHydroBasedCounter ( HydroBasedMsg msg  ) 

Definition at line 1050 of file ParallelIOMgr.C.

References endi(), SimParameters::fixedAtomsOn, iINFO(), iout, SimParameters::lattice, Molecule::maxHydrogenGroupSize, Molecule::maxMigrationGroupSize, Molecule::num_deg_freedom(), Molecule::numAngles, Molecule::numAtoms, Molecule::numBonds, Molecule::numCrossterms, Molecule::numDihedrals, Molecule::numExclusions, Molecule::numFixedAtoms, HydroBasedMsg::numFixedGroups, Molecule::numFixedGroups, HydroBasedMsg::numFixedRigidBonds, Molecule::numFixedRigidBonds, Molecule::numHydrogenGroups, Molecule::numImpropers, Molecule::numMigrationGroups, Molecule::numMultipleDihedrals, Molecule::numMultipleImpropers, Molecule::numRigidBonds, SimParameters::paraTypeCharmmOn, SimParameters::paraTypeXplorOn, SimParameters::rigidBonds, and Lattice::volume().

01050                                                             {
01051 #ifdef MEM_OPT_VERSION
01052     //only the rank 0 in the SMP node update the Molecule object
01053     if(CmiMyRank()) {
01054         delete msg;
01055         return;
01056     }
01057     molecule->numFixedRigidBonds = msg->numFixedRigidBonds;
01058     molecule->numFixedGroups = msg->numFixedGroups;
01059     delete msg;
01060 
01061     if(!CkMyPe()) {
01062         iout << iINFO << "****************************\n";
01063         iout << iINFO << "STRUCTURE SUMMARY:\n";
01064         iout << iINFO << molecule->numAtoms << " ATOMS\n";
01065         iout << iINFO << molecule->numBonds << " BONDS\n";
01066         iout << iINFO << molecule->numAngles << " ANGLES\n";
01067         iout << iINFO << molecule->numDihedrals << " DIHEDRALS\n";
01068         iout << iINFO << molecule->numImpropers << " IMPROPERS\n";
01069         iout << iINFO << molecule->numCrossterms << " CROSSTERMS\n";
01070         iout << iINFO << molecule->numExclusions << " EXCLUSIONS\n";
01071 
01072             //****** BEGIN CHARMM/XPLOR type changes
01073         if ((molecule->numMultipleDihedrals) && (simParameters->paraTypeXplorOn)){
01074             iout << iINFO << molecule->numMultipleDihedrals 
01075              << " DIHEDRALS WITH MULTIPLE PERIODICITY (BASED ON PSF FILE)\n";
01076         }
01077         if ((molecule->numMultipleDihedrals) && (simParameters->paraTypeCharmmOn)){
01078             iout << iINFO << molecule->numMultipleDihedrals 
01079          << " DIHEDRALS WITH MULTIPLE PERIODICITY IGNORED (BASED ON PSF FILE) \n";
01080             iout << iINFO  
01081          << " CHARMM MULTIPLICITIES BASED ON PARAMETER FILE INFO! \n";
01082         }
01083             //****** END CHARMM/XPLOR type changes
01084 
01085         if (molecule->numMultipleImpropers){
01086             iout << iINFO << molecule->numMultipleImpropers 
01087                  << " IMPROPERS WITH MULTIPLE PERIODICITY\n";
01088         }
01089 
01090         if (simParameters->fixedAtomsOn)
01091            iout << iINFO << molecule->numFixedAtoms << " FIXED ATOMS\n";
01092         
01093 
01094         if (simParameters->rigidBonds)        
01095            iout << iINFO << molecule->numRigidBonds << " RIGID BONDS\n";        
01096 
01097         if (simParameters->fixedAtomsOn && simParameters->rigidBonds)        
01098            iout << iINFO << molecule->numFixedRigidBonds <<
01099                 " RIGID BONDS BETWEEN FIXED ATOMS\n";
01100 
01101         iout << iINFO << molecule->num_deg_freedom(1)
01102              << " DEGREES OF FREEDOM\n";
01103 
01104         iout << iINFO << molecule->numHydrogenGroups << " HYDROGEN GROUPS\n";
01105         iout << iINFO << molecule->maxHydrogenGroupSize
01106             << " ATOMS IN LARGEST HYDROGEN GROUP\n";
01107         iout << iINFO << molecule->numMigrationGroups << " MIGRATION GROUPS\n";
01108         iout << iINFO << molecule->maxMigrationGroupSize
01109             << " ATOMS IN LARGEST MIGRATION GROUP\n";
01110         if (simParameters->fixedAtomsOn)
01111         {
01112            iout << iINFO << molecule->numFixedGroups <<
01113                 " HYDROGEN GROUPS WITH ALL ATOMS FIXED\n";
01114         }
01115         
01116         iout << iINFO << "TOTAL MASS = " << totalMass << " amu\n"; 
01117         iout << iINFO << "TOTAL CHARGE = " << totalCharge << " e\n"; 
01118 
01119         BigReal volume = simParameters->lattice.volume();
01120         if ( volume ) {
01121             iout << iINFO << "MASS DENSITY = "
01122                 << ((totalMass/volume) / 0.6022) << " g/cm^3\n";
01123             iout << iINFO << "ATOM DENSITY = "
01124                 << (molecule->numAtoms/volume) << " atoms/A^3\n";
01125         }
01126     
01127         iout << iINFO << "*****************************\n";
01128         iout << endi;
01129         fflush(stdout);               
01130     }
01131 #endif
01132 }

void ParallelIOMgr::bcastMolInfo ( MolInfoMsg msg  ) 

Definition at line 991 of file ParallelIOMgr.C.

References SimParameters::comMove, endi(), iINFO(), iout, MolInfoMsg::numAngles, Molecule::numAngles, MolInfoMsg::numBonds, Molecule::numBonds, MolInfoMsg::numCalcAngles, Molecule::numCalcAngles, MolInfoMsg::numCalcBonds, Molecule::numCalcBonds, MolInfoMsg::numCalcCrossterms, Molecule::numCalcCrossterms, MolInfoMsg::numCalcDihedrals, Molecule::numCalcDihedrals, MolInfoMsg::numCalcExclusions, Molecule::numCalcExclusions, MolInfoMsg::numCalcFullExclusions, Molecule::numCalcFullExclusions, MolInfoMsg::numCalcImpropers, Molecule::numCalcImpropers, MolInfoMsg::numCrossterms, Molecule::numCrossterms, MolInfoMsg::numDihedrals, Molecule::numDihedrals, MolInfoMsg::numExclusions, MolInfoMsg::numImpropers, Molecule::numImpropers, MolInfoMsg::numRigidBonds, Molecule::numRigidBonds, Molecule::numTotalExclusions, PDBVELFACTOR, ResizeArray< Elem >::size(), MolInfoMsg::totalMass, and MolInfoMsg::totalMV.

00992 {
00993 #ifdef MEM_OPT_VERSION
00994     if(myInputRank!=-1) {
00995         if(!simParameters->comMove) {
00996             //needs to remove the center of mass motion from a molecule
00997             Vector val = msg->totalMV / msg->totalMass;
00998             for (int i=0; i<initAtoms.size(); i++) initAtoms[i].velocity -= val;
00999         }
01000     }
01001 
01002     //only the rank 0 in the SMP node update the Molecule object
01003     if(CmiMyRank()) {
01004         delete msg;
01005         return;
01006     }
01007 
01008     molecule->numBonds = msg->numBonds;
01009     molecule->numCalcBonds = msg->numCalcBonds;
01010     molecule->numAngles = msg->numAngles;
01011     molecule->numCalcAngles = msg->numCalcAngles;
01012     molecule->numDihedrals = msg->numDihedrals;
01013     molecule->numCalcDihedrals = msg->numCalcDihedrals;
01014     molecule->numImpropers = msg->numImpropers;
01015     molecule->numCalcImpropers = msg->numCalcImpropers;
01016     molecule->numCrossterms = msg->numCrossterms;
01017     molecule->numCalcCrossterms = msg->numCalcCrossterms;
01018 
01019     molecule->numTotalExclusions = msg->numExclusions;
01020     molecule->numCalcExclusions = msg->numCalcExclusions;
01021     molecule->numCalcFullExclusions = msg->numCalcFullExclusions;
01022 
01023     molecule->numRigidBonds = msg->numRigidBonds;
01024     delete msg;
01025 
01026     if(!CkMyPe()) {
01027         iout << iINFO << "LOADED " << molecule->numTotalExclusions << " TOTAL EXCLUSIONS\n" << endi;
01028         if(!simParameters->comMove) {
01029             iout << iINFO << "REMOVING COM VELOCITY "
01030                  << (PDBVELFACTOR * (msg->totalMV / msg->totalMass))<< "\n" <<endi;
01031         }
01032     }
01033 #endif
01034 }

void ParallelIOMgr::calcAtomsInEachPatch (  ) 

Definition at line 1134 of file ParallelIOMgr.C.

References PatchMap::assignToPatch(), SimParameters::fixedAtomsOn, PatchMap::getTmpPatchAtomsList(), PatchMap::initTmpPatchAtomsList(), SimParameters::lattice, PatchMap::numPatches(), numPatches, PatchMap::Object(), and ResizeArray< Elem >::size().

01135 {
01136     if(myInputRank==-1) return;
01137 
01138     PatchMap *patchMap = PatchMap::Object();
01139     int numPatches = patchMap->numPatches();
01140 
01141     patchMap->initTmpPatchAtomsList();
01142 
01143     //each list contains the atom index to the initAtoms
01144     vector<int> *eachPatchAtomList = patchMap->getTmpPatchAtomsList();
01145 
01146     CProxy_PatchMgr pm(CkpvAccess(BOCclass_group).patchMgr);
01147     PatchMgr *patchMgr = pm.ckLocalBranch();
01148 
01149     int pid=0;
01150     const Lattice lattice = simParameters->lattice;
01151     for(int i=0; i<initAtoms.size(); i++) {
01152         InputAtom *atom = &(initAtoms[i]);
01153         if(!atom->isValid) continue;
01154         if(atom->isMP) {
01155             pid = patchMap->assignToPatch(atom->position, lattice);
01156         }
01157         eachPatchAtomList[pid].push_back(i);
01158     }
01159 
01160     CProxy_ParallelIOMgr pIO(thisgroup);
01161 
01162     int patchCnt = 0;
01163     for(int i=0; i<numPatches; i++) {
01164         int cursize = eachPatchAtomList[i].size();
01165         if(cursize>0) patchCnt++;
01166     }
01167 
01168     AtomsCntPerPatchMsg *msg = NULL;
01169     if(simParameters->fixedAtomsOn) {
01170         msg = new (patchCnt, patchCnt, patchCnt, 0)AtomsCntPerPatchMsg;
01171     } else {
01172         msg = new (patchCnt, patchCnt, 0, 0)AtomsCntPerPatchMsg;
01173     }
01174 
01175     msg->length = patchCnt;
01176     patchCnt = 0;
01177     for(int i=0; i<numPatches; i++) {
01178         int cursize = eachPatchAtomList[i].size();
01179         if(cursize>0) {
01180             if ( cursize > USHRT_MAX ) {
01181               char errstr[512];
01182               sprintf(errstr, "Patch %d exceeds %d atoms.", i, USHRT_MAX);
01183               NAMD_die(errstr);
01184             }
01185             msg->pidList[patchCnt] = i;
01186             msg->atomsCntList[patchCnt] = cursize;
01187             patchCnt++;
01188         }
01189     }
01190 
01191     if(simParameters->fixedAtomsOn) {
01192         patchCnt = 0;
01193         for(int i=0; i<numPatches; i++) {
01194             int cursize = eachPatchAtomList[i].size();
01195             if(cursize>0) {
01196                 int fixedCnt = 0;
01197                 for(int j=0; j<cursize; j++) {
01198                     int aid = eachPatchAtomList[i][j];
01199                     //atomFixed is either 0 or 1
01200                     fixedCnt += initAtoms[aid].atomFixed;
01201                 }
01202                 msg->fixedAtomsCntList[patchCnt] = fixedCnt;
01203                 patchCnt++;
01204             }
01205         }
01206     }
01207 
01208     pIO[0].recvAtomsCntPerPatch(msg);
01209 
01210 }

void ParallelIOMgr::createHomePatches (  ) 

Definition at line 1423 of file ParallelIOMgr.C.

References ResizeArray< Elem >::begin(), ResizeArray< Elem >::clear(), PatchMgr::createHomePatch(), ResizeArray< Elem >::end(), PatchMap::node(), PatchMap::numPatches(), PatchMap::numPatchesOnNode(), Node::Object(), PatchMap::Object(), ResizeArray< Elem >::size(), and Node::workDistrib.

01424 {
01425 #ifdef MEM_OPT_VERSION
01426 
01427     int assignedPids = PatchMap::Object()->numPatchesOnNode(CkMyPe());
01428     int numPids = hpIDList.size();
01429     if(numPids==0){
01430         //this node actually contains no homepatches
01431         if(assignedPids == 0) return; 
01432 
01433         //Entering the rare condition that all the homepatches this node has
01434         //are empty so that "recvAtomsToHomePatchProcs" is never called!
01435         //But we still need to create those empty homepatches!
01436         CmiAssert(isOKToRecvHPAtoms == false);        
01437         PatchMap *patchMap = PatchMap::Object();
01438         CProxy_PatchMgr pm(CkpvAccess(BOCclass_group).patchMgr);
01439         PatchMgr *patchMgr = pm.ckLocalBranch();
01440         for(int i=0; i<patchMap->numPatches(); i++) {
01441             if(patchMap->node(i)==CkMyPe()) {
01442                 FullAtomList emptyone;
01443                 patchMgr->createHomePatch(i, emptyone);
01444             }
01445         }        
01446         return;
01447     }
01448 
01449     CProxy_PatchMgr pm(CkpvAccess(BOCclass_group).patchMgr);
01450     PatchMgr *patchMgr = pm.ckLocalBranch();
01451 
01452     //go through the home patch list
01453     for(int i=0; i<numPids; i++) {
01454         int pid = hpIDList[i];
01455 
01456         //re-sort the atom list of this patch
01457         std::sort(hpAtomsList[i].begin(), hpAtomsList[i].end());
01458         Node::Object()->workDistrib->fillAtomListForOnePatch(pid, hpAtomsList[i]);
01459         patchMgr->createHomePatch(pid, hpAtomsList[i]);
01460     }
01461 
01462     hpIDList.clear();   
01463     delete [] hpAtomsList;
01464 
01465     hpAtomsList = NULL;
01466 #endif
01467 }

void ParallelIOMgr::disposeForces ( int  seq,
double  prevT 
)

Definition at line 1620 of file ParallelIOMgr.C.

01621 {
01622 #ifdef MEM_OPT_VERSION
01623         double iotime = CmiWallTimer();
01624     midCM->disposeForces(seq);
01625         iotime = CmiWallTimer()-iotime+prevT;
01626     
01627 #if OUTPUT_SINGLE_FILE
01628         //Token-based file output
01629     if(myOutputRank==getMyOutputGroupHighestRank()) {
01630         //notify the CollectionMaster to start the next round
01631         CProxy_CollectionMaster cm(mainMaster);
01632         cm.startNextRoundOutputForce(iotime);
01633     } else {
01634         CProxy_ParallelIOMgr io(thisgroup);
01635         io[outputProcArray[myOutputRank+1]].disposeForces(seq, iotime);
01636     }
01637 #else
01638         //notify the CollectionMaster to start the next round
01639         CProxy_CollectionMaster cm(mainMaster);
01640         cm.startNextRoundOutputForce(iotime);   
01641 #endif
01642 
01643 #endif
01644 }

void ParallelIOMgr::disposePositions ( int  seq,
double  prevT 
)

Definition at line 1568 of file ParallelIOMgr.C.

01569 {
01570 #ifdef MEM_OPT_VERSION
01571         double iotime = CmiWallTimer();
01572     midCM->disposePositions(seq);
01573         iotime = CmiWallTimer()-iotime+prevT;
01574 
01575 #if OUTPUT_SINGLE_FILE    
01576         //Token-based file output
01577     if(myOutputRank == getMyOutputGroupHighestRank()) {
01578         //notify the CollectionMaster to start the next round
01579         CProxy_CollectionMaster cm(mainMaster);
01580         cm.startNextRoundOutputPos(iotime);
01581     } else {
01582         CProxy_ParallelIOMgr io(thisgroup);
01583         io[outputProcArray[myOutputRank+1]].disposePositions(seq, iotime);
01584     }
01585 #else
01586         //notify the CollectionMaster to start the next round
01587         CProxy_CollectionMaster cm(mainMaster);
01588         cm.startNextRoundOutputPos(iotime);
01589 #endif
01590 
01591 #endif
01592 }

void ParallelIOMgr::disposeVelocities ( int  seq,
double  prevT 
)

Definition at line 1594 of file ParallelIOMgr.C.

01595 {
01596 #ifdef MEM_OPT_VERSION
01597         double iotime = CmiWallTimer();
01598     midCM->disposeVelocities(seq);
01599         iotime = CmiWallTimer()-iotime+prevT;
01600     
01601 #if OUTPUT_SINGLE_FILE
01602         //Token-based file output
01603     if(myOutputRank==getMyOutputGroupHighestRank()) {
01604         //notify the CollectionMaster to start the next round
01605         CProxy_CollectionMaster cm(mainMaster);
01606         cm.startNextRoundOutputVel(iotime);
01607     } else {
01608         CProxy_ParallelIOMgr io(thisgroup);
01609         io[outputProcArray[myOutputRank+1]].disposeVelocities(seq, iotime);
01610     }
01611 #else
01612         //notify the CollectionMaster to start the next round
01613         CProxy_CollectionMaster cm(mainMaster);
01614         cm.startNextRoundOutputVel(iotime);     
01615 #endif
01616 
01617 #endif
01618 }

void ParallelIOMgr::freeMolSpace (  ) 

Definition at line 1469 of file ParallelIOMgr.C.

References SimParameters::freeEnergyOn.

01470 {
01471 #ifdef MEM_OPT_VERSION
01472     molecule->delAtomNames();
01473     molecule->delChargeSpace();
01474 
01475     //???TODO NOT SURE WHETHER freeEnergyOn is support in MEM_OPT_VERSION
01476     //-CHAOMEI
01477     if(!CkMyPe() && !simParameters->freeEnergyOn)
01478         molecule->delMassSpace();
01479 
01480     molecule->delFixedAtoms();
01481 #endif
01482 }

int ParallelIOMgr::getNumOutputProcs (  )  [inline]

Definition at line 376 of file ParallelIOMgr.h.

00376 { return numOutputProcs; }

void ParallelIOMgr::initialize ( Node node  ) 

Definition at line 89 of file ParallelIOMgr.C.

References UniqueSet< Elem >::clear(), endi(), CollectionMgr::getMasterChareID(), iINFO(), iout, Node::molecule, NAMD_bug(), SimParameters::numinputprocs, SimParameters::numoutputprocs, SimParameters::numoutputwrts, CollectionMgr::Object(), WorkDistrib::peDiffuseOrdering, ResizeArray< Elem >::resize(), and Node::simParameters.

00090 {
00091     simParameters = node->simParameters;
00092     molecule = node->molecule;
00093 
00094     numInputProcs = simParameters->numinputprocs;
00095     numOutputProcs = simParameters->numoutputprocs;
00096     numOutputWrts = simParameters->numoutputwrts;
00097 
00098 
00099     if(!CkMyPe()) {
00100         iout << iINFO << "Running with " <<numInputProcs<<" input processors.\n"<<endi;
00101         #if OUTPUT_SINGLE_FILE
00102         iout << iINFO << "Running with " <<numOutputProcs<<" output processors ("<<numOutputWrts<<" of them will output simultaneously).\n"<<endi;
00103         #else
00104         iout << iINFO << "Running with " <<numOutputProcs<<" output processors, and each of them will output to its own separate file.\n"<<endi;
00105         #endif
00106     }
00107 
00108     //build inputProcArray
00109    {
00110     inputProcArray = new int[numInputProcs];
00111     myInputRank = -1;
00112     for(int i=0; i<numInputProcs; ++i) {
00113       inputProcArray[i] = WorkDistrib::peDiffuseOrdering[(1+numOutputProcs+i)%CkNumPes()];
00114     }
00115     std::sort(inputProcArray, inputProcArray+numInputProcs);
00116     for(int i=0; i<numInputProcs; ++i) {
00117       if ( CkMyPe() == inputProcArray[i] ) {
00118         if ( myInputRank != -1 ) NAMD_bug("Duplicate input proc");
00119         myInputRank = i;
00120       }
00121     }
00122 
00123     if(!CkMyPe()) {
00124       iout << iINFO << "INPUT PROC LOCATIONS:";
00125       int i;
00126       for ( i=0; i<numInputProcs && i < 10; ++i ) {
00127         iout << " " << inputProcArray[i];
00128       }
00129       if ( i<numInputProcs ) iout << " ... " << inputProcArray[numInputProcs-1];
00130       iout << "\n" << endi;
00131     }
00132    }
00133 
00134     if(myInputRank!=-1) {
00135         //NOTE: this could further be optimized by pre-allocate the memory
00136         //for incoming atoms --Chao Mei
00137         int numMyAtoms = numInitMyAtomsOnInput();
00138         initAtoms.resize(numMyAtoms+100);  // extra space for orphan hydrogens
00139         initAtoms.resize(numMyAtoms);
00140         tmpRecvAtoms.resize(0);
00141     } else {
00142         initAtoms.resize(0);
00143         tmpRecvAtoms.resize(0);
00144     }
00145     hpIDList.resize(0);
00146 
00147     //build outputProcArray
00148     //spread the output processors across all the processors
00149    {
00150     outputProcArray = new int[numOutputProcs];
00151     outputProcFlags = new char[CkNumPes()];
00152     myOutputRank = -1;
00153     for(int i=0; i<numOutputProcs; ++i) {
00154       outputProcArray[i] = WorkDistrib::peDiffuseOrdering[(1+i)%CkNumPes()];
00155     }
00156     std::sort(outputProcArray, outputProcArray+numOutputProcs);
00157     for(int i=0; i<CkNumPes(); ++i) {
00158       outputProcFlags[i] = 0;
00159     }
00160     for(int i=0; i<numOutputProcs; ++i) {
00161       outputProcFlags[outputProcArray[i]] = 1;
00162       if ( CkMyPe() == outputProcArray[i] ) {
00163         if ( myOutputRank != -1 ) NAMD_bug("Duplicate output proc");
00164         myOutputRank = i;
00165       }
00166     }
00167 
00168     if(!CkMyPe()) {
00169       iout << iINFO << "OUTPUT PROC LOCATIONS:";
00170       int i;
00171       for ( i=0; i<numOutputProcs && i < 10; ++i ) {
00172         iout << " " << outputProcArray[i];
00173       }
00174       if ( i<numOutputProcs ) iout << " ... " << outputProcArray[numOutputProcs-1];
00175       iout << "\n" << endi;
00176     }
00177    }
00178 
00179 #ifdef MEM_OPT_VERSION
00180     if(myOutputRank!=-1) {
00181         midCM = new CollectionMidMaster(this);
00182     }
00183     remoteClusters.clear();
00184     csmBuf.resize(0);
00185     remoteCoors.clear();
00186     ccmBuf.resize(0);
00187 
00188     mainMaster = CollectionMgr::Object()->getMasterChareID();
00189 #endif
00190 }

void ParallelIOMgr::integrateClusterSize (  ) 

Definition at line 521 of file ParallelIOMgr.C.

References recvFinalClusterSize(), ResizeArray< Elem >::resize(), ResizeArray< Elem >::size(), SimParameters::wrapAll, and SimParameters::wrapWater.

00522 {
00523     if(myOutputRank==-1) return;
00524     if(!(simParameters->wrapAll || simParameters->wrapWater)) return;
00525 
00526     int fromIdx, toIdx; //atoms' range
00527     getMyAtomsRangeOnOutput(fromIdx,toIdx);
00528 
00529     //calculated the final cluster size
00530     for(int i=0; i<csmBuf.size(); i++) {
00531         ClusterSizeMsg *msg = csmBuf[i];
00532         int lidx = msg->clusterId - fromIdx;
00533         clusterSize[lidx] += msg->atomsCnt;
00534     }
00535 
00536     CProxy_ParallelIOMgr pIO(thisgroup);
00537     for(int i=0; i<csmBuf.size(); i++) {
00538         ClusterSizeMsg *msg = csmBuf[i];
00539         int lidx = msg->clusterId - fromIdx;
00540         msg->atomsCnt = clusterSize[lidx];
00541         pIO[outputProcArray[msg->srcRank]].recvFinalClusterSize(msg);
00542     }
00543     numRemoteReqs = csmBuf.size();
00544     csmBuf.resize(0);
00545     
00546     //There's a possible msg race problem here that recvFinalClusterSize 
00547     //executes before integrateClusterSize because other proc finishes faster
00548     //in calculating the cluster size. The recvFinalClusterSize should be
00549     //executed after integrateClusterSize. To avoid this, a self message is
00550     //sent to participate the reduction.
00551     if(numRemoteClusters!=0){
00552         recvFinalClusterSize(NULL);
00553     }else{
00554         //this output proc already has the final cluster size for each atom
00555         int numMyAtoms = toIdx-fromIdx+1;
00556         for(int i=0; i<numMyAtoms; i++) {
00557             int lidx = clusterID[i]-fromIdx;
00558             clusterSize[i] = clusterSize[lidx];
00559         }
00560         
00561         #if 0 //write out cluster debug info
00562         char fname[128];
00563         sprintf(fname, "cluster.par.%d", CkMyPe());
00564         FILE *ofp = fopen(fname, "w");
00565         for(int i=0; i<numMyAtoms; i++) {
00566             fprintf(ofp, "%d: %d: %d\n", i+fromIdx, clusterID[i], clusterSize[i]);
00567         }
00568         fclose(ofp);
00569         #endif
00570     }
00571 }

void ParallelIOMgr::integrateMigratedAtoms (  ) 

Definition at line 680 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add(), ResizeArray< Elem >::begin(), ResizeArray< Elem >::clear(), ResizeArray< Elem >::end(), j, Molecule::numFixedAtoms, HydroBasedMsg::numFixedGroups, HydroBasedMsg::numFixedRigidBonds, Molecule::numRigidBonds, and ResizeArray< Elem >::size().

00681 {
00682     if(myInputRank==-1) return;
00683 
00684     for(int i=0; i<tmpRecvAtoms.size(); i++) {
00685         tmpRecvAtoms[i].isValid = true;
00686         initAtoms.add(tmpRecvAtoms[i]);
00687     }
00688     tmpRecvAtoms.clear();
00689 
00690     //sort atom list based on hydrogenList value
00691     std::sort(initAtoms.begin(), initAtoms.end());
00692 
00693     //now compute the counters inside Molecule such as numFixedRigidBonds
00694     //which is based on the hydrogen group info
00695 
00696     int numFixedRigidBonds = 0;
00697     if(molecule->numRigidBonds){
00698         int parentIsFixed = 0;
00699         for(int i=0; i<initAtoms.size(); i++) {
00700             InputAtom *one = &(initAtoms[i]);
00701             if(!one->isValid) continue;
00702             if(one->isGP) {
00703                 parentIsFixed = one->atomFixed;
00704                 InputAtom *a1 = &(initAtoms[i+1]);
00705                 InputAtom *a2 = &(initAtoms[i+2]);
00706                 if((one->rigidBondLength>0.0) &&
00707                    a1->atomFixed && a2->atomFixed) {
00708                     numFixedRigidBonds++;
00709                 }
00710             }else{
00711                 if((one->rigidBondLength>0.0) &&
00712                    one->atomFixed && parentIsFixed) {
00713                     numFixedRigidBonds++;
00714                 }
00715             }
00716         }
00717     }
00718 
00719     int numFixedGroups = 0;
00720     if(molecule->numFixedAtoms){        
00721         for(int i=0; i<initAtoms.size();) {
00722             InputAtom *one = &(initAtoms[i]);
00723             if(!one->isValid){
00724                 i++;
00725                 continue;
00726             }
00727             if(one->isGP) {
00728                 int allFixed = 1;                
00729                 for(int j=0; j<one->hydrogenGroupSize; j++){
00730                     InputAtom *a1 = &(initAtoms[i+j]);
00731                     allFixed = allFixed & a1->atomFixed;
00732                     if(!allFixed) break;
00733                 }
00734                 if(allFixed) numFixedGroups++;                
00735                 i += one->hydrogenGroupSize;
00736             }
00737         }
00738     }
00739     
00740     CProxy_ParallelIOMgr pIO(thisgroup);
00741     HydroBasedMsg *msg = new HydroBasedMsg;
00742     msg->numFixedGroups = numFixedGroups;
00743     msg->numFixedRigidBonds = numFixedRigidBonds;
00744     pIO[0].recvHydroBasedCounter(msg);
00745 }

bool ParallelIOMgr::isOutputProcessor ( int  pe  ) 

Definition at line 192 of file ParallelIOMgr.C.

00192                                             {
00193    return outputProcFlags[pe];
00194 }

void ParallelIOMgr::migrateAtomsMGrp (  ) 

Definition at line 620 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add(), ResizeArray< Elem >::begin(), ResizeArray< Elem >::clear(), and ResizeArray< Elem >::size().

00621 {
00622     if(myInputRank==-1) return;
00623 
00624     //1. first get the list of atoms to be migrated
00625     //which should be few compared with the number of atoms
00626     //initially assigned to this input proc.
00627     AtomIDList toMigrateList; //the list of atoms to be migrated
00628     //the max distance from this processor of atoms to be sent
00629     int maxOffset = 0;
00630     for(int i=0; i<initAtoms.size(); i++) {
00631         //returns the proc id on which atom MPID resides on
00632         int parentRank = atomInitRankOnInput(initAtoms[i].MPID);
00633         if(parentRank != myInputRank) {
00634             toMigrateList.add(i);
00635             initAtoms[i].isValid = false;
00636             int tmp = parentRank - myInputRank;
00637             tmp = tmp>0 ? tmp : -tmp;
00638             if(tmp > maxOffset) maxOffset = tmp;
00639         }
00640     }
00641 
00642     //2. prepare atom migration messages
00643     //the messages are indexed as [-maxOffset,..., -1,0,1,..., maxOffset]
00644     //where the "0" is not used at all. It is added for the sake of
00645     //computing the index easily.
00646     InputAtomList *migLists = new InputAtomList[2*maxOffset+1];
00647     for(int i=0; i<toMigrateList.size(); i++) {
00648         int idx = toMigrateList[i];
00649         int parentRank = atomInitRankOnInput(initAtoms[idx].MPID);
00650         //decide which migList to put this atom
00651         int offset = parentRank - myInputRank + maxOffset;
00652         migLists[offset].add(initAtoms[idx]);
00653     }
00654 
00655     CProxy_ParallelIOMgr pIO(thisgroup);
00656     for(int i=0; i<2*maxOffset+1; i++) {
00657         int migLen = migLists[i].size();
00658         if(migLen>0) {
00659             MoveInputAtomsMsg *msg = new (migLen, 0)MoveInputAtomsMsg;
00660             msg->length = migLen;
00661             memcpy(msg->atomList, migLists[i].begin(), sizeof(InputAtom)*migLen);
00662             int destRank = i-maxOffset+myInputRank;
00663             pIO[inputProcArray[destRank]].recvAtomsMGrp(msg);
00664             migLists[i].clear();
00665         }
00666     }
00667     
00668     toMigrateList.clear();
00669     delete [] migLists;
00670 }

void ParallelIOMgr::readPerAtomInfo (  ) 

Definition at line 202 of file ParallelIOMgr.C.

References j, SimParameters::wrapAll, and SimParameters::wrapWater.

00203 {
00204 #ifdef MEM_OPT_VERSION
00205     if(myInputRank!=-1) {
00206         int myAtomLIdx, myAtomUIdx;
00207         getMyAtomsInitRangeOnInput(myAtomLIdx, myAtomUIdx);
00208 
00209         //1. read the file that contains per-atom info such as signature index
00210         molecule->read_binary_atom_info(myAtomLIdx, myAtomUIdx, initAtoms);
00211 
00212         //2. read coordinates and velocities of each atom if the velocity file
00213         //exists, otherwise, the velocity of each atom is randomly generated.
00214         //This has to be DONE AFTER THE FIRST STEP as the atom mass is required
00215         //if the velocity is generated randomly.
00216         readCoordinatesAndVelocity();
00217 
00218         //3. set every atom's output processor rank, i.e. the dest pe this
00219         //atom will be sent for writing positions and velocities etc.
00220         int oRank=atomRankOnOutput(myAtomLIdx);
00221         for(int i=oRank; i<numOutputProcs; i++) {
00222             int lIdx, uIdx; //indicates the range of atom ids outputProcArray[i] has
00223             getAtomsRangeOnOutput(lIdx, uIdx, i);
00224             if(lIdx > myAtomUIdx) break;
00225             int fid = lIdx>myAtomLIdx?lIdx:myAtomLIdx;
00226             int tid = uIdx>myAtomUIdx?myAtomUIdx:uIdx;
00227             for(int j=fid; j<=tid; j++) initAtoms[j-myAtomLIdx].outputRank = i;
00228         }
00229     }
00230 
00231     //read clusters
00232     if(myOutputRank!=-1) {
00233         //only when wrapAll or wrapWater is set, cluster info is required
00234         if(!(simParameters->wrapAll || simParameters->wrapWater)) return;
00235         readInfoForParOutput();
00236     }
00237 #endif
00238 }

void ParallelIOMgr::receiveForces ( CollectVectorVarMsg msg  ) 

Definition at line 1555 of file ParallelIOMgr.C.

References CollectVectorVarMsg::seq.

01556 {
01557 #ifdef MEM_OPT_VERSION
01558     int ready = midCM->receiveForces(msg);
01559     if(ready) {
01560         CProxy_CollectionMaster cm(mainMaster);
01561         cm.receiveOutputForceReady(msg->seq);        
01562     }
01563     delete msg;
01564 #endif
01565 }

void ParallelIOMgr::receivePositions ( CollectVectorVarMsg msg  ) 

Definition at line 1531 of file ParallelIOMgr.C.

References CollectVectorVarMsg::seq.

01532 {
01533 #ifdef MEM_OPT_VERSION
01534     int ready = midCM->receivePositions(msg);
01535     if(ready) {
01536         CProxy_CollectionMaster cm(mainMaster);
01537         cm.receiveOutputPosReady(msg->seq);
01538     }
01539     delete msg;
01540 #endif
01541 }

void ParallelIOMgr::receiveVelocities ( CollectVectorVarMsg msg  ) 

Definition at line 1543 of file ParallelIOMgr.C.

References CollectVectorVarMsg::seq.

01544 {
01545 #ifdef MEM_OPT_VERSION
01546     int ready = midCM->receiveVelocities(msg);
01547     if(ready) {
01548         CProxy_CollectionMaster cm(mainMaster);
01549         cm.receiveOutputVelReady(msg->seq);        
01550     }
01551     delete msg;
01552 #endif
01553 }

void ParallelIOMgr::recvAtomsCntPerPatch ( AtomsCntPerPatchMsg msg  ) 

Definition at line 1212 of file ParallelIOMgr.C.

References AtomsCntPerPatchMsg::atomsCntList, endi(), AtomsCntPerPatchMsg::fixedAtomsCntList, SimParameters::fixedAtomsOn, iINFO(), iout, AtomsCntPerPatchMsg::length, NAMD_die(), Molecule::numAtoms, PatchMap::numPatches(), Node::Object(), PatchMap::Object(), and AtomsCntPerPatchMsg::pidList.

01213 {
01214 #ifdef MEM_OPT_VERSION
01215     PatchMap *patchMap = PatchMap::Object();
01216     for(int i=0; i<msg->length; i++) {
01217         int pid = msg->pidList[i];
01218         int oldNum = patchMap->numAtoms(pid);
01219         if ( oldNum + msg->atomsCntList[i] > USHRT_MAX ) {
01220           char errstr[512];
01221           sprintf(errstr, "Patch %d exceeds %d atoms.", pid, USHRT_MAX);
01222           NAMD_die(errstr);
01223         }
01224         patchMap->setNumAtoms(pid, oldNum+msg->atomsCntList[i]);
01225         if(simParameters->fixedAtomsOn) {
01226             oldNum = patchMap->numFixedAtoms(pid);
01227             patchMap->setNumFixedAtoms(pid, oldNum+msg->fixedAtomsCntList[i]);
01228         }
01229     }
01230     delete msg;
01231 
01232     if(++procsReceived == numInputProcs) {
01233         //print max PATCH info
01234         int maxAtoms = -1;
01235         int maxPatch = -1;
01236         int totalAtoms = 0;
01237         for(int i=0; i<patchMap->numPatches(); i++) {
01238             int cnt = patchMap->numAtoms(i);
01239             totalAtoms += cnt;
01240             if(cnt>maxAtoms) {
01241                 maxAtoms = cnt;
01242                 maxPatch = i;
01243             }
01244         }
01245         procsReceived = 0;
01246         iout << iINFO << "LARGEST PATCH (" << maxPatch <<
01247              ") HAS " << maxAtoms << " ATOMS\n" << endi;
01248         if ( totalAtoms !=  Node::Object()->molecule->numAtoms ) {
01249           char errstr[512];
01250           sprintf(errstr, "Incorrect atom count in void ParallelIOMgr::recvAtomsCntPerPatch: %d vs %d", totalAtoms, Node::Object()->molecule->numAtoms);
01251           NAMD_die(errstr);
01252         }
01253     }
01254 #endif
01255 }

void ParallelIOMgr::recvAtomsMGrp ( MoveInputAtomsMsg msg  ) 

Definition at line 672 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add(), MoveInputAtomsMsg::atomList, and MoveInputAtomsMsg::length.

00673 {
00674     for(int i=0; i<msg->length; i++) {
00675         tmpRecvAtoms.add((msg->atomList)[i]);
00676     }
00677     delete msg;
00678 }

void ParallelIOMgr::recvAtomsToHomePatchProcs ( MovePatchAtomsMsg msg  ) 

Definition at line 1359 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add(), MovePatchAtomsMsg::allAtoms, MovePatchAtomsMsg::from, j, MovePatchAtomsMsg::patchCnt, MovePatchAtomsMsg::pidList, ResizeArray< Elem >::size(), and MovePatchAtomsMsg::sizeList.

01360 {
01361     CProxy_ParallelIOMgr pIO(thisgroup);
01362     pIO[msg->from].ackAtomsToHomePatchProcs();
01363 
01364     if(!isOKToRecvHPAtoms) {
01365         prepareHomePatchAtomList();
01366         isOKToRecvHPAtoms = true;
01367     }
01368 
01369     int numRecvPatches = msg->patchCnt;
01370     int aid = 0;
01371     for(int i=0; i<numRecvPatches; i++) {
01372         int pid = msg->pidList[i];
01373         int size = msg->sizeList[i];
01374         int idx = binaryFindHPID(pid);
01375         for(int j=0; j<size; j++, aid++) {
01376             hpAtomsList[idx].add(msg->allAtoms[aid]);
01377         }
01378     }
01379     //CkPrintf("Pe %d recvAtomsToHomePatchProcs for %d patches %d atoms\n",CkMyPe(),numRecvPatches,aid);
01380     delete msg;
01381 }

void ParallelIOMgr::recvClusterCoor ( ClusterCoorMsg msg  ) 

Definition at line 1721 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add().

Referenced by wrapCoor().

01721                                                       {
01722     //only add the msg from remote procs
01723     if(msg!=NULL) ccmBuf.add(msg);
01724 
01725     //include a msg sent by itself
01726     if(++numReqRecved == (numRemoteReqs+1)){
01727         numReqRecved = 0;
01728         integrateClusterCoor();
01729     }
01730 }

void ParallelIOMgr::recvClusterSize ( ClusterSizeMsg msg  ) 

Definition at line 513 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add().

00514 {
00515     csmBuf.add(msg); //added to buffer for reuse to send back to src
00516 
00517     //update cluster size has to be delayed to integration to prevent
00518     //data racing where the clusterSize has not been created!
00519 }

void ParallelIOMgr::recvFinalClusterCoor ( ClusterCoorMsg msg  ) 

Definition at line 1793 of file ParallelIOMgr.C.

References UniqueSet< Elem >::clear(), ClusterCoorElem::clusterId, ClusterCoorMsg::clusterId, ClusterCoorMsg::dsum, ClusterCoorElem::dsum, UniqueSet< Elem >::find(), ResizeArray< Elem >::size(), Lattice::wrap_delta(), Lattice::wrap_nearest_delta(), SimParameters::wrapAll, and SimParameters::wrapNearest.

01793                                                            {
01794 #ifdef MEM_OPT_VERSION
01795     if(msg!=NULL){
01796         //only process the message sent from other procs!
01797         ClusterCoorElem one(msg->clusterId);
01798         ClusterCoorElem *ret = remoteCoors.find(one);
01799         ret->dsum = msg->dsum;
01800         delete msg;
01801     }
01802     
01803     if(++numCSMAck == (numRemoteClusters+1)){        
01804         //final wrap coor computation
01805         int fromIdx = coorInstance->fromAtomID;
01806         int toIdx = coorInstance->toAtomID;
01807         int numMyAtoms = toIdx-fromIdx+1;
01808         ResizeArray<Vector> &data = coorInstance->data;
01809         ResizeArray<FloatVector> &fdata = coorInstance->fdata;
01810         ClusterCoorElem tmp;
01811         for(int i=0; i<numMyAtoms; i++){
01812             if(!simParameters->wrapAll && !isWater[i]) continue;
01813             int cid = clusterID[i];
01814             int lidx = cid-fromIdx;
01815             if(lidx<0){
01816                 //this cid should be inside remoteCoors
01817                 tmp.clusterId = cid;
01818                 ClusterCoorElem *fone = remoteCoors.find(tmp);
01819                 if(data.size()) data[i] += fone->dsum; 
01820                 if(fdata.size()) fdata[i] = fdata[i] + fone->dsum; 
01821             }else{
01822                 if(lidx==i){
01823                     Lattice *lat = &(coorInstance->lattice);
01824                     Vector coni = tmpCoorCon[lidx]/clusterSize[lidx];
01825                     tmpCoorCon[lidx] = (simParameters->wrapNearest ?
01826                     lat->wrap_nearest_delta(coni) : lat->wrap_delta(coni));
01827                 }
01828                 if(data.size()) data[i] += tmpCoorCon[lidx]; 
01829                 if(fdata.size()) fdata[i] = fdata[i] + tmpCoorCon[lidx];
01830             }
01831         }
01832 
01833         delete [] tmpCoorCon;
01834         tmpCoorCon = NULL;
01835         CProxy_CollectionMaster cm(mainMaster);
01836         cm.wrapCoorFinished();
01837         numCSMAck = 0;
01838         remoteCoors.clear();
01839     }
01840 #endif
01841 }

void ParallelIOMgr::recvFinalClusterSize ( ClusterSizeMsg msg  ) 

Definition at line 573 of file ParallelIOMgr.C.

References ClusterSizeMsg::atomsCnt, ClusterElem::atomsCnt, UniqueSet< Elem >::clear(), ClusterElem::clusterId, ClusterSizeMsg::clusterId, and UniqueSet< Elem >::find().

Referenced by integrateClusterSize().

00574 {
00575     //only process the message sent by other procs
00576     if(msg!=NULL) {
00577         //indicating a message from other procs
00578         ClusterElem one(msg->clusterId);
00579         ClusterElem *ret = remoteClusters.find(one);
00580         CmiAssert(ret!=NULL);
00581         ret->atomsCnt = msg->atomsCnt;
00582     }
00583     delete msg;
00584 
00585     //include a msg sent by itself for reduction
00586     if(++numCSMAck == (numRemoteClusters+1)) {
00587         //recved all the msgs needed to update the cluster size for each atom finally
00588         int fromIdx, toIdx; //atoms' range
00589         getMyAtomsRangeOnOutput(fromIdx,toIdx);
00590         int numMyAtoms = toIdx-fromIdx+1;
00591         ClusterElem tmp;
00592         for(int i=0; i<numMyAtoms; i++) {
00593             int cid = clusterID[i];
00594             int lidx = cid-fromIdx;
00595             if(lidx<0) {
00596                 //this cid should be inside remoteClusters
00597                 tmp.clusterId = cid;
00598                 ClusterElem *fone = remoteClusters.find(tmp);
00599                 clusterSize[i] = fone->atomsCnt;
00600             } else {
00601                 clusterSize[i] = clusterSize[lidx];
00602             }
00603         }
00604         numCSMAck = 0;
00605         remoteClusters.clear();
00606 
00607 #if 0 //write out cluster debug info
00608         char fname[128];
00609         sprintf(fname, "cluster.par.%d", CkMyPe());
00610         FILE *ofp = fopen(fname, "w");
00611         for(int i=0; i<numMyAtoms; i++) {
00612             fprintf(ofp, "%d: %d: %d\n", i+fromIdx, clusterID[i], clusterSize[i]);
00613         }
00614         fclose(ofp);
00615 #endif
00616 
00617     }
00618 }

void ParallelIOMgr::recvHydroBasedCounter ( HydroBasedMsg msg  ) 

Definition at line 1037 of file ParallelIOMgr.C.

References HydroBasedMsg::numFixedGroups, Molecule::numFixedGroups, HydroBasedMsg::numFixedRigidBonds, and Molecule::numFixedRigidBonds.

01037                                                            {
01038     molecule->numFixedRigidBonds += msg->numFixedRigidBonds;
01039     molecule->numFixedGroups += msg->numFixedGroups;
01040 
01041     if(++hydroMsgRecved == numInputProcs){
01042         msg->numFixedRigidBonds = molecule->numFixedRigidBonds;
01043         msg->numFixedGroups = molecule->numFixedGroups;
01044         CProxy_ParallelIOMgr pIO(thisgroup);
01045         pIO.bcastHydroBasedCounter(msg);
01046         hydroMsgRecved = 0;
01047     }else delete msg;
01048 }

void ParallelIOMgr::recvMolInfo ( MolInfoMsg msg  ) 

Definition at line 935 of file ParallelIOMgr.C.

References SimParameters::comMove, MolInfoMsg::numAngles, Molecule::numAngles, MolInfoMsg::numBonds, Molecule::numBonds, MolInfoMsg::numCalcAngles, Molecule::numCalcAngles, MolInfoMsg::numCalcBonds, Molecule::numCalcBonds, MolInfoMsg::numCalcCrossterms, Molecule::numCalcCrossterms, MolInfoMsg::numCalcDihedrals, Molecule::numCalcDihedrals, MolInfoMsg::numCalcExclusions, MolInfoMsg::numCalcFullExclusions, MolInfoMsg::numCalcImpropers, Molecule::numCalcImpropers, MolInfoMsg::numCrossterms, Molecule::numCrossterms, MolInfoMsg::numDihedrals, Molecule::numDihedrals, MolInfoMsg::numExclusions, MolInfoMsg::numImpropers, Molecule::numImpropers, MolInfoMsg::numRigidBonds, Molecule::numRigidBonds, MolInfoMsg::totalCharge, MolInfoMsg::totalMass, and MolInfoMsg::totalMV.

00936 {
00937     molecule->numBonds += msg->numBonds;
00938     molecule->numCalcBonds += msg->numCalcBonds;
00939     molecule->numAngles += msg->numAngles;
00940     molecule->numCalcAngles += msg->numCalcAngles;
00941     molecule->numDihedrals += msg->numDihedrals;
00942     molecule->numCalcDihedrals += msg->numCalcDihedrals;
00943     molecule->numImpropers += msg->numImpropers;
00944     molecule->numCalcImpropers += msg->numCalcImpropers;
00945     molecule->numCrossterms += msg->numCrossterms;
00946     molecule->numCalcCrossterms += msg->numCalcCrossterms;
00947     numTotalExclusions += msg->numExclusions;
00948     numCalcExclusions += msg->numCalcExclusions;
00949     numCalcFullExclusions += msg->numCalcFullExclusions;
00950     molecule->numRigidBonds += msg->numRigidBonds;
00951 
00952     totalMass += msg->totalMass;
00953     totalCharge += msg->totalCharge;
00954 
00955     if(!simParameters->comMove) {
00956         totalMV += msg->totalMV;        
00957     }
00958 
00959     if(++procsReceived == numInputProcs) {
00960         //received all the counters
00961         msg->numBonds = molecule->numBonds;
00962         msg->numCalcBonds = molecule->numCalcBonds;
00963         msg->numAngles = molecule->numAngles;
00964         msg->numCalcAngles = molecule->numCalcAngles;
00965         msg->numDihedrals = molecule->numDihedrals;
00966         msg->numCalcDihedrals = molecule->numCalcDihedrals;
00967         msg->numImpropers = molecule->numImpropers;
00968         msg->numCalcImpropers = molecule->numCalcImpropers;
00969         msg->numCrossterms = molecule->numCrossterms;
00970         msg->numCalcCrossterms = molecule->numCalcCrossterms;
00971         msg->numExclusions = numTotalExclusions/2;
00972         msg->numCalcExclusions = numCalcExclusions/2;
00973         msg->numCalcFullExclusions = numCalcFullExclusions/2;
00974         msg->numRigidBonds = molecule->numRigidBonds;
00975 
00976         msg->totalMass = totalMass;
00977         msg->totalCharge = totalCharge;
00978 
00979         if(!simParameters->comMove) {
00980             msg->totalMV = totalMV;            
00981         }
00982 
00983         CProxy_ParallelIOMgr pIO(thisgroup);
00984         pIO.bcastMolInfo(msg);
00985 
00986         //reset to 0 for the next p2p-based reduction on input procs
00987         procsReceived = 0;
00988     } else delete msg;
00989 }

void ParallelIOMgr::sendAtomsToHomePatchProcs (  ) 

Definition at line 1262 of file ParallelIOMgr.C.

References ResizeArray< Elem >::add(), MovePatchAtomsMsg::allAtoms, ResizeArray< Elem >::begin(), call_sendAtomsToHomePatchProcs(), ResizeArray< Elem >::clear(), PatchMap::delTmpPatchAtomsList(), MovePatchAtomsMsg::from, PatchMap::getTmpPatchAtomsList(), j, PatchMap::node(), numAcksOutstanding, PatchMap::numPatches(), PatchMap::Object(), MovePatchAtomsMsg::patchCnt, MovePatchAtomsMsg::pidList, sendAtomsThread, ResizeArray< Elem >::size(), and MovePatchAtomsMsg::sizeList.

01263 {
01264 #ifdef MEM_OPT_VERSION
01265     if(myInputRank==-1) return;
01266 
01267     if ( sendAtomsThread == 0 ) {
01268       sendAtomsThread = CthCreate((CthVoidFn)call_sendAtomsToHomePatchProcs,this,0);
01269       CthAwaken(sendAtomsThread);
01270       return;
01271     }
01272     sendAtomsThread = 0;
01273     numAcksOutstanding = 0;
01274 
01275     PatchMap *patchMap = PatchMap::Object();
01276     int numPatches = patchMap->numPatches();
01277     vector<int> *eachPatchAtomList = patchMap->getTmpPatchAtomsList();
01278 
01279     //each element (proc) contains the list of ids of patches which will stay
01280     //on that processor
01281     ResizeArray<int> *procList = new ResizeArray<int>[CkNumPes()];
01282     ResizeArray<int> pesToSend;
01283     for(int i=0; i<numPatches; i++) {
01284         if(eachPatchAtomList[i].size()==0) continue;
01285         int onPE = patchMap->node(i);
01286         if ( procList[onPE].size() == 0 ) pesToSend.add(onPE);
01287         procList[onPE].add(i);
01288     }
01289 
01290     Random(CkMyPe()).reorder(pesToSend.begin(),pesToSend.size());
01291     //CkPrintf("Pe %d ParallelIOMgr::sendAtomsToHomePatchProcs sending to %d pes\n",CkMyPe(),pesToSend.size());
01292 
01293     //go over every processor to send a message if necessary
01294     //TODO: Optimization for local home patches to save temp memory usage??? -CHAOMEI
01295     CProxy_ParallelIOMgr pIO(thisgroup);
01296     for(int k=0; k<pesToSend.size(); k++) {
01297         const int i = pesToSend[k];
01298         int len = procList[i].size();
01299         if(len==0) continue;
01300 
01301         if ( numAcksOutstanding >= 10 ) {
01302           //CkPrintf("Pe %d ParallelIOMgr::sendAtomsToHomePatchProcs suspending at %d of %d pes\n",CkMyPe(),k,pesToSend.size());
01303           //fflush(stdout);
01304           sendAtomsThread = CthSelf();
01305           CthSuspend();
01306         }
01307         ++numAcksOutstanding;
01308 
01309         //prepare a message to send
01310         int patchCnt = len;
01311         int totalAtomCnt = 0;
01312         for(int j=0; j<len; j++) {
01313             int pid = procList[i][j];
01314             int atomCnt = eachPatchAtomList[pid].size();
01315             totalAtomCnt += atomCnt;
01316         }
01317 
01318         MovePatchAtomsMsg *msg = new (patchCnt, patchCnt, totalAtomCnt, 0)MovePatchAtomsMsg;
01319         msg->from = CkMyPe();
01320         msg->patchCnt = patchCnt;
01321         int atomIdx = 0;
01322         for(int j=0; j<len; j++) {
01323             int pid = procList[i][j];
01324             int atomCnt = eachPatchAtomList[pid].size();
01325             msg->pidList[j] = pid;
01326             msg->sizeList[j] = atomCnt;
01327             for(int k=0; k<atomCnt; k++, atomIdx++) {
01328                 int aid = eachPatchAtomList[pid][k];
01329                 FullAtom one = initAtoms[aid];
01330                 //HACK to re-sort the atom list after receiving the atom list on
01331                 //home patch processor -Chao Mei
01332                 one.hydVal = initAtoms[aid].hydList;
01333                 msg->allAtoms[atomIdx] = one;
01334             }
01335         }
01336         pIO[i].recvAtomsToHomePatchProcs(msg);
01337 
01338         procList[i].clear();
01339     }
01340 
01341     //clean up to free space
01342     delete [] procList;
01343     patchMap->delTmpPatchAtomsList();
01344 
01345     //free the space occupied by the list that contains the input atoms
01346     initAtoms.clear();
01347 #endif
01348 }

void ParallelIOMgr::updateMolInfo (  ) 

Definition at line 747 of file ParallelIOMgr.C.

References AtomSignature::angleCnt, AtomSignature::angleSigs, atomSigPool, AtomSignature::bondCnt, AtomSignature::bondSigs, SimParameters::comMove, AtomSignature::crosstermCnt, AtomSignature::crosstermSigs, AtomSignature::dihedralCnt, AtomSignature::dihedralSigs, SimParameters::fixedAtomsForces, ExclusionSignature::fullExclCnt, ExclusionSignature::fullOffset, AtomSignature::gromacsPairCnt, AtomSignature::gromacsPairSigs, AtomSignature::improperCnt, AtomSignature::improperSigs, j, ExclusionSignature::modExclCnt, ExclusionSignature::modOffset, MolInfoMsg::numAngles, MolInfoMsg::numBonds, MolInfoMsg::numCalcAngles, MolInfoMsg::numCalcBonds, MolInfoMsg::numCalcCrossterms, MolInfoMsg::numCalcDihedrals, MolInfoMsg::numCalcExclusions, MolInfoMsg::numCalcFullExclusions, MolInfoMsg::numCalcImpropers, MolInfoMsg::numCalcLJPairs, MolInfoMsg::numCrossterms, MolInfoMsg::numDihedrals, MolInfoMsg::numExclusions, Molecule::numFixedAtoms, MolInfoMsg::numImpropers, MolInfoMsg::numLJPairs, MolInfoMsg::numRigidBonds, ResizeArray< Elem >::size(), MolInfoMsg::totalCharge, MolInfoMsg::totalMass, MolInfoMsg::totalMV, x, y, and z.

00748 {
00749 #ifdef MEM_OPT_VERSION
00750     if(myInputRank==-1) return;
00751 
00752     CProxy_ParallelIOMgr pIO(thisgroup);
00753 
00754     MolInfoMsg *msg = new MolInfoMsg;
00755     msg->numBonds = msg->numCalcBonds = 0;
00756     msg->numAngles = msg->numCalcAngles = 0;
00757     msg->numDihedrals = msg->numCalcDihedrals = 0;
00758     msg->numImpropers = msg->numCalcImpropers = 0;
00759     msg->numCrossterms = msg->numCalcCrossterms = 0;
00760     msg->numExclusions = msg->numCalcExclusions = 0;
00761     int numFullExclusions = msg->numCalcFullExclusions = 0;
00762     // JLai
00763     msg->numLJPairs = msg->numCalcLJPairs = 0;
00764     // End of JLai
00765     msg->numRigidBonds = 0;
00766     msg->totalMass = 0.0;
00767     msg->totalCharge = 0.0;
00768 
00769     //calculate the tuples this input processor have
00770     AtomSignature *atomSigPool = molecule->atomSigPool;
00771     ExclusionSignature *exclSigPool = molecule->exclSigPool;
00772     for(int i=0; i<initAtoms.size(); i++) {
00773         AtomSignature *thisSig = &atomSigPool[initAtoms[i].sigId];
00774         msg->numBonds += thisSig->bondCnt;
00775         msg->numAngles += thisSig->angleCnt;
00776         msg->numDihedrals += thisSig->dihedralCnt;
00777         msg->numImpropers += thisSig->improperCnt;
00778         msg->numCrossterms += thisSig->crosstermCnt;
00779         // JLai
00780         msg->numLJPairs += thisSig->gromacsPairCnt;
00781         // End of JLai
00782 
00783         ExclusionSignature *exclSig = &exclSigPool[initAtoms[i].exclId];
00784         msg->numExclusions += (exclSig->fullExclCnt + exclSig->modExclCnt);
00785         numFullExclusions += exclSig->fullExclCnt;
00786 
00787         if(initAtoms[i].rigidBondLength > 0.0) msg->numRigidBonds++;
00788 
00789         msg->totalMass += initAtoms[i].mass;
00790         msg->totalCharge += initAtoms[i].charge;
00791     }
00792 
00793     //deal with numCalc* which is related with fixed atoms!
00794     if(molecule->numFixedAtoms>0 && ! simParameters->fixedAtomsForces) {
00795         //if there's fixed atoms, calcExclusions needs to be calculated
00796         //Since it's possible the atom inside the this exclusion set is on
00797         //another input processor, we have to resort to the global fixed atoms
00798         //info inside the Molecule object. The number of such accesses should
00799         //be very small! --Chao Mei
00800         int sAId = initAtoms[0].id;
00801         int remoteCnt=0; //stats info
00802         for(int i=0; i<initAtoms.size(); i++) {
00803             //When all the atoms in the set are fixed, the elem (Bond etc.)
00804             //is not counted as a calc*.
00805             int myAId = initAtoms[i].id;
00806             AtomSignature *thisSig = &atomSigPool[initAtoms[i].sigId];
00807             ExclusionSignature *exclSig = &exclSigPool[initAtoms[i].exclId];
00808             if(!initAtoms[i].atomFixed) {
00809                 msg->numCalcBonds += thisSig->bondCnt;                
00810                 msg->numCalcAngles += thisSig->angleCnt;
00811                 msg->numCalcDihedrals += thisSig->dihedralCnt;
00812                 msg->numCalcImpropers += thisSig->improperCnt;
00813                 msg->numCalcCrossterms += thisSig->crosstermCnt;
00814                 msg->numCalcExclusions+=(exclSig->fullExclCnt+exclSig->modExclCnt);
00815                 msg->numCalcFullExclusions+=(exclSig->fullExclCnt);
00816                 continue;
00817             }
00818                        
00819             //1. Bonds
00820             for(int j=0; j<thisSig->bondCnt; j++) {            
00821                 TupleSignature *bsig = &(thisSig->bondSigs[j]);
00822                 int a1 = myAId + bsig->offset[0];
00823                 if(!isAtomFixed(sAId, a1)) msg->numCalcBonds++;
00824             }
00825             
00826             //2. Angles
00827             for(int j=0; j<thisSig->angleCnt; j++) {            
00828                 TupleSignature *bsig = &(thisSig->angleSigs[j]);
00829                 int a1 = myAId + bsig->offset[0];
00830                 int a2 = myAId + bsig->offset[1];
00831                 if(!isAtomFixed(sAId, a1) || !isAtomFixed(sAId, a2)) 
00832                     msg->numCalcAngles++;
00833             }
00834 
00835             //3. Dihedrals
00836             for(int j=0; j<thisSig->dihedralCnt; j++) {            
00837                 TupleSignature *bsig = &(thisSig->dihedralSigs[j]);
00838                 int a1 = myAId + bsig->offset[0];
00839                 int a2 = myAId + bsig->offset[1];
00840                 int a3 = myAId + bsig->offset[2];
00841                 if(!isAtomFixed(sAId, a1) || 
00842                    !isAtomFixed(sAId, a2) ||
00843                    !isAtomFixed(sAId, a3)) 
00844                     msg->numCalcDihedrals++;
00845             }
00846 
00847             //4. Impropers
00848             for(int j=0; j<thisSig->improperCnt; j++) {            
00849                 TupleSignature *bsig = &(thisSig->improperSigs[j]);
00850                 int a1 = myAId + bsig->offset[0];
00851                 int a2 = myAId + bsig->offset[1];
00852                 int a3 = myAId + bsig->offset[2];
00853                 if(!isAtomFixed(sAId, a1) || 
00854                    !isAtomFixed(sAId, a2) ||
00855                    !isAtomFixed(sAId, a3)) 
00856                     msg->numCalcImpropers++;
00857             }
00858 
00859             //5. Crossterms
00860             for(int j=0; j<thisSig->crosstermCnt; j++) {            
00861                 TupleSignature *bsig = &(thisSig->crosstermSigs[j]);
00862                 int a1 = myAId + bsig->offset[0];
00863                 int a2 = myAId + bsig->offset[1];
00864                 int a3 = myAId + bsig->offset[2];
00865                 int a4 = myAId + bsig->offset[3];
00866                 int a5 = myAId + bsig->offset[4];
00867                 int a6 = myAId + bsig->offset[5];
00868                 int a7 = myAId + bsig->offset[6];
00869 
00870                 if(!isAtomFixed(sAId, a1) || 
00871                    !isAtomFixed(sAId, a2) ||
00872                    !isAtomFixed(sAId, a3) ||
00873                    !isAtomFixed(sAId, a4) ||
00874                    !isAtomFixed(sAId, a5) ||
00875                    !isAtomFixed(sAId, a6) ||
00876                    !isAtomFixed(sAId, a7)) 
00877                     msg->numCalcDihedrals++;
00878             }
00879             
00880             //6: Exclusions            
00881             //this atom is fixed, check atoms in the exclusion set
00882             for(int j=0; j<exclSig->fullExclCnt; j++) {
00883                 int thisAId = exclSig->fullOffset[j]+myAId;
00884                 if(!isAtomFixed(sAId, thisAId)) { msg->numCalcExclusions++; msg->numCalcFullExclusions++; }
00885             }
00886             for(int j=0; j<exclSig->modExclCnt; j++) {
00887                 int thisAId = exclSig->modOffset[j]+myAId;
00888                 if(!isAtomFixed(sAId, thisAId)) msg->numCalcExclusions++;
00889             }
00890 
00891             //7: GromacsPair
00892             for(int j=0; j<thisSig->gromacsPairCnt; j++) {
00893                 TupleSignature *bsig = &(thisSig->gromacsPairSigs[j]);
00894                 int a1 = myAId + bsig->offset[0];
00895                 int a2 = myAId + bsig->offset[1];
00896                 if(!isAtomFixed(sAId, a1) || 
00897                    !isAtomFixed(sAId, a2))
00898                     msg->numCalcLJPairs++;
00899             }
00900         }
00901 #if COLLECT_PERFORMANCE_DATA
00902         printf("Num fixedAtom lookup on proc %d is %d\n", CkMyPe(), numFixedAtomLookup);
00903 #endif
00904     } else {
00905         //no fixed atoms, numCalc* is same with numExclusions
00906         msg->numCalcBonds = msg->numBonds;
00907         msg->numCalcAngles = msg->numAngles;
00908         msg->numCalcDihedrals = msg->numDihedrals;
00909         msg->numCalcImpropers = msg->numImpropers;
00910         msg->numCalcCrossterms = msg->numCrossterms;
00911         msg->numCalcExclusions = msg->numExclusions;
00912         msg->numCalcFullExclusions = numFullExclusions;
00913     }
00914 
00915 
00916     if(!simParameters->comMove) {
00917         //to remove the center of mass motion from a molecule.
00918         //first calculate the values on every input proc, then reduce.
00919         //For more info, refer to WorkDistrib::remove_com_motion
00920         //-Chao Mei
00921         (msg->totalMV).x = 0.0;
00922         (msg->totalMV).y = 0.0;
00923         (msg->totalMV).z = 0.0;
00924         for (int i=0; i<initAtoms.size(); i++) {            
00925             msg->totalMV += initAtoms[i].mass * initAtoms[i].velocity;
00926         }
00927     }
00928 
00929     //always send to the master processor (proc 0)
00930     pIO[0].recvMolInfo(msg);
00931 #endif
00932 }

void ParallelIOMgr::wrapCoor ( int  seq,
Lattice  lat 
)

Definition at line 1647 of file ParallelIOMgr.C.

References UniqueSet< Elem >::add(), UniqueSetIter< T >::begin(), ClusterCoorElem::clusterId, ClusterCoorElem::dsum, UniqueSetIter< T >::end(), UniqueSet< Elem >::find(), recvClusterCoor(), UniqueSet< Elem >::size(), and ResizeArray< Elem >::size().

01648 {
01649 #ifdef MEM_OPT_VERSION
01650     coorInstance = midCM->getReadyPositions(seq);
01651 
01652     coorInstance->lattice = lat; //record the lattice to use for wrapAll/Water!
01653     int fromAtomID = coorInstance->fromAtomID;
01654     int toAtomID = coorInstance->toAtomID;
01655 
01656     //only reference copies
01657     ResizeArray<Vector> &data = coorInstance->data;
01658     ResizeArray<FloatVector> &fdata = coorInstance->fdata;
01659     //if both data and fdata are not empty, they contain exact values, the only
01660     //difference lies in their precisions. Therefore, we only need to compute 
01661     //the higher precision coordinate array. -Chao Mei
01662     int dsize = data.size();    
01663     int numMyAtoms = toAtomID-fromAtomID+1;
01664     tmpCoorCon = new Vector[numMyAtoms];    
01665     ClusterCoorElem one;
01666     //1. compute wrapped coordinates locally 
01667     for(int i=0; i<numMyAtoms; i++){
01668         tmpCoorCon[i] = 0.0;
01669         int cid = clusterID[i];
01670         if(cid<fromAtomID){
01671             //on output procs ahead of me
01672             one.clusterId = cid;
01673             ClusterCoorElem *ret = remoteCoors.find(one);
01674             if(ret==NULL){
01675                 if(dsize==0) 
01676                     one.dsum = fdata[i];
01677                 else 
01678                     one.dsum = data[i];
01679                                 
01680                 remoteCoors.add(one);                 
01681             }else{
01682                 if(dsize==0) 
01683                     ret->dsum += fdata[i];
01684                 else 
01685                     ret->dsum += data[i];               
01686             }
01687         }else{
01688             if(dsize==0) 
01689                 tmpCoorCon[cid-fromAtomID] += fdata[i];
01690             else 
01691                 tmpCoorCon[cid-fromAtomID] += data[i];
01692         }
01693     }
01694 
01695     //2. Prepare to send msgs to remote output procs to reduce coordinates 
01696     //values of a cluster
01697     CmiAssert(numRemoteClusters == remoteCoors.size());
01698     numCSMAck = 0; //set to 0 to prepare recving the final coor update
01699     CProxy_ParallelIOMgr pIO(thisgroup);
01700     ClusterCoorSetIter iter(remoteCoors);
01701     for(iter=iter.begin(); iter!=iter.end(); iter++){
01702         ClusterCoorMsg *msg = new ClusterCoorMsg;
01703         msg->srcRank = myOutputRank;
01704         msg->clusterId = iter->clusterId;
01705         msg->dsum = iter->dsum;
01706         int dstRank = atomRankOnOutput(iter->clusterId);
01707         pIO[outputProcArray[dstRank]].recvClusterCoor(msg);
01708     }
01709     
01710     //Just send a local NULL msg to indicate the local wrapping
01711     //coordinates has finished.
01712     recvClusterCoor(NULL);
01713 #endif
01714 }


Member Data Documentation

int ParallelIOMgr::numAcksOutstanding

Definition at line 365 of file ParallelIOMgr.h.

Referenced by ackAtomsToHomePatchProcs(), and sendAtomsToHomePatchProcs().

CthThread ParallelIOMgr::sendAtomsThread

Definition at line 363 of file ParallelIOMgr.h.

Referenced by ackAtomsToHomePatchProcs(), ParallelIOMgr(), and sendAtomsToHomePatchProcs().


The documentation for this class was generated from the following files:
Generated on Wed Nov 22 01:17:21 2017 for NAMD by  doxygen 1.4.7