# | Line 5 | Line 5 | i#include <cstdlib> | |
---|---|---|
5 | #include "mpiSimulation.hpp" | |
6 | #include "simError.h" | |
7 | ||
8 | + | extern "C"{ |
9 | + | void wrapsimparallelmod_( void (*wrapFunction)(void (*fSub)( mpiSimData*, |
10 | + | int*, int*, |
11 | + | int*))); |
12 | + | } |
13 | ||
14 | + | void wrapSimParallel((void (*fSub)(mpiSimData*, int*, int*, int*))); |
15 | ||
16 | + | |
17 | + | mpiSimulation* mpiSim; |
18 | + | |
19 | mpiSimulation::mpiSimulation(SimInfo* the_entryPlug) | |
20 | { | |
21 | entryPlug = the_entryPlug; | |
22 | + | mpiPlug = new MpiSimData; |
23 | ||
24 | < | numberProcessors = MPI::COMM_WORLD.Get_size(); |
25 | < | myNode = worldRank; |
24 | > | mpiPlug->numberProcessors = MPI::COMM_WORLD.Get_size(); |
25 | > | mpiPlug->myNode = worldRank; |
26 | ||
27 | < | // let the simulation know were there. |
28 | < | entryPlug->mpiSim = this; |
27 | > | mpiSim = this; |
28 | > | wrapMe(); |
29 | > | |
30 | } | |
31 | ||
32 | ||
33 | mpiSimulation::~mpiSimulation(){ | |
34 | ||
35 | < | // empty for now |
35 | > | delete mpiPlug; |
36 | > | // perhaps we should let fortran know the party is over. |
37 | ||
38 | } | |
39 | ||
40 | + | void mpiSimulation::wrapMe(){ |
41 | ||
42 | + | wrapsimparallelmod_( wrapSimParallel ); |
43 | + | } |
44 | + | |
45 | + | |
46 | + | |
47 | void mpiSimulation::divideLabor( void ){ | |
48 | ||
49 | int nComponents; | |
# | Line 49 | Line 67 | void mpiSimulation::divideLabor( void ){ | |
67 | compStamps = entryPlug->compStamps; | |
68 | componentsNmol = entryPlug->componentsNmol; | |
69 | ||
70 | + | mpiPlug->nAtomsGlobal = entryPlug->n_atoms; |
71 | + | mpiPlug->nBondsGlobal = entryPlug->n_bonds; |
72 | + | mpiPlug->nBendsGlobal = entryPlug->n_bends; |
73 | + | mpiPlug->nTorsionsGlobal = entryPlug->n_torsions; |
74 | + | mpiPlug->nSRIGlobal = entryPlug->n_SRI; |
75 | + | mpiPlug->nMolGlobal = entryPlug->n_nmol; |
76 | + | |
77 | numerator = (double) entryPlug->n_atoms; | |
78 | < | denominator = (double) numberProcessors; |
78 | > | denominator = (double) mpiPlug->numberProcessors; |
79 | precast = numerator / denominator; | |
80 | nTarget = (int)( precast + 0.5 ); | |
81 | ||
# | Line 58 | Line 83 | void mpiSimulation::divideLabor( void ){ | |
83 | atomIndex = 0; | |
84 | compIndex = 0; | |
85 | compStart = 0; | |
86 | < | for( i=0; i<(numberProcessors-1); i++){ |
86 | > | for( i=0; i<(mpiPlug->numberProcessors-1); i++){ |
87 | ||
88 | done = 0; | |
89 | nLocal = 0; | |
90 | molLocal = 0; | |
91 | ||
92 | < | if( i == myNode ){ |
93 | < | myMolStart = molIndex; |
94 | < | myAtomStart = atomIndex; |
92 | > | if( i == mpiPlug->myNode ){ |
93 | > | mpiPlug->myMolStart = molIndex; |
94 | > | mpiPlug->myAtomStart = atomIndex; |
95 | } | |
96 | ||
97 | while( !done ){ | |
# | Line 101 | Line 126 | void mpiSimulation::divideLabor( void ){ | |
126 | } | |
127 | } | |
128 | ||
129 | < | if( i == myNode ){ |
130 | < | myMolEnd = (molIndex - 1); |
131 | < | myAtomEnd = (atomIndex - 1); |
132 | < | myNlocal = nLocal; |
133 | < | myMol = molLocal; |
129 | > | if( i == mpiPlug->myNode ){ |
130 | > | mpiPlug->myMolEnd = (molIndex - 1); |
131 | > | mpiPlug->myAtomEnd = (atomIndex - 1); |
132 | > | mpiPlug->myNlocal = nLocal; |
133 | > | mpiPlug->myMol = molLocal; |
134 | } | |
135 | ||
136 | numerator = (double)( entryPlug->n_atoms - atomIndex ); | |
137 | < | denominator = (double)( numberProcessors - (i+1) ); |
137 | > | denominator = (double)( mpiPlug->numberProcessors - (i+1) ); |
138 | precast = numerator / denominator; | |
139 | nTarget = (int)( precast + 0.5 ); | |
140 | } | |
141 | ||
142 | < | if( myNode == numberProcessors-1 ){ |
143 | < | myMolStart = molIndex; |
144 | < | myAtomStart = atomIndex; |
142 | > | if( mpiPlug->myNode == mpiPlug->numberProcessors-1 ){ |
143 | > | mpiPlug->myMolStart = molIndex; |
144 | > | mpiPlug->myAtomStart = atomIndex; |
145 | ||
146 | nLocal = 0; | |
147 | molLocal = 0; | |
# | Line 134 | Line 159 | void mpiSimulation::divideLabor( void ){ | |
159 | molLocal++; | |
160 | } | |
161 | ||
162 | < | myMolEnd = (molIndex - 1); |
163 | < | myAtomEnd = (atomIndex - 1); |
164 | < | myNlocal = nLocal; |
165 | < | myMol = molLocal; |
162 | > | mpiPlug->myMolEnd = (molIndex - 1); |
163 | > | mpiPlug->myAtomEnd = (atomIndex - 1); |
164 | > | mpiPlug->myNlocal = nLocal; |
165 | > | mpiPlug->myMol = molLocal; |
166 | } | |
167 | ||
168 | ||
169 | < | MPI_Allreduce( &Nlocal, &testSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); |
169 | > | MPI_Allreduce( &nLocal, &testSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); |
170 | ||
171 | < | if( myNode == 0 ){ |
171 | > | if( mpiPlug->myNode == 0 ){ |
172 | if( testSum != entryPlug->n_atoms ){ | |
173 | sprintf( painCave.errMsg, | |
174 | "The summ of all nLocals, %d, did not equal the total number of atoms, %d.\n", | |
# | Line 159 | Line 184 | void mpiSimulation::divideLabor( void ){ | |
184 | ||
185 | // lets create the identity array | |
186 | } | |
187 | + | |
188 | + | |
189 | + | void wrapSimParallel((void (*fSub)(mpiSimData*, int*, int*, int*))){ |
190 | + | |
191 | + | mpiSim->setInternal( fSub ); |
192 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |