--- trunk/OOPSE/libmdtools/mpiSimulation.cpp 2003/03/27 23:33:40 432 +++ trunk/OOPSE/libmdtools/mpiSimulation.cpp 2003/10/28 16:03:37 829 @@ -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]; @@ -60,17 +57,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; @@ -83,9 +76,10 @@ int* mpiSimulation::divideLabor( void ){ mpiPlug->nSRIGlobal = entryPlug->n_SRI; mpiPlug->nMolGlobal = entryPlug->n_mol; + myRandom = new randomSPRNG( baseSeed ); - a = (double)mpiPlug->nMolGlobal / (double)mpiPlug->nAtomsGlobal; + a = 3.0 * (double)mpiPlug->nMolGlobal / (double)mpiPlug->nAtomsGlobal; // Initialize things that we'll send out later: for (i = 0; i < mpiPlug->numberProcessors; i++ ) { @@ -136,9 +130,6 @@ int* mpiSimulation::divideLabor( void ){ add_atoms = compStamps[MolComponentType[i]]->getNAtoms(); new_atoms = old_atoms + add_atoms; - // If the processor already had too many atoms, just skip this - // processor and try again. - // If we've been through this loop too many times, we need // to just give up and assign the molecule to this processor // and be done with it. @@ -161,8 +152,6 @@ int* mpiSimulation::divideLabor( void ){ done = 1; continue; } - - if (old_atoms >= nTarget) continue; // If we can add this molecule to this processor without sending // it above nTarget, then go ahead and do it: @@ -179,18 +168,18 @@ int* mpiSimulation::divideLabor( void ){ } - // The only situation left is where old_atoms < nTarget, but - // new_atoms > nTarget. We want to accept this with some - // probability that dies off the farther we are from nTarget + // The only situation left is when new_atoms > nTarget. We + // want to accept this with some probability that dies off the + // farther we are from nTarget // roughly: x = new_atoms - nTarget // Pacc(x) = exp(- a * x) - // where a = 1 / (average atoms per molecule) + // where a = penalty / (average atoms per molecule) x = (double) (new_atoms - nTarget); y = myRandom->getRandom(); - - if (exp(- a * x) > y) { + + if (y < exp(- a * x)) { MolToProcMap[i] = which_proc; AtomsPerProc[which_proc] += add_atoms; for (j = 0 ; j < add_atoms; j++ ) { @@ -208,32 +197,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); } @@ -255,10 +244,10 @@ int* mpiSimulation::divideLabor( void ){ } } - std::cerr << "proc = " << mpiPlug->myNode << " atoms = " << natoms_local << "\n"; - - 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, @@ -303,8 +292,11 @@ void mpiSimulation::mpiRefresh( void ){ int isError, i; int *globalIndex = new int[mpiPlug->myNlocal]; - for(i=0; imyNlocal; i++) globalIndex[i] = entryPlug->atoms[i]->getGlobalIndex(); + // Fortran indexing needs to be increased by 1 in order to get the 2 languages to + // not barf + for(i=0; imyNlocal; i++) globalIndex[i] = entryPlug->atoms[i]->getGlobalIndex()+1; + isError = 0; setFsimParallel( mpiPlug, &(entryPlug->n_atoms), globalIndex, &isError );