ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/mpiSimulation.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/mpiSimulation.cpp (file contents):
Revision 422 by mmeineke, Thu Mar 27 19:21:42 2003 UTC vs.
Revision 434 by chuckv, Fri Mar 28 19:30:59 2003 UTC

# Line 1 | Line 1
1   #ifdef IS_MPI
2 <
2 > #include <iostream>
3   #include <cstdlib>
4   #include <cstring>
5   #include <cmath>
# Line 85 | Line 85 | int* mpiSimulation::divideLabor( void ){
85  
86    myRandom = new randomSPRNG( baseSeed );
87  
88 <  a = (double)mpiPlug->nMolGlobal / (double)mpiPlug->nAtomsGlobal;
88 >  a = 3.0 * (double)mpiPlug->nMolGlobal / (double)mpiPlug->nAtomsGlobal;
89  
90    // Initialize things that we'll send out later:
91    for (i = 0; i < mpiPlug->numberProcessors; i++ ) {
# Line 133 | Line 133 | int* mpiSimulation::divideLabor( void ){
133          // How many atoms does this processor have?
134          
135          old_atoms = AtomsPerProc[which_proc];
136
137        // If the processor already had too many atoms, just skip this
138        // processor and try again.
139
140        if (old_atoms >= nTarget) continue;
141
136          add_atoms = compStamps[MolComponentType[i]]->getNAtoms();
137          new_atoms = old_atoms + add_atoms;
144    
145        // If we can add this molecule to this processor without sending
146        // it above nTarget, then go ahead and do it:
147    
148        if (new_atoms <= nTarget) {
149          MolToProcMap[i] = which_proc;
150          AtomsPerProc[which_proc] += add_atoms;
151          for (j = 0 ; j < add_atoms; j++ ) {
152            AtomToProcMap[atomIndex] = which_proc;
153            atomIndex++;
154          }
155          done = 1;
156          continue;
157        }
138  
139          // If we've been through this loop too many times, we need
140          // to just give up and assign the molecule to this processor
# Line 178 | Line 158 | int* mpiSimulation::divideLabor( void ){
158            done = 1;
159            continue;
160          }
161 +    
162 +        // If we can add this molecule to this processor without sending
163 +        // it above nTarget, then go ahead and do it:
164 +    
165 +        if (new_atoms <= nTarget) {
166 +          MolToProcMap[i] = which_proc;
167 +          AtomsPerProc[which_proc] += add_atoms;
168 +          for (j = 0 ; j < add_atoms; j++ ) {
169 +            AtomToProcMap[atomIndex] = which_proc;
170 +            atomIndex++;
171 +          }
172 +          done = 1;
173 +          continue;
174 +        }
175  
182        // The only situation left is where old_atoms < nTarget, but
183        // new_atoms > nTarget.   We want to accept this with some
184        // probability that dies off the farther we are from nTarget
176  
177 +        // The only situation left is when new_atoms > nTarget.  We
178 +        // want to accept this with some probability that dies off the
179 +        // farther we are from nTarget
180 +
181          // roughly:  x = new_atoms - nTarget
182          //           Pacc(x) = exp(- a * x)
183 <        // where a = 1 / (average atoms per molecule)
183 >        // where a = penalty / (average atoms per molecule)
184  
185          x = (double) (new_atoms - nTarget);
186          y = myRandom->getRandom();
187 <        
188 <        if (exp(- a * x) > y) {
187 >      
188 >        if (y < exp(- a * x)) {
189            MolToProcMap[i] = which_proc;
190            AtomsPerProc[which_proc] += add_atoms;
191            for (j = 0 ; j < add_atoms; j++ ) {
# Line 234 | Line 229 | int* mpiSimulation::divideLabor( void ){
229      
230      MPI::COMM_WORLD.Bcast(AtomsPerProc, mpiPlug->numberProcessors,
231                            MPI_INT, 0);
232 +
233 +
234    }
235  
236  
# Line 289 | Line 286 | int* mpiSimulation::divideLabor( void ){
286        local_index++;
287      }
288    }
289 <
289 >  
290    return globalIndex;
291   }
292  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines