1 |
< |
#include <cstring> |
1 |
> |
#define _FILE_OFFSET_BITS 64 |
2 |
> |
|
3 |
> |
#include <string.h> |
4 |
|
#include <iostream> |
5 |
|
#include <fstream> |
6 |
|
|
7 |
|
#ifdef IS_MPI |
8 |
|
#include <mpi.h> |
9 |
|
#include "mpiSimulation.hpp" |
10 |
< |
#define TAKE_THIS_TAG 0 |
10 |
> |
#define TAKE_THIS_TAG_CHAR 1 |
11 |
> |
#define TAKE_THIS_TAG_INT 2 |
12 |
> |
|
13 |
> |
namespace dWrite{ |
14 |
> |
void nodeZeroError( void ); |
15 |
> |
void anonymousNodeDie( void ); |
16 |
> |
} |
17 |
> |
|
18 |
> |
using namespace dWrite; |
19 |
|
#endif //is_mpi |
20 |
|
|
21 |
|
#include "ReadWrite.hpp" |
22 |
|
#include "simError.h" |
23 |
|
|
14 |
– |
|
15 |
– |
|
16 |
– |
|
17 |
– |
|
24 |
|
DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ |
25 |
|
|
26 |
|
entry_plug = the_entry_plug; |
28 |
|
#ifdef IS_MPI |
29 |
|
if(worldRank == 0 ){ |
30 |
|
#endif // is_mpi |
31 |
< |
|
26 |
< |
|
27 |
< |
|
31 |
> |
|
32 |
|
strcpy( outName, entry_plug->sampleName ); |
33 |
< |
|
33 |
> |
|
34 |
|
outFile.open(outName, ios::out | ios::trunc ); |
35 |
< |
|
35 |
> |
|
36 |
|
if( !outFile ){ |
37 |
< |
|
37 |
> |
|
38 |
|
sprintf( painCave.errMsg, |
39 |
|
"Could not open \"%s\" for dump output.\n", |
40 |
|
outName); |
41 |
|
painCave.isFatal = 1; |
42 |
|
simError(); |
43 |
|
} |
44 |
< |
|
44 |
> |
|
45 |
|
//outFile.setf( ios::scientific ); |
46 |
|
|
47 |
|
#ifdef IS_MPI |
67 |
|
} |
68 |
|
|
69 |
|
void DumpWriter::writeDump( double currentTime ){ |
70 |
< |
|
70 |
> |
|
71 |
|
const int BUFFERSIZE = 2000; |
72 |
|
char tempBuffer[BUFFERSIZE]; |
73 |
|
char writeLine[BUFFERSIZE]; |
74 |
|
|
75 |
|
int i; |
76 |
+ |
#ifdef IS_MPI |
77 |
+ |
int j, which_node, done, which_atom, local_index; |
78 |
+ |
#else //is_mpi |
79 |
+ |
int nAtoms = entry_plug->n_atoms; |
80 |
+ |
#endif //is_mpi |
81 |
+ |
|
82 |
|
double q[4]; |
83 |
|
DirectionalAtom* dAtom; |
74 |
– |
int nAtoms = entry_plug->n_atoms; |
84 |
|
Atom** atoms = entry_plug->atoms; |
85 |
< |
|
85 |
> |
double pos[3], vel[3]; |
86 |
|
|
87 |
+ |
|
88 |
+ |
// write current frame to the eor file |
89 |
+ |
|
90 |
+ |
this->writeFinal( currentTime ); |
91 |
+ |
|
92 |
|
#ifndef IS_MPI |
93 |
< |
|
93 |
> |
|
94 |
|
outFile << nAtoms << "\n"; |
95 |
< |
|
96 |
< |
outFile << currentTime << "\t" |
97 |
< |
<< entry_plug->box_x << "\t" |
98 |
< |
<< entry_plug->box_y << "\t" |
99 |
< |
<< entry_plug->box_z << "\n"; |
100 |
< |
|
95 |
> |
|
96 |
> |
outFile << currentTime << ";\t" |
97 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
98 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
99 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
100 |
> |
|
101 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
102 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
103 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
104 |
> |
|
105 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
106 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
107 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
108 |
> |
//write out additional parameters, such as chi and eta |
109 |
> |
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
110 |
> |
outFile << endl; |
111 |
> |
|
112 |
|
for( i=0; i<nAtoms; i++ ){ |
88 |
– |
|
113 |
|
|
114 |
+ |
atoms[i]->getPos(pos); |
115 |
+ |
atoms[i]->getVel(vel); |
116 |
+ |
|
117 |
|
sprintf( tempBuffer, |
118 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
119 |
|
atoms[i]->getType(), |
120 |
< |
atoms[i]->getX(), |
121 |
< |
atoms[i]->getY(), |
122 |
< |
atoms[i]->getZ(), |
123 |
< |
atoms[i]->get_vx(), |
124 |
< |
atoms[i]->get_vy(), |
125 |
< |
atoms[i]->get_vz()); |
120 |
> |
pos[0], |
121 |
> |
pos[1], |
122 |
> |
pos[2], |
123 |
> |
vel[0], |
124 |
> |
vel[1], |
125 |
> |
vel[2]); |
126 |
|
strcpy( writeLine, tempBuffer ); |
127 |
|
|
128 |
|
if( atoms[i]->isDirectional() ){ |
129 |
< |
|
129 |
> |
|
130 |
|
dAtom = (DirectionalAtom *)atoms[i]; |
131 |
|
dAtom->getQ( q ); |
132 |
< |
|
132 |
> |
|
133 |
|
sprintf( tempBuffer, |
134 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
135 |
|
q[0], |
143 |
|
} |
144 |
|
else |
145 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
146 |
< |
|
146 |
> |
|
147 |
|
outFile << writeLine; |
148 |
|
} |
149 |
|
outFile.flush(); |
150 |
|
|
151 |
|
#else // is_mpi |
152 |
|
|
153 |
< |
int masterIndex; |
154 |
< |
int nodeAtomsStart; |
128 |
< |
int nodeAtomsEnd; |
129 |
< |
int mpiErr; |
130 |
< |
int sendError; |
131 |
< |
int procIndex; |
132 |
< |
|
133 |
< |
MPI_Status istatus[MPI_STATUS_SIZE]; |
153 |
> |
// first thing first, suspend fatalities. |
154 |
> |
painCave.isEventLoop = 1; |
155 |
|
|
156 |
< |
|
156 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
157 |
> |
int haveError; |
158 |
> |
|
159 |
> |
MPI_Status istatus; |
160 |
> |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
161 |
> |
|
162 |
|
// write out header and node 0's coordinates |
163 |
|
|
164 |
|
if( worldRank == 0 ){ |
165 |
|
outFile << mpiSim->getTotAtoms() << "\n"; |
140 |
– |
|
141 |
– |
outFile << currentTime << "\t" |
142 |
– |
<< entry_plug->box_x << "\t" |
143 |
– |
<< entry_plug->box_y << "\t" |
144 |
– |
<< entry_plug->box_z << "\n"; |
166 |
|
|
167 |
< |
masterIndex = 0; |
168 |
< |
for( i=0; i<nAtoms; i++ ){ |
169 |
< |
|
170 |
< |
sprintf( tempBuffer, |
171 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
172 |
< |
atoms[i]->getType(), |
173 |
< |
atoms[i]->getX(), |
174 |
< |
atoms[i]->getY(), |
175 |
< |
atoms[i]->getZ(), |
176 |
< |
atoms[i]->get_vx(), |
177 |
< |
atoms[i]->get_vy(), |
178 |
< |
atoms[i]->get_vz()); |
179 |
< |
strcpy( writeLine, tempBuffer ); |
180 |
< |
|
181 |
< |
if( atoms[i]->isDirectional() ){ |
161 |
< |
|
162 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
163 |
< |
dAtom->getQ( q ); |
164 |
< |
|
165 |
< |
sprintf( tempBuffer, |
166 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
167 |
< |
q[0], |
168 |
< |
q[1], |
169 |
< |
q[2], |
170 |
< |
q[3], |
171 |
< |
dAtom->getJx(), |
172 |
< |
dAtom->getJy(), |
173 |
< |
dAtom->getJz()); |
174 |
< |
strcat( writeLine, tempBuffer ); |
175 |
< |
} |
176 |
< |
else |
177 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
178 |
< |
|
179 |
< |
outFile << writeLine; |
180 |
< |
masterIndex++; |
181 |
< |
} |
167 |
> |
outFile << currentTime << ";\t" |
168 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
169 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
170 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
171 |
> |
|
172 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
173 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
174 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
175 |
> |
|
176 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
177 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
178 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
179 |
> |
|
180 |
> |
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
181 |
> |
outFile << endl; |
182 |
|
outFile.flush(); |
183 |
< |
} |
183 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
184 |
> |
// Get the Node number which has this atom; |
185 |
|
|
186 |
< |
sprintf( checkPointMsg, |
186 |
< |
"Sucessfully wrote node 0's dump configuration.\n"); |
187 |
< |
MPIcheckPoint(); |
188 |
< |
|
189 |
< |
for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
190 |
< |
procIndex++){ |
186 |
> |
which_node = AtomToProcMap[i]; |
187 |
|
|
188 |
< |
if( worldRank == 0 ){ |
189 |
< |
|
190 |
< |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
191 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
192 |
< |
|
193 |
< |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
194 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
195 |
< |
|
196 |
< |
// Make sure where node 0 is writing to, matches where the |
197 |
< |
// receiving node expects it to be. |
198 |
< |
|
199 |
< |
if (masterIndex != nodeAtomsStart){ |
200 |
< |
sendError = 1; |
201 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
202 |
< |
MPI_COMM_WORLD); |
203 |
< |
sprintf(painCave.errMsg, |
204 |
< |
"DumpWriter error: atoms start index (%d) for " |
205 |
< |
"node %d not equal to master index (%d)", |
206 |
< |
nodeAtomsStart,procIndex,masterIndex ); |
207 |
< |
painCave.isFatal = 1; |
208 |
< |
simError(); |
209 |
< |
} |
210 |
< |
|
211 |
< |
sendError = 0; |
212 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
213 |
< |
MPI_COMM_WORLD); |
214 |
< |
|
215 |
< |
// recieve the nodes writeLines |
216 |
< |
|
217 |
< |
for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
218 |
< |
|
219 |
< |
mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
220 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
221 |
< |
|
222 |
< |
outFile << writeLine; |
223 |
< |
masterIndex++; |
188 |
> |
if (which_node == 0 ) { |
189 |
> |
|
190 |
> |
haveError = 0; |
191 |
> |
which_atom = i; |
192 |
> |
local_index=-1; |
193 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
194 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
195 |
> |
} |
196 |
> |
if (local_index != -1) { |
197 |
> |
//format the line |
198 |
> |
|
199 |
> |
atoms[local_index]->getPos(pos); |
200 |
> |
atoms[local_index]->getVel(vel); |
201 |
> |
|
202 |
> |
sprintf( tempBuffer, |
203 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
204 |
> |
atoms[local_index]->getType(), |
205 |
> |
pos[0], |
206 |
> |
pos[1], |
207 |
> |
pos[2], |
208 |
> |
vel[0], |
209 |
> |
vel[1], |
210 |
> |
vel[2]); // check here. |
211 |
> |
strcpy( writeLine, tempBuffer ); |
212 |
> |
|
213 |
> |
if( atoms[local_index]->isDirectional() ){ |
214 |
> |
|
215 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
216 |
> |
dAtom->getQ( q ); |
217 |
> |
|
218 |
> |
sprintf( tempBuffer, |
219 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
220 |
> |
q[0], |
221 |
> |
q[1], |
222 |
> |
q[2], |
223 |
> |
q[3], |
224 |
> |
dAtom->getJx(), |
225 |
> |
dAtom->getJy(), |
226 |
> |
dAtom->getJz()); |
227 |
> |
strcat( writeLine, tempBuffer ); |
228 |
> |
|
229 |
> |
} |
230 |
> |
else |
231 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
232 |
> |
} |
233 |
> |
else { |
234 |
> |
sprintf(painCave.errMsg, |
235 |
> |
"Atom %d not found on processor %d\n", |
236 |
> |
i, worldRank ); |
237 |
> |
haveError= 1; |
238 |
> |
simError(); |
239 |
> |
} |
240 |
> |
|
241 |
> |
if(haveError) nodeZeroError(); |
242 |
> |
|
243 |
|
} |
244 |
+ |
else { |
245 |
+ |
myStatus = 1; |
246 |
+ |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
247 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
248 |
+ |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
249 |
+ |
MPI_COMM_WORLD); |
250 |
+ |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
251 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
252 |
+ |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
253 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
254 |
+ |
|
255 |
+ |
if(!myStatus) nodeZeroError(); |
256 |
+ |
|
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
outFile << writeLine; |
260 |
+ |
outFile.flush(); |
261 |
|
} |
262 |
|
|
263 |
< |
else if( worldRank == procIndex ){ |
263 |
> |
// kill everyone off: |
264 |
> |
myStatus = -1; |
265 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
266 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
267 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
268 |
> |
} |
269 |
|
|
270 |
< |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
234 |
< |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
270 |
> |
} else { |
271 |
|
|
272 |
< |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
273 |
< |
MPI_COMM_WORLD); |
238 |
< |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
239 |
< |
MPI_COMM_WORLD); |
240 |
< |
|
241 |
< |
sendError = -1; |
242 |
< |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
243 |
< |
MPI_COMM_WORLD, istatus); |
272 |
> |
done = 0; |
273 |
> |
while (!done) { |
274 |
|
|
275 |
< |
if (sendError) MPIcheckPoint(); |
275 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
276 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
277 |
|
|
278 |
< |
// send current node's configuration line by line. |
278 |
> |
if(!myStatus) anonymousNodeDie(); |
279 |
|
|
280 |
< |
for( i=0; i<nAtoms; i++ ){ |
280 |
> |
if(myStatus < 0) break; |
281 |
|
|
282 |
+ |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
283 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
284 |
+ |
|
285 |
+ |
myStatus = 1; |
286 |
+ |
local_index=-1; |
287 |
+ |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
288 |
+ |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
289 |
+ |
} |
290 |
+ |
if (local_index != -1) { |
291 |
+ |
//format the line |
292 |
+ |
|
293 |
+ |
atoms[local_index]->getPos(pos); |
294 |
+ |
atoms[local_index]->getVel(vel); |
295 |
+ |
|
296 |
|
sprintf( tempBuffer, |
297 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
298 |
< |
atoms[i]->getType(), |
299 |
< |
atoms[i]->getX(), |
300 |
< |
atoms[i]->getY(), |
301 |
< |
atoms[i]->getZ(), |
302 |
< |
atoms[i]->get_vx(), |
303 |
< |
atoms[i]->get_vy(), |
304 |
< |
atoms[i]->get_vz()); // check here. |
298 |
> |
atoms[local_index]->getType(), |
299 |
> |
pos[0], |
300 |
> |
pos[1], |
301 |
> |
pos[2], |
302 |
> |
vel[0], |
303 |
> |
vel[1], |
304 |
> |
vel[2]); // check here. |
305 |
|
strcpy( writeLine, tempBuffer ); |
306 |
< |
|
307 |
< |
if( atoms[i]->isDirectional() ){ |
308 |
< |
|
309 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
306 |
> |
|
307 |
> |
if( atoms[local_index]->isDirectional() ){ |
308 |
> |
|
309 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
310 |
|
dAtom->getQ( q ); |
311 |
< |
|
311 |
> |
|
312 |
|
sprintf( tempBuffer, |
313 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
314 |
|
q[0], |
320 |
|
dAtom->getJz()); |
321 |
|
strcat( writeLine, tempBuffer ); |
322 |
|
} |
323 |
< |
else |
323 |
> |
else{ |
324 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
325 |
< |
|
281 |
< |
mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
282 |
< |
MPI_COMM_WORLD); |
325 |
> |
} |
326 |
|
} |
327 |
+ |
else { |
328 |
+ |
sprintf(painCave.errMsg, |
329 |
+ |
"Atom %d not found on processor %d\n", |
330 |
+ |
which_atom, worldRank ); |
331 |
+ |
myStatus = 0; |
332 |
+ |
simError(); |
333 |
+ |
|
334 |
+ |
strcpy( writeLine, "Hello, I'm an error.\n"); |
335 |
+ |
} |
336 |
+ |
|
337 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
338 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
339 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
340 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
341 |
|
} |
285 |
– |
|
286 |
– |
sprintf(checkPointMsg,"Node %d sent dump configuration.", |
287 |
– |
procIndex); |
288 |
– |
MPIcheckPoint(); |
342 |
|
} |
343 |
< |
|
343 |
> |
outFile.flush(); |
344 |
> |
sprintf( checkPointMsg, |
345 |
> |
"Sucessfully took a dump.\n"); |
346 |
> |
MPIcheckPoint(); |
347 |
> |
|
348 |
> |
// last thing last, enable fatalities. |
349 |
> |
painCave.isEventLoop = 0; |
350 |
> |
|
351 |
|
#endif // is_mpi |
352 |
|
} |
353 |
|
|
354 |
+ |
void DumpWriter::writeFinal(double finalTime){ |
355 |
|
|
356 |
+ |
char finalName[500]; |
357 |
+ |
ofstream finalOut; |
358 |
|
|
296 |
– |
void DumpWriter::writeFinal(){ |
297 |
– |
|
298 |
– |
|
359 |
|
const int BUFFERSIZE = 2000; |
360 |
< |
char tempBuffer[500]; |
360 |
> |
char tempBuffer[BUFFERSIZE]; |
361 |
|
char writeLine[BUFFERSIZE]; |
302 |
– |
|
303 |
– |
char finalName[500]; |
362 |
|
|
305 |
– |
int i; |
363 |
|
double q[4]; |
364 |
|
DirectionalAtom* dAtom; |
308 |
– |
int nAtoms = entry_plug->n_atoms; |
365 |
|
Atom** atoms = entry_plug->atoms; |
366 |
< |
|
311 |
< |
ofstream finalOut; |
312 |
< |
|
366 |
> |
int i; |
367 |
|
#ifdef IS_MPI |
368 |
+ |
int j, which_node, done, which_atom, local_index; |
369 |
+ |
#else //is_mpi |
370 |
+ |
int nAtoms = entry_plug->n_atoms; |
371 |
+ |
#endif //is_mpi |
372 |
+ |
|
373 |
+ |
double pos[3], vel[3]; |
374 |
+ |
|
375 |
+ |
#ifdef IS_MPI |
376 |
|
if(worldRank == 0 ){ |
377 |
|
#endif // is_mpi |
378 |
< |
|
378 |
> |
|
379 |
|
strcpy( finalName, entry_plug->finalName ); |
380 |
< |
|
380 |
> |
|
381 |
|
finalOut.open( finalName, ios::out | ios::trunc ); |
382 |
|
if( !finalOut ){ |
383 |
|
sprintf( painCave.errMsg, |
386 |
|
painCave.isFatal = 1; |
387 |
|
simError(); |
388 |
|
} |
389 |
< |
|
389 |
> |
|
390 |
|
// finalOut.setf( ios::scientific ); |
391 |
< |
|
391 |
> |
|
392 |
|
#ifdef IS_MPI |
393 |
|
} |
394 |
< |
|
394 |
> |
|
395 |
|
sprintf(checkPointMsg,"Opened file for final configuration\n"); |
396 |
< |
MPIcheckPoint(); |
397 |
< |
|
396 |
> |
MPIcheckPoint(); |
397 |
> |
|
398 |
|
#endif //is_mpi |
399 |
|
|
338 |
– |
|
400 |
|
|
401 |
|
#ifndef IS_MPI |
402 |
< |
|
402 |
> |
|
403 |
|
finalOut << nAtoms << "\n"; |
404 |
< |
|
405 |
< |
finalOut << entry_plug->box_x << "\t" |
406 |
< |
<< entry_plug->box_y << "\t" |
407 |
< |
<< entry_plug->box_z << "\n"; |
408 |
< |
|
404 |
> |
|
405 |
> |
finalOut << finalTime << ";\t" |
406 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
407 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
408 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
409 |
> |
|
410 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
411 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
412 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
413 |
> |
|
414 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
415 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
416 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
417 |
> |
|
418 |
> |
//write out additional parameters, such as chi and eta |
419 |
> |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
420 |
> |
finalOut << endl; |
421 |
> |
|
422 |
|
for( i=0; i<nAtoms; i++ ){ |
423 |
< |
|
423 |
> |
|
424 |
> |
atoms[i]->getPos(pos); |
425 |
> |
atoms[i]->getVel(vel); |
426 |
> |
|
427 |
|
sprintf( tempBuffer, |
428 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
429 |
|
atoms[i]->getType(), |
430 |
< |
atoms[i]->getX(), |
431 |
< |
atoms[i]->getY(), |
432 |
< |
atoms[i]->getZ(), |
433 |
< |
atoms[i]->get_vx(), |
434 |
< |
atoms[i]->get_vy(), |
435 |
< |
atoms[i]->get_vz()); |
430 |
> |
pos[0], |
431 |
> |
pos[1], |
432 |
> |
pos[2], |
433 |
> |
vel[0], |
434 |
> |
vel[1], |
435 |
> |
vel[2]); |
436 |
|
strcpy( writeLine, tempBuffer ); |
437 |
|
|
438 |
|
if( atoms[i]->isDirectional() ){ |
439 |
< |
|
439 |
> |
|
440 |
|
dAtom = (DirectionalAtom *)atoms[i]; |
441 |
|
dAtom->getQ( q ); |
442 |
< |
|
442 |
> |
|
443 |
|
sprintf( tempBuffer, |
444 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
445 |
|
q[0], |
453 |
|
} |
454 |
|
else |
455 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
456 |
< |
|
456 |
> |
|
457 |
|
finalOut << writeLine; |
458 |
|
} |
459 |
|
finalOut.flush(); |
460 |
+ |
finalOut.close(); |
461 |
|
|
462 |
|
#else // is_mpi |
463 |
|
|
464 |
< |
int masterIndex; |
465 |
< |
int nodeAtomsStart; |
388 |
< |
int nodeAtomsEnd; |
389 |
< |
int mpiErr; |
390 |
< |
int sendError; |
391 |
< |
int procIndex; |
392 |
< |
|
393 |
< |
MPI_Status istatus[MPI_STATUS_SIZE]; |
464 |
> |
// first thing first, suspend fatalities. |
465 |
> |
painCave.isEventLoop = 1; |
466 |
|
|
467 |
< |
|
467 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
468 |
> |
int haveError; |
469 |
> |
|
470 |
> |
MPI_Status istatus; |
471 |
> |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
472 |
> |
|
473 |
|
// write out header and node 0's coordinates |
474 |
|
|
475 |
+ |
haveError = 0; |
476 |
|
if( worldRank == 0 ){ |
477 |
|
finalOut << mpiSim->getTotAtoms() << "\n"; |
400 |
– |
|
401 |
– |
finalOut << entry_plug->box_x << "\t" |
402 |
– |
<< entry_plug->box_y << "\t" |
403 |
– |
<< entry_plug->box_z << "\n"; |
404 |
– |
|
405 |
– |
masterIndex = 0; |
406 |
– |
|
407 |
– |
for( i=0; i<nAtoms; i++ ){ |
408 |
– |
|
409 |
– |
sprintf( tempBuffer, |
410 |
– |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
411 |
– |
atoms[i]->getType(), |
412 |
– |
atoms[i]->getX(), |
413 |
– |
atoms[i]->getY(), |
414 |
– |
atoms[i]->getZ(), |
415 |
– |
atoms[i]->get_vx(), |
416 |
– |
atoms[i]->get_vy(), |
417 |
– |
atoms[i]->get_vz()); |
418 |
– |
strcpy( writeLine, tempBuffer ); |
419 |
– |
|
420 |
– |
if( atoms[i]->isDirectional() ){ |
421 |
– |
|
422 |
– |
dAtom = (DirectionalAtom *)atoms[i]; |
423 |
– |
dAtom->getQ( q ); |
424 |
– |
|
425 |
– |
sprintf( tempBuffer, |
426 |
– |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
427 |
– |
q[0], |
428 |
– |
q[1], |
429 |
– |
q[2], |
430 |
– |
q[3], |
431 |
– |
dAtom->getJx(), |
432 |
– |
dAtom->getJy(), |
433 |
– |
dAtom->getJz()); |
434 |
– |
strcat( writeLine, tempBuffer ); |
435 |
– |
} |
436 |
– |
else |
437 |
– |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
438 |
– |
|
439 |
– |
finalOut << writeLine; |
440 |
– |
masterIndex++; |
441 |
– |
} |
442 |
– |
finalOut.flush(); |
443 |
– |
} |
444 |
– |
|
445 |
– |
for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
446 |
– |
procIndex++){ |
478 |
|
|
479 |
< |
if( worldRank == 0 ){ |
480 |
< |
|
481 |
< |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
482 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
479 |
> |
finalOut << finalTime << ";\t" |
480 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
481 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
482 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
483 |
|
|
484 |
< |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
485 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
486 |
< |
|
456 |
< |
// Make sure where node 0 is writing to, matches where the |
457 |
< |
// receiving node expects it to be. |
458 |
< |
|
459 |
< |
if (masterIndex != nodeAtomsStart){ |
460 |
< |
sendError = 1; |
461 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
462 |
< |
MPI_COMM_WORLD); |
463 |
< |
sprintf(painCave.errMsg, |
464 |
< |
"DumpWriter error: atoms start index (%d) for " |
465 |
< |
"node %d not equal to master index (%d)", |
466 |
< |
nodeAtomsStart,procIndex,masterIndex ); |
467 |
< |
painCave.isFatal = 1; |
468 |
< |
simError(); |
469 |
< |
} |
470 |
< |
|
471 |
< |
sendError = 0; |
472 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
473 |
< |
MPI_COMM_WORLD); |
484 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
485 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
486 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
487 |
|
|
488 |
< |
// recieve the nodes writeLines |
488 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
489 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
490 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
491 |
|
|
492 |
< |
for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
493 |
< |
|
494 |
< |
mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
480 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
492 |
> |
//write out additional parameters, such as chi and eta |
493 |
> |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
494 |
> |
finalOut << endl; |
495 |
|
|
496 |
< |
finalOut << writeLine; |
497 |
< |
masterIndex++; |
484 |
< |
} |
496 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
497 |
> |
// Get the Node number which has this molecule: |
498 |
|
|
499 |
< |
finalOut.flush(); |
487 |
< |
} |
499 |
> |
which_node = AtomToProcMap[i]; |
500 |
|
|
501 |
< |
else if( worldRank == procIndex ){ |
501 |
> |
if (which_node == mpiSim->getMyNode()) { |
502 |
|
|
503 |
< |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
504 |
< |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
505 |
< |
|
506 |
< |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
507 |
< |
MPI_COMM_WORLD); |
508 |
< |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
497 |
< |
MPI_COMM_WORLD); |
498 |
< |
|
499 |
< |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
500 |
< |
MPI_COMM_WORLD, istatus); |
501 |
< |
if (sendError) MPIcheckPoint(); |
502 |
< |
|
503 |
< |
// send current node's configuration line by line. |
503 |
> |
which_atom = i; |
504 |
> |
local_index=-1; |
505 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
506 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
507 |
> |
} |
508 |
> |
if (local_index != -1) { |
509 |
|
|
510 |
< |
for( i=0; i<nAtoms; i++ ){ |
511 |
< |
|
510 |
> |
atoms[local_index]->getPos(pos); |
511 |
> |
atoms[local_index]->getVel(vel); |
512 |
> |
|
513 |
> |
sprintf( tempBuffer, |
514 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
515 |
> |
atoms[local_index]->getType(), |
516 |
> |
pos[0], |
517 |
> |
pos[1], |
518 |
> |
pos[2], |
519 |
> |
vel[0], |
520 |
> |
vel[1], |
521 |
> |
vel[2]); |
522 |
> |
strcpy( writeLine, tempBuffer ); |
523 |
> |
|
524 |
> |
if( atoms[local_index]->isDirectional() ){ |
525 |
> |
|
526 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
527 |
> |
dAtom->getQ( q ); |
528 |
> |
|
529 |
> |
sprintf( tempBuffer, |
530 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
531 |
> |
q[0], |
532 |
> |
q[1], |
533 |
> |
q[2], |
534 |
> |
q[3], |
535 |
> |
dAtom->getJx(), |
536 |
> |
dAtom->getJy(), |
537 |
> |
dAtom->getJz()); |
538 |
> |
strcat( writeLine, tempBuffer ); |
539 |
> |
} |
540 |
> |
else |
541 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
542 |
> |
} |
543 |
> |
else { |
544 |
> |
sprintf(painCave.errMsg, |
545 |
> |
"Atom %d not found on processor %d\n", |
546 |
> |
i, worldRank ); |
547 |
> |
haveError= 1; |
548 |
> |
simError(); |
549 |
> |
} |
550 |
> |
|
551 |
> |
if(haveError) nodeZeroError(); |
552 |
> |
|
553 |
> |
} |
554 |
> |
else { |
555 |
> |
|
556 |
> |
myStatus = 1; |
557 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
558 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
559 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
560 |
> |
MPI_COMM_WORLD); |
561 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
562 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
563 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
564 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
565 |
> |
|
566 |
> |
if(!myStatus) nodeZeroError(); |
567 |
> |
} |
568 |
> |
|
569 |
> |
finalOut << writeLine; |
570 |
> |
} |
571 |
> |
|
572 |
> |
// kill everyone off: |
573 |
> |
myStatus = -1; |
574 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
575 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
576 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
577 |
> |
} |
578 |
> |
|
579 |
> |
} else { |
580 |
> |
|
581 |
> |
done = 0; |
582 |
> |
while (!done) { |
583 |
> |
|
584 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
585 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
586 |
> |
|
587 |
> |
if(!myStatus) anonymousNodeDie(); |
588 |
> |
|
589 |
> |
if(myStatus < 0) break; |
590 |
> |
|
591 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
592 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
593 |
> |
|
594 |
> |
myStatus = 1; |
595 |
> |
local_index=-1; |
596 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
597 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
598 |
> |
} |
599 |
> |
if (local_index != -1) { |
600 |
> |
|
601 |
> |
atoms[local_index]->getPos(pos); |
602 |
> |
atoms[local_index]->getVel(vel); |
603 |
> |
|
604 |
> |
//format the line |
605 |
|
sprintf( tempBuffer, |
606 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
607 |
< |
atoms[i]->getType(), |
608 |
< |
atoms[i]->getX(), |
609 |
< |
atoms[i]->getY(), |
610 |
< |
atoms[i]->getZ(), |
611 |
< |
atoms[i]->get_vx(), |
612 |
< |
atoms[i]->get_vy(), |
613 |
< |
atoms[i]->get_vz()); |
607 |
> |
atoms[local_index]->getType(), |
608 |
> |
pos[0], |
609 |
> |
pos[1], |
610 |
> |
pos[2], |
611 |
> |
vel[0], |
612 |
> |
vel[1], |
613 |
> |
vel[2]); // check here. |
614 |
|
strcpy( writeLine, tempBuffer ); |
615 |
< |
|
616 |
< |
if( atoms[i]->isDirectional() ){ |
617 |
< |
|
618 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
615 |
> |
|
616 |
> |
if( atoms[local_index]->isDirectional() ){ |
617 |
> |
|
618 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
619 |
|
dAtom->getQ( q ); |
620 |
< |
|
620 |
> |
|
621 |
|
sprintf( tempBuffer, |
622 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
623 |
|
q[0], |
629 |
|
dAtom->getJz()); |
630 |
|
strcat( writeLine, tempBuffer ); |
631 |
|
} |
632 |
< |
else |
632 |
> |
else{ |
633 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
634 |
< |
|
537 |
< |
mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
538 |
< |
MPI_COMM_WORLD); |
634 |
> |
} |
635 |
|
} |
636 |
+ |
else { |
637 |
+ |
sprintf(painCave.errMsg, |
638 |
+ |
"Atom %d not found on processor %d\n", |
639 |
+ |
which_atom, worldRank ); |
640 |
+ |
myStatus = 0; |
641 |
+ |
simError(); |
642 |
+ |
|
643 |
+ |
strcpy( writeLine, "Hello, I'm an error.\n"); |
644 |
+ |
} |
645 |
+ |
|
646 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
647 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
648 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
649 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
650 |
|
} |
541 |
– |
|
542 |
– |
sprintf(checkPointMsg,"Node %d sent dump configuration.", |
543 |
– |
procIndex); |
544 |
– |
MPIcheckPoint(); |
651 |
|
} |
652 |
+ |
finalOut.flush(); |
653 |
+ |
sprintf( checkPointMsg, |
654 |
+ |
"Sucessfully took a dump.\n"); |
655 |
+ |
MPIcheckPoint(); |
656 |
|
|
657 |
|
if( worldRank == 0 ) finalOut.close(); |
548 |
– |
|
549 |
– |
|
658 |
|
#endif // is_mpi |
659 |
|
} |
660 |
+ |
|
661 |
+ |
|
662 |
+ |
|
663 |
+ |
#ifdef IS_MPI |
664 |
+ |
|
665 |
+ |
// a couple of functions to let us escape the write loop |
666 |
+ |
|
667 |
+ |
void dWrite::nodeZeroError( void ){ |
668 |
+ |
int j, myStatus; |
669 |
+ |
|
670 |
+ |
myStatus = 0; |
671 |
+ |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
672 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, j, |
673 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
674 |
+ |
} |
675 |
+ |
|
676 |
+ |
|
677 |
+ |
MPI_Finalize(); |
678 |
+ |
exit (0); |
679 |
+ |
|
680 |
+ |
} |
681 |
+ |
|
682 |
+ |
void dWrite::anonymousNodeDie( void ){ |
683 |
+ |
|
684 |
+ |
MPI_Finalize(); |
685 |
+ |
exit (0); |
686 |
+ |
} |
687 |
+ |
|
688 |
+ |
#endif //is_mpi |