--- trunk/OOPSE/libmdtools/SimSetup.cpp 2004/06/01 17:15:43 1212 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2004/06/01 18:42:58 1214 @@ -171,8 +171,8 @@ void SimSetup::makeMolecules(void){ int i, j, k; int exI, exJ, exK, exL, slI, slJ; int tempI, tempJ, tempK, tempL; - int molI; - int stampID, atomOffset, rbOffset; + int molI, globalID; + int stampID, atomOffset, rbOffset, groupOffset; molInit molInfo; DirectionalAtom* dAtom; RigidBody* myRB; @@ -216,6 +216,16 @@ void SimSetup::makeMolecules(void){ for (k = 0; k < nInfo; k++){ the_ff->setSimInfo(&(info[k])); +#ifdef IS_MPI + info[k].globalGroupMembership = new int[mpiSim->getNAtomsGlobal()]; + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = 0; +#else + info[k].globalGroupMembership = new int[info[k].n_atoms]; + for (i = 0; i < info[k].n_atoms; i++) + info[k].globalGroupMembership[i] = 0; +#endif + atomOffset = 0; groupOffset = 0; @@ -282,9 +292,7 @@ void SimSetup::makeMolecules(void){ molInfo.myAtoms[j]->setType(currentAtom->getType()); #ifdef IS_MPI - molInfo.myAtoms[j]->setGlobalIndex(globalAtomIndex[j + atomOffset]); - #endif // is_mpi } @@ -506,7 +514,12 @@ void SimSetup::makeMolecules(void){ nMembers = currentCutoffGroup->getNMembers(); myCutoffGroup = new CutoffGroup(); + +#ifdef IS_MPI myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); +#else + myCutoffGroup->setGlobalIndex(j + groupOffset); +#endif for (int cg = 0; cg < nMembers; cg++) { @@ -517,37 +530,42 @@ void SimSetup::makeMolecules(void){ tempI = molI + atomOffset; #ifdef IS_MPI - globalID = info[k].atoms[tempI]->getGlobalIndex() + globalID = info[k].atoms[tempI]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; #else globalID = info[k].atoms[tempI]->getIndex(); + info[k].globalGroupMembership[globalID] = j + groupOffset; #endif + - globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; - + myCutoffGroup->addAtom(info[k].atoms[tempI]); - + cutoffAtomSet.insert(tempI); } - + molInfo.myCutoffGroups.push_back(myCutoffGroup); groupOffset++; }//end for (j = 0; j < molInfo.nCutoffGroups; j++) - + //creat a cutoff group for every atom in current molecule which does not belong to cutoffgroup defined at mdl file - + for(j = 0; j < molInfo.nAtoms; j++){ - + if(cutoffAtomSet.find(molInfo.myAtoms[j]->getIndex()) == cutoffAtomSet.end()){ myCutoffGroup = new CutoffGroup(); myCutoffGroup->addAtom(molInfo.myAtoms[j]); - myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); -#ifdef IS_MPI - globalID = info[k].atoms[atomOffset + j]->getGlobalIndex() -#else + +#ifdef IS_MPI + myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); + globalID = info[k].atoms[atomOffset + j]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; +#else + myCutoffGroup->setGlobalIndex(j + groupOffset); globalID = info[k].atoms[atomOffset + j]->getIndex(); + info[k].globalGroupMembership[globalID] = j+groupOffset; #endif - globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; molInfo.myCutoffGroups.push_back(myCutoffGroup); groupOffset++; } @@ -641,13 +659,39 @@ void SimSetup::makeMolecules(void){ theTorsions); info[k].molecules[i].initialize(molInfo); - - + + atomOffset += molInfo.nAtoms; delete[] theBonds; delete[] theBends; delete[] theTorsions; - } + } + + + +#ifdef IS_MPI + // Since the globalGroupMembership has been zero filled and we've only + // poked values into the atoms we know, we can do an Allreduce + // to get the full globalGroupMembership array (We think). + // This would be prettier if we could use MPI_IN_PLACE like the MPI-2 + // docs said we could. + + int* ggMjunk = new int[mpiSim->getNAtomsGlobal()]; + + MPI_Allreduce(info[k].globalGroupMembership, + ggMjunk, + mpiSim->getNAtomsGlobal(), + MPI_INT, MPI_SUM, MPI_COMM_WORLD); + + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = ggMjunk[i]; + + delete[] ggMjunk; + +#endif + + + } #ifdef IS_MPI @@ -1609,6 +1653,7 @@ void SimSetup::mpiMolDivide(void){ mpiSim->divideLabor(); globalAtomIndex = mpiSim->getGlobalAtomIndex(); + globalGroupIndex = mpiSim->getGlobalGroupIndex(); //globalMolIndex = mpiSim->getGlobalMolIndex(); // set up the local variables