ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/mpi_implementation/mpiSimulation.cpp
Revision: 196
Committed: Thu Dec 5 21:37:51 2002 UTC (22 years, 4 months ago) by chuckv
File size: 3253 byte(s)
Log Message:

Working on the clean removal of key Molecule stamps from the Hash table.
stamps will be moved into a persitient linked list.

File Contents

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