2 |
|
|
3 |
|
#include <cstdlib> |
4 |
|
#include <cstring> |
5 |
+ |
#include <cmath> |
6 |
|
#include <mpi.h> |
7 |
|
#include <mpi++.h> |
8 |
|
|
11 |
|
#include "fortranWrappers.hpp" |
12 |
|
#include "randomSPRNG.hpp" |
13 |
|
|
14 |
+ |
#define BASE_SEED 123456789 |
15 |
|
|
16 |
|
mpiSimulation* mpiSim; |
17 |
|
|
46 |
|
|
47 |
|
int nComponents; |
48 |
|
MoleculeStamp** compStamps; |
49 |
< |
randomSPRNG myRandom; |
49 |
> |
randomSPRNG *myRandom; |
50 |
|
int* componentsNmol; |
51 |
|
int* AtomsPerProc; |
52 |
|
|
60 |
|
int molIndex, atomIndex, compIndex, compStart; |
61 |
|
int done; |
62 |
|
int nLocal, molLocal; |
63 |
< |
int i, index; |
63 |
> |
int i, j, loops, which_proc, nmol_local, natoms_local; |
64 |
> |
int nmol_global, natoms_global; |
65 |
> |
int local_index, index; |
66 |
|
int smallDiff, bigDiff; |
67 |
+ |
int baseSeed = BASE_SEED; |
68 |
|
|
69 |
|
int testSum; |
70 |
|
|
80 |
|
mpiPlug->nSRIGlobal = entryPlug->n_SRI; |
81 |
|
mpiPlug->nMolGlobal = entryPlug->n_mol; |
82 |
|
|
83 |
< |
myRandom = new randomSPRNG(); |
83 |
> |
myRandom = new randomSPRNG( baseSeed ); |
84 |
|
|
85 |
|
a = (double)mpiPlug->nMolGlobal / (double)mpiPlug->nAtomsGlobal; |
86 |
|
|
125 |
|
|
126 |
|
// Pick a processor at random |
127 |
|
|
128 |
< |
which_proc = (int) (myRandom.getRandom() * mpiPlug->numberProcessors); |
128 |
> |
which_proc = (int) (myRandom->getRandom() * mpiPlug->numberProcessors); |
129 |
|
|
130 |
|
// How many atoms does this processor have? |
131 |
|
|
136 |
|
|
137 |
|
if (old_atoms >= nTarget) continue; |
138 |
|
|
139 |
< |
add_atoms = compStamps[MolComponentType[i]]->getNatoms(); |
139 |
> |
add_atoms = compStamps[MolComponentType[i]]->getNAtoms(); |
140 |
|
new_atoms = old_atoms + add_atoms; |
141 |
|
|
142 |
|
// If we can add this molecule to this processor without sending |
185 |
|
// where a = 1 / (average atoms per molecule) |
186 |
|
|
187 |
|
x = (double) (new_atoms - nTarget); |
188 |
< |
y = myRandom.getRandom(); |
188 |
> |
y = myRandom->getRandom(); |
189 |
|
|
190 |
|
if (exp(- a * x) > y) { |
191 |
|
MolToProcMap[i] = which_proc; |
282 |
|
local_index = 0; |
283 |
|
for (i = 0; i < mpiPlug->nAtomsGlobal; i++) { |
284 |
|
if (AtomToProcMap[i] == mpiPlug->myNode) { |
285 |
< |
globalIndex[local_index] = |
285 |
> |
local_index++; |
286 |
> |
globalIndex[local_index] = i; |
287 |
|
} |
288 |
|
} |
289 |
< |
|
290 |
< |
|
285 |
< |
|
286 |
< |
|
287 |
< |
index = mpiPlug->myAtomStart; |
288 |
< |
// for( i=0; i<mpiPlug->myNlocal; i++){ |
289 |
< |
// globalIndex[i] = index; |
290 |
< |
// index++; |
291 |
< |
// } |
292 |
< |
|
293 |
< |
// return globalIndex; |
289 |
> |
|
290 |
> |
return globalIndex; |
291 |
|
} |
292 |
|
|
293 |
|
|