ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/mpi_implementation/mpiSimulation.cpp
Revision: 202
Committed: Tue Dec 10 21:41:26 2002 UTC (21 years, 7 months ago) by mmeineke
File size: 3607 byte(s)
Log Message:
*** empty log message ***

File Contents

# Content
1 i#include <cstdlib>
2 #include <cstring>
3 #include <mpi.h>
4
5 #include "mpiSimulation.hpp"
6 #include "simError.h"
7
8
9
10 mpiSimulation::mpiSimulation(SimInfo* the_entryPlug)
11 {
12 entryPlug = the_entryPlug;
13
14 numberProcessors = MPI::COMM_WORLD.Get_size();
15 myNode = worldRank;
16
17 // let the simulation know were there.
18 entryPlug->mpiSim = this;
19 }
20
21
22 mpiSimulation::~mpiSimulation(){
23
24 // empty for now
25
26 }
27
28
29 void mpiSimulation::divideLabor( void ){
30
31 int nComponents;
32 MoleculeStamp** compStamps;
33 int* componentsNmol;
34
35 double numerator;
36 double denominator;
37 double precast;
38
39 int nTarget;
40 int molIndex, atomIndex, compIndex, compStart;
41 int done;
42 int nLocal, molLocal;
43 int i;
44 int smallDiff, bigDiff;
45
46 int testSum;
47
48 nComponents = entryPlug->nComponents;
49 compStamps = entryPlug->compStamps;
50 componentsNmol = entryPlug->componentsNmol;
51
52 simTotAtoms = entryPlug->n_atoms;
53 simTotBonds = entryPlug->n_bonds;
54 simTotBends = entryPlug->n_bends;
55 simTotTorsions = entryPlug->n_torsions;
56 simTotSRI = entryPlug->n_SRI;
57 simTotNmol = entryPlug->n_nmol;
58
59 numerator = (double) entryPlug->n_atoms;
60 denominator = (double) numberProcessors;
61 precast = numerator / denominator;
62 nTarget = (int)( precast + 0.5 );
63
64 molIndex = 0;
65 atomIndex = 0;
66 compIndex = 0;
67 compStart = 0;
68 for( i=0; i<(numberProcessors-1); i++){
69
70 done = 0;
71 nLocal = 0;
72 molLocal = 0;
73
74 if( i == myNode ){
75 myMolStart = molIndex;
76 myAtomStart = atomIndex;
77 }
78
79 while( !done ){
80
81 if( (molIndex-compStart) >= componentsNmol[compIndex] ){
82 compStart = molIndex;
83 compIndex++;
84 continue;
85 }
86
87 nLocal += compStamps[compIndex]->getNAtoms();
88 atomIndex += compStamps[compIndex]->getNAtoms();
89 molIndex++;
90 molLocal++;
91
92 if ( nLocal == nTarget ) done = 1;
93
94 else if( nLocal < nTarget ){
95 smallDiff = nTarget - nLocal;
96 }
97 else if( nLocal > nTarget ){
98 bigDiff = nLocal - nTarget;
99
100 if( bigDiff < smallDiff ) done = 1;
101 else{
102 molIndex--;
103 molLocal--;
104 atomIndex -= compStamps[compIndex]->getNAtoms();
105 nLocal -= compStamps[compIndex]->getNAtoms();
106 done = 1;
107 }
108 }
109 }
110
111 if( i == myNode ){
112 myMolEnd = (molIndex - 1);
113 myAtomEnd = (atomIndex - 1);
114 myNlocal = nLocal;
115 myMol = molLocal;
116 }
117
118 numerator = (double)( entryPlug->n_atoms - atomIndex );
119 denominator = (double)( numberProcessors - (i+1) );
120 precast = numerator / denominator;
121 nTarget = (int)( precast + 0.5 );
122 }
123
124 if( myNode == numberProcessors-1 ){
125 myMolStart = molIndex;
126 myAtomStart = atomIndex;
127
128 nLocal = 0;
129 molLocal = 0;
130 while( compIndex < nComponents ){
131
132 if( (molIndex-compStart) >= componentsNmol[compIndex] ){
133 compStart = molIndex;
134 compIndex++;
135 continue;
136 }
137
138 nLocal += compStamps[compIndex]->getNAtoms();
139 atomIndex += compStamps[compIndex]->getNAtoms();
140 molIndex++;
141 molLocal++;
142 }
143
144 myMolEnd = (molIndex - 1);
145 myAtomEnd = (atomIndex - 1);
146 myNlocal = nLocal;
147 myMol = molLocal;
148 }
149
150
151 MPI_Allreduce( &Nlocal, &testSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
152
153 if( myNode == 0 ){
154 if( testSum != entryPlug->n_atoms ){
155 sprintf( painCave.errMsg,
156 "The summ of all nLocals, %d, did not equal the total number of atoms, %d.\n",
157 testSum, entryPlug->n_atoms );
158 painCave.isFatal = 1;
159 simError();
160 }
161 }
162
163 sprintf( checkPointMsg,
164 "Successfully divided the molecules among the processors.\n" );
165 MPIcheckPoint();
166
167 // lets create the identity array
168 }