--- trunk/OOPSE/libmdtools/mpiSimulation.cpp 2003/04/01 16:50:14 441 +++ trunk/OOPSE/libmdtools/mpiSimulation.cpp 2004/04/14 15:37:41 1108 @@ -1,18 +1,15 @@ #ifdef IS_MPI #include -#include -#include -#include +#include +#include +#include #include -#include #include "mpiSimulation.hpp" #include "simError.h" #include "fortranWrappers.hpp" #include "randomSPRNG.hpp" -#define BASE_SEED 123456789 - mpiSimulation* mpiSim; mpiSimulation::mpiSimulation(SimInfo* the_entryPlug) @@ -20,7 +17,7 @@ mpiSimulation::mpiSimulation(SimInfo* the_entryPlug) entryPlug = the_entryPlug; mpiPlug = new mpiSimData; - mpiPlug->numberProcessors = MPI::COMM_WORLD.Get_size(); + MPI_Comm_size(MPI_COMM_WORLD, &(mpiPlug->numberProcessors) ); mpiPlug->myNode = worldRank; MolToProcMap = new int[entryPlug->n_mol]; @@ -43,10 +40,8 @@ mpiSimulation::~mpiSimulation(){ } -int* mpiSimulation::divideLabor( void ){ +void mpiSimulation::divideLabor( ){ - int* globalIndex; - int nComponents; MoleculeStamp** compStamps; randomSPRNG *myRandom; @@ -60,17 +55,13 @@ int* mpiSimulation::divideLabor( void ){ int old_atoms, add_atoms, new_atoms; int nTarget; - int molIndex, atomIndex, compIndex, compStart; + int molIndex, atomIndex; int done; - int nLocal, molLocal; int i, j, loops, which_proc, nmol_local, natoms_local; int nmol_global, natoms_global; - int local_index, index; - int smallDiff, bigDiff; - int baseSeed = BASE_SEED; + int local_index; + int baseSeed = entryPlug->getSeed(); - int testSum; - nComponents = entryPlug->nComponents; compStamps = entryPlug->compStamps; componentsNmol = entryPlug->componentsNmol; @@ -203,32 +194,32 @@ int* mpiSimulation::divideLabor( void ){ // Spray out this nonsense to all other processors: - MPI::COMM_WORLD.Bcast(MolToProcMap, mpiPlug->nMolGlobal, - MPI_INT, 0); + MPI_Bcast(MolToProcMap, mpiPlug->nMolGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(AtomToProcMap, mpiPlug->nAtomsGlobal, - MPI_INT, 0); + MPI_Bcast(AtomToProcMap, mpiPlug->nAtomsGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(MolComponentType, mpiPlug->nMolGlobal, - MPI_INT, 0); + MPI_Bcast(MolComponentType, mpiPlug->nMolGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(AtomsPerProc, mpiPlug->numberProcessors, - MPI_INT, 0); + MPI_Bcast(AtomsPerProc, mpiPlug->numberProcessors, + MPI_INT, 0, MPI_COMM_WORLD); } else { // Listen to your marching orders from processor 0: - MPI::COMM_WORLD.Bcast(MolToProcMap, mpiPlug->nMolGlobal, - MPI_INT, 0); + MPI_Bcast(MolToProcMap, mpiPlug->nMolGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(AtomToProcMap, mpiPlug->nAtomsGlobal, - MPI_INT, 0); + MPI_Bcast(AtomToProcMap, mpiPlug->nAtomsGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(MolComponentType, mpiPlug->nMolGlobal, - MPI_INT, 0); + MPI_Bcast(MolComponentType, mpiPlug->nMolGlobal, + MPI_INT, 0, MPI_COMM_WORLD); - MPI::COMM_WORLD.Bcast(AtomsPerProc, mpiPlug->numberProcessors, - MPI_INT, 0); + MPI_Bcast(AtomsPerProc, mpiPlug->numberProcessors, + MPI_INT, 0, MPI_COMM_WORLD); } @@ -250,8 +241,10 @@ int* mpiSimulation::divideLabor( void ){ } } - MPI::COMM_WORLD.Allreduce(&nmol_local,&nmol_global,1,MPI_INT,MPI_SUM); - MPI::COMM_WORLD.Allreduce(&natoms_local,&natoms_global,1,MPI_INT,MPI_SUM); + MPI_Allreduce(&nmol_local,&nmol_global,1,MPI_INT,MPI_SUM, + MPI_COMM_WORLD); + MPI_Allreduce(&natoms_local,&natoms_global,1,MPI_INT, + MPI_SUM, MPI_COMM_WORLD); if( nmol_global != entryPlug->n_mol ){ sprintf( painCave.errMsg, @@ -278,16 +271,32 @@ int* mpiSimulation::divideLabor( void ){ mpiPlug->myNMol = nmol_local; mpiPlug->myNlocal = natoms_local; - globalIndex = new int[mpiPlug->myNlocal]; + globalAtomIndex.resize(mpiPlug->myNlocal); local_index = 0; for (i = 0; i < mpiPlug->nAtomsGlobal; i++) { if (AtomToProcMap[i] == mpiPlug->myNode) { - globalIndex[local_index] = i; + globalAtomIndex[local_index] = i; + + globalToLocalAtom[i] = local_index; local_index++; + } + else + globalToLocalAtom[i] = -1; } + + globalMolIndex.resize(mpiPlug->myNMol); + local_index = 0; + for (i = 0; i < mpiPlug->nMolGlobal; i++) { + if (MolToProcMap[i] == mpiPlug->myNode) { + globalMolIndex[local_index] = i; + globalToLocalMol[i] = local_index; + local_index++; + } + else + globalToLocalMol[i] = -1; + } - return globalIndex; }