--- trunk/mdtools/interface_implementation/SimSetup.cpp 2002/11/26 21:04:43 189 +++ trunk/mdtools/interface_implementation/SimSetup.cpp 2002/12/10 21:41:26 202 @@ -73,7 +73,7 @@ void SimSetup::createSim( void ){ MakeStamps *the_stamps; Globals* the_globals; - int i; + int i, j; // get the stamps and globals; the_stamps = stamps; @@ -161,15 +161,51 @@ void SimSetup::createSim( void ){ #endif // is_mpi // make an array of molecule stamps that match the components used. + // also extract the used stamps out into a separate linked list + simnfo->nComponents = n_components; + simnfo->componentsNmol = components_nmol; + simnfo->compStamps = comp_stamps; + simnfo->headStamp = new LinkedMolStamp(); + + char* id; + LinkedMolStamp* headStamp = simnfo->headStamp; + LinkedMolStamp* currentStamp = NULL; for( i=0; igetMolecule( the_components[i]->getType() ); + id = the_components[i]->getType(); + comp_stamps[i] = NULL; + + // check to make sure the component isn't already in the list + + comp_stamps[i] = headStamp->match( id ); + if( comp_stamps[i] == NULL ){ + + // extract the component from the list; + + currentStamp = the_stamps->extractMolStamp( id ); + if( currentStamp == NULL ){ + sprintf( painCave.errMsg, + "SimSetup error: Component \"%s\" was not found in the " + "list of declared molecules\n" + id ); + painCave.isFatal = 1; + simError(); + } + + headStamp->add( currentStamp ); + comp_stamps[i] = headStamp->match( id ); + } } +#ifdef IS_MPI + strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); + MPIcheckPoint(); +#endif // is_mpi + + // caclulate the number of atoms, bonds, bends and torsions tot_atoms = 0; @@ -177,10 +213,10 @@ void SimSetup::createSim( void ){ tot_bends = 0; tot_torsions = 0; for( i=0; igetNAtoms(); - tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); - tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); + + tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); + tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); + tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); } @@ -191,17 +227,61 @@ void SimSetup::createSim( void ){ simnfo->n_bends = tot_bends; simnfo->n_torsions = tot_torsions; simnfo->n_SRI = tot_SRI; + simnfo->n_mol = tot_nmol; + +#ifdef IS_MPI + + // divide the molecules among processors here. + + mpiSimulation* mpiSim = new mpiSimulation( simnfo ); + + mpiSim->divideLabor(); + + // set up the local variables + + int localMol; + int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; + + localMol = 0; + local_atoms = 0; + local_bonds = 0; + local_bends = 0; + local_torsions = 0; + for( i=0; igetMyMolStart() <= j && + j <= mpiSim->getMyMolEnd() ){ + + local_atoms += comp_stamps[i]->getNAtoms(); + local_bonds += comp_stamps[i]->getNBonds(); + local_bends += comp_stamps[i]->getNBends(); + local_torsions += comp_stamps[i]->getNTorsions(); + localMol++; + } + } + } + + + + simnfo->n_atoms = mpiSim->getMyNlocal(); + + +#endif // is_mpi + + // create the atom and short range interaction arrays - Atom::createArrays(tot_atoms); - the_atoms = new Atom*[tot_atoms]; - the_molecules = new Molecule[tot_nmol]; + Atom::createArrays(simnfo->n_atoms); + the_atoms = new Atom*[simnfo->n_atoms]; + the_molecules = new Molecule[simnfo->n_mol]; - if( tot_SRI ){ - the_sris = new SRI*[tot_SRI]; - the_excludes = new ex_pair[tot_SRI]; + if( simnfo->n_SRI ){ + the_sris = new SRI*[simnfo->n_SRI]; + the_excludes = new ex_pair[simnfo->n_SRI]; } // set the arrays into the SimInfo object @@ -230,7 +310,6 @@ void SimSetup::createSim( void ){ makeTorsions(); } - // makeMolecules(); // get some of the tricky things that may still be in the globals @@ -314,11 +393,24 @@ void SimSetup::createSim( void ){ // delete fileInit; // } // else{ + +#ifdef IS_MPI + + // no init from bass + + sprintf( painCave.errMsg, + "Cannot intialize a parallel simulation without an initial configuration file.\n" ); + painCave.isFatal; + simError(); + +#else initFromBass(); + +#endif // is_mpi #ifdef IS_MPI - strcpy( checkPointMsg, "initFromBass successfully created the lattice" ); + strcpy( checkPointMsg, "Successfully read in the initial configuration" ); MPIcheckPoint(); #endif // is_mpi @@ -501,6 +593,7 @@ void SimSetup::makeAtoms( void ){ the_molecules[molIndex].setNMembers( nMemb ); the_molecules[molIndex].setStartAtom( molStart ); the_molecules[molIndex].setEndAtom( molEnd ); + the_molecules[molIndex].setStampID( i ); molIndex++; }