# | Line 1 | Line 1 | |
---|---|---|
1 | #define _FILE_OFFSET_BITS 64 | |
2 | ||
3 | < | #include <cstring> |
3 | > | #include <string.h> |
4 | #include <iostream> | |
5 | #include <fstream> | |
6 | + | #include <algorithm> |
7 | + | #include <utility> |
8 | ||
9 | #ifdef IS_MPI | |
10 | #include <mpi.h> | |
11 | #include "mpiSimulation.hpp" | |
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 ); |
14 | > | void DieDieDie( void ); |
15 | } | |
16 | ||
17 | using namespace dWrite; | |
# | Line 28 | Line 27 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | |
27 | #ifdef IS_MPI | |
28 | if(worldRank == 0 ){ | |
29 | #endif // is_mpi | |
30 | < | |
31 | < | strcpy( outName, entry_plug->sampleName ); |
32 | < | |
33 | < | outFile.open(outName, ios::out | ios::trunc ); |
34 | < | |
35 | < | if( !outFile ){ |
37 | < | |
30 | > | |
31 | > | |
32 | > | dumpFile.open(entry_plug->sampleName, ios::out | ios::trunc ); |
33 | > | |
34 | > | if( !dumpFile ){ |
35 | > | |
36 | sprintf( painCave.errMsg, | |
37 | "Could not open \"%s\" for dump output.\n", | |
38 | < | outName); |
38 | > | entry_plug->sampleName); |
39 | painCave.isFatal = 1; | |
40 | simError(); | |
41 | } | |
42 | ||
43 | < | //outFile.setf( ios::scientific ); |
43 | > | finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); |
44 | > | if( !finalOut ){ |
45 | > | sprintf( painCave.errMsg, |
46 | > | "Could not open \"%s\" for final dump output.\n", |
47 | > | entry_plug->finalName ); |
48 | > | painCave.isFatal = 1; |
49 | > | simError(); |
50 | > | } |
51 | ||
52 | #ifdef IS_MPI | |
53 | } | |
54 | ||
55 | + | //sort the local atoms by global index |
56 | + | sortByGlobalIndex(); |
57 | + | |
58 | sprintf( checkPointMsg, | |
59 | "Sucessfully opened output file for dumping.\n"); | |
60 | MPIcheckPoint(); | |
# | Line 59 | Line 67 | DumpWriter::~DumpWriter( ){ | |
67 | if(worldRank == 0 ){ | |
68 | #endif // is_mpi | |
69 | ||
70 | < | outFile.close(); |
70 | > | dumpFile.close(); |
71 | > | finalOut.close(); |
72 | ||
73 | #ifdef IS_MPI | |
74 | } | |
75 | #endif // is_mpi | |
76 | } | |
77 | ||
78 | < | void DumpWriter::writeDump( double currentTime ){ |
78 | > | #ifdef IS_MPI |
79 | > | |
80 | > | /** |
81 | > | * A hook function to load balancing |
82 | > | */ |
83 | > | |
84 | > | void DumpWriter::update(){ |
85 | > | sortByGlobalIndex(); |
86 | > | } |
87 | ||
88 | + | /** |
89 | + | * Auxiliary sorting function |
90 | + | */ |
91 | + | |
92 | + | bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){ |
93 | + | return p1.second < p2.second; |
94 | + | } |
95 | + | |
96 | + | /** |
97 | + | * Sorting the local index by global index |
98 | + | */ |
99 | + | |
100 | + | void DumpWriter::sortByGlobalIndex(){ |
101 | + | Atom** atoms = entry_plug->atoms; |
102 | + | |
103 | + | indexArray.clear(); |
104 | + | |
105 | + | for(int i = 0; i < mpiSim->getMyNlocal();i++) |
106 | + | indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex())); |
107 | + | |
108 | + | sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); |
109 | + | } |
110 | + | #endif |
111 | + | |
112 | + | void DumpWriter::writeDump(double currentTime){ |
113 | + | |
114 | + | vector<ofstream*> fileStreams; |
115 | + | |
116 | + | #ifdef IS_MPI |
117 | + | if(worldRank == 0 ){ |
118 | + | finalOut.seekp(0); |
119 | + | } |
120 | + | #endif // is_mpi |
121 | + | |
122 | + | fileStreams.push_back(&finalOut); |
123 | + | fileStreams.push_back(&dumpFile); |
124 | + | |
125 | + | writeFrame(fileStreams, currentTime); |
126 | + | |
127 | + | } |
128 | + | |
129 | + | void DumpWriter::writeFinal(double currentTime){ |
130 | + | |
131 | + | vector<ofstream*> fileStreams; |
132 | + | |
133 | + | #ifdef IS_MPI |
134 | + | if(worldRank == 0 ){ |
135 | + | finalOut.seekp(0); |
136 | + | } |
137 | + | #endif // is_mpi |
138 | + | |
139 | + | fileStreams.push_back(&finalOut); |
140 | + | writeFrame(fileStreams, currentTime); |
141 | + | |
142 | + | } |
143 | + | |
144 | + | void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){ |
145 | + | |
146 | const int BUFFERSIZE = 2000; | |
147 | + | const int MINIBUFFERSIZE = 100; |
148 | + | |
149 | char tempBuffer[BUFFERSIZE]; | |
150 | char writeLine[BUFFERSIZE]; | |
151 | ||
152 | < | int i; |
152 | > | int i, k; |
153 | > | |
154 | #ifdef IS_MPI | |
155 | < | int j, which_node, done, which_atom, local_index; |
155 | > | |
156 | > | int *potatoes; |
157 | > | int myPotato; |
158 | > | |
159 | > | int nProc; |
160 | > | int j, which_node, done, which_atom, local_index, currentIndex; |
161 | > | double atomData6[6]; |
162 | > | double atomData13[13]; |
163 | > | int isDirectional; |
164 | > | char* atomTypeString; |
165 | > | char MPIatomTypeString[MINIBUFFERSIZE]; |
166 | > | |
167 | #else //is_mpi | |
168 | int nAtoms = entry_plug->n_atoms; | |
169 | #endif //is_mpi | |
# | Line 83 | Line 172 | void DumpWriter::writeDump( double currentTime ){ | |
172 | DirectionalAtom* dAtom; | |
173 | Atom** atoms = entry_plug->atoms; | |
174 | double pos[3], vel[3]; | |
86 | – | |
87 | – | |
88 | – | // write current frame to the eor file |
175 | ||
90 | – | this->writeFinal( currentTime ); |
91 | – | |
176 | #ifndef IS_MPI | |
177 | < | |
178 | < | outFile << nAtoms << "\n"; |
179 | < | |
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" |
177 | > | |
178 | > | for(k = 0; k < outFile.size(); k++){ |
179 | > | *outFile[k] << nAtoms << "\n"; |
180 | ||
181 | < | << entry_plug->Hmat[0][1] << "\t" |
182 | < | << entry_plug->Hmat[1][1] << "\t" |
183 | < | << entry_plug->Hmat[2][1] << ";\t" |
181 | > | *outFile[k] << currentTime << ";\t" |
182 | > | << entry_plug->Hmat[0][0] << "\t" |
183 | > | << entry_plug->Hmat[1][0] << "\t" |
184 | > | << entry_plug->Hmat[2][0] << ";\t" |
185 | > | |
186 | > | << entry_plug->Hmat[0][1] << "\t" |
187 | > | << entry_plug->Hmat[1][1] << "\t" |
188 | > | << entry_plug->Hmat[2][1] << ";\t" |
189 | ||
190 | < | << entry_plug->Hmat[0][2] << "\t" |
191 | < | << entry_plug->Hmat[1][2] << "\t" |
192 | < | << entry_plug->Hmat[2][2] << ";\n"; |
193 | < | |
190 | > | << entry_plug->Hmat[0][2] << "\t" |
191 | > | << entry_plug->Hmat[1][2] << "\t" |
192 | > | << entry_plug->Hmat[2][2] << ";"; |
193 | > | |
194 | > | //write out additional parameters, such as chi and eta |
195 | > | *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; |
196 | > | } |
197 | > | |
198 | for( i=0; i<nAtoms; i++ ){ | |
199 | < | |
199 | > | |
200 | atoms[i]->getPos(pos); | |
201 | atoms[i]->getVel(vel); | |
202 | ||
# | Line 123 | Line 212 | void DumpWriter::writeDump( double currentTime ){ | |
212 | strcpy( writeLine, tempBuffer ); | |
213 | ||
214 | if( atoms[i]->isDirectional() ){ | |
215 | < | |
215 | > | |
216 | dAtom = (DirectionalAtom *)atoms[i]; | |
217 | dAtom->getQ( q ); | |
218 | < | |
218 | > | |
219 | sprintf( tempBuffer, | |
220 | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", | |
221 | q[0], | |
# | Line 140 | Line 229 | void DumpWriter::writeDump( double currentTime ){ | |
229 | } | |
230 | else | |
231 | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); | |
232 | < | |
233 | < | outFile << writeLine; |
232 | > | |
233 | > | for(k = 0; k < outFile.size(); k++) |
234 | > | *outFile[k] << writeLine; |
235 | } | |
146 | – | outFile.flush(); |
236 | ||
237 | #else // is_mpi | |
238 | ||
239 | < | // first thing first, suspend fatalities. |
240 | < | painCave.isEventLoop = 1; |
239 | > | /* code to find maximum tag value */ |
240 | > | |
241 | > | int *tagub, flag, MAXTAG; |
242 | > | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
243 | > | if (flag) { |
244 | > | MAXTAG = *tagub; |
245 | > | } else { |
246 | > | MAXTAG = 32767; |
247 | > | } |
248 | ||
153 | – | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
249 | int haveError; | |
250 | ||
251 | MPI_Status istatus; | |
252 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
253 | < | |
253 | > | |
254 | // write out header and node 0's coordinates | |
255 | < | |
255 | > | |
256 | if( worldRank == 0 ){ | |
257 | < | outFile << mpiSim->getTotAtoms() << "\n"; |
258 | < | |
259 | < | outFile << currentTime << ";\t" |
260 | < | << entry_plug->Hmat[0][0] << "\t" |
261 | < | << entry_plug->Hmat[1][0] << "\t" |
262 | < | << entry_plug->Hmat[2][0] << ";\t" |
263 | < | |
264 | < | << entry_plug->Hmat[0][1] << "\t" |
265 | < | << entry_plug->Hmat[1][1] << "\t" |
171 | < | << entry_plug->Hmat[2][1] << ";\t" |
172 | < | |
173 | < | << entry_plug->Hmat[0][2] << "\t" |
174 | < | << entry_plug->Hmat[1][2] << "\t" |
175 | < | << entry_plug->Hmat[2][2] << ";\n"; |
257 | > | |
258 | > | // Node 0 needs a list of the magic potatoes for each processor; |
259 | > | |
260 | > | nProc = mpiSim->getNumberProcessors(); |
261 | > | potatoes = new int[nProc]; |
262 | > | |
263 | > | //write out the comment lines |
264 | > | for (i = 0; i < nProc; i++) |
265 | > | potatoes[i] = 0; |
266 | ||
267 | < | outFile.flush(); |
267 | > | for(k = 0; k < outFile.size(); k++){ |
268 | > | *outFile[k] << mpiSim->getTotAtoms() << "\n"; |
269 | > | |
270 | > | *outFile[k] << currentTime << ";\t" |
271 | > | << entry_plug->Hmat[0][0] << "\t" |
272 | > | << entry_plug->Hmat[1][0] << "\t" |
273 | > | << entry_plug->Hmat[2][0] << ";\t" |
274 | > | |
275 | > | << entry_plug->Hmat[0][1] << "\t" |
276 | > | << entry_plug->Hmat[1][1] << "\t" |
277 | > | << entry_plug->Hmat[2][1] << ";\t" |
278 | > | |
279 | > | << entry_plug->Hmat[0][2] << "\t" |
280 | > | << entry_plug->Hmat[1][2] << "\t" |
281 | > | << entry_plug->Hmat[2][2] << ";"; |
282 | > | |
283 | > | *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; |
284 | > | } |
285 | > | |
286 | > | currentIndex = 0; |
287 | > | |
288 | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { | |
289 | + | |
290 | // Get the Node number which has this atom; | |
291 | ||
292 | < | which_node = AtomToProcMap[i]; |
293 | < | |
294 | < | if (which_node == 0 ) { |
292 | > | which_node = AtomToProcMap[i]; |
293 | > | |
294 | > | if (which_node != 0) { |
295 | > | |
296 | > | if (potatoes[which_node] + 3 >= MAXTAG) { |
297 | > | // The potato was going to exceed the maximum value, |
298 | > | // so wrap this processor potato back to 0: |
299 | > | |
300 | > | potatoes[which_node] = 0; |
301 | > | MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
302 | > | |
303 | > | } |
304 | > | |
305 | > | myPotato = potatoes[which_node]; |
306 | > | |
307 | > | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
308 | > | myPotato, MPI_COMM_WORLD, &istatus); |
309 | > | |
310 | > | atomTypeString = MPIatomTypeString; |
311 | ||
312 | < | haveError = 0; |
313 | < | which_atom = i; |
314 | < | local_index=-1; |
315 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
316 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
312 | > | myPotato++; |
313 | > | |
314 | > | MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
315 | > | myPotato, MPI_COMM_WORLD, &istatus); |
316 | > | |
317 | > | myPotato++; |
318 | > | |
319 | > | if (isDirectional) { |
320 | > | MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node, |
321 | > | myPotato, MPI_COMM_WORLD, &istatus); |
322 | > | } else { |
323 | > | MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node, |
324 | > | myPotato, MPI_COMM_WORLD, &istatus); |
325 | } | |
326 | < | if (local_index != -1) { |
327 | < | //format the line |
328 | < | |
194 | < | atoms[local_index]->getPos(pos); |
195 | < | atoms[local_index]->getVel(vel); |
326 | > | |
327 | > | myPotato++; |
328 | > | potatoes[which_node] = myPotato; |
329 | ||
330 | < | sprintf( tempBuffer, |
331 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
332 | < | atoms[local_index]->getType(), |
333 | < | pos[0], |
334 | < | pos[1], |
335 | < | pos[2], |
336 | < | vel[0], |
337 | < | vel[1], |
338 | < | vel[2]); // check here. |
339 | < | strcpy( writeLine, tempBuffer ); |
340 | < | |
330 | > | } else { |
331 | > | |
332 | > | haveError = 0; |
333 | > | which_atom = i; |
334 | > | |
335 | > | local_index = indexArray[currentIndex].first; |
336 | > | |
337 | > | if (which_atom == indexArray[currentIndex].second) { |
338 | > | |
339 | > | atomTypeString = atoms[local_index]->getType(); |
340 | > | |
341 | > | atoms[local_index]->getPos(pos); |
342 | > | atoms[local_index]->getVel(vel); |
343 | > | |
344 | > | atomData6[0] = pos[0]; |
345 | > | atomData6[1] = pos[1]; |
346 | > | atomData6[2] = pos[2]; |
347 | > | |
348 | > | atomData6[3] = vel[0]; |
349 | > | atomData6[4] = vel[1]; |
350 | > | atomData6[5] = vel[2]; |
351 | > | |
352 | > | isDirectional = 0; |
353 | > | |
354 | if( atoms[local_index]->isDirectional() ){ | |
355 | + | |
356 | + | isDirectional = 1; |
357 | ||
358 | dAtom = (DirectionalAtom *)atoms[local_index]; | |
359 | dAtom->getQ( q ); | |
212 | – | |
213 | – | sprintf( tempBuffer, |
214 | – | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
215 | – | q[0], |
216 | – | q[1], |
217 | – | q[2], |
218 | – | q[3], |
219 | – | dAtom->getJx(), |
220 | – | dAtom->getJy(), |
221 | – | dAtom->getJz()); |
222 | – | strcat( writeLine, tempBuffer ); |
223 | – | |
224 | – | } |
225 | – | else |
226 | – | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
227 | – | } |
228 | – | else { |
229 | – | sprintf(painCave.errMsg, |
230 | – | "Atom %d not found on processor %d\n", |
231 | – | i, worldRank ); |
232 | – | haveError= 1; |
233 | – | simError(); |
234 | – | } |
235 | – | |
236 | – | if(haveError) nodeZeroError(); |
360 | ||
361 | + | for (int j = 0; j < 6 ; j++) |
362 | + | atomData13[j] = atomData6[j]; |
363 | + | |
364 | + | atomData13[6] = q[0]; |
365 | + | atomData13[7] = q[1]; |
366 | + | atomData13[8] = q[2]; |
367 | + | atomData13[9] = q[3]; |
368 | + | |
369 | + | atomData13[10] = dAtom->getJx(); |
370 | + | atomData13[11] = dAtom->getJy(); |
371 | + | atomData13[12] = dAtom->getJz(); |
372 | + | } |
373 | + | |
374 | + | } else { |
375 | + | sprintf(painCave.errMsg, |
376 | + | "Atom %d not found on processor %d\n", |
377 | + | i, worldRank ); |
378 | + | haveError= 1; |
379 | + | simError(); |
380 | + | } |
381 | + | |
382 | + | if(haveError) DieDieDie(); |
383 | + | |
384 | + | currentIndex ++; |
385 | } | |
386 | < | else { |
387 | < | myStatus = 1; |
388 | < | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
242 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
243 | < | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
244 | < | MPI_COMM_WORLD); |
245 | < | MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
246 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
247 | < | MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
248 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
386 | > | // If we've survived to here, format the line: |
387 | > | |
388 | > | if (!isDirectional) { |
389 | ||
390 | < | if(!myStatus) nodeZeroError(); |
390 | > | sprintf( writeLine, |
391 | > | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
392 | > | atomTypeString, |
393 | > | atomData6[0], |
394 | > | atomData6[1], |
395 | > | atomData6[2], |
396 | > | atomData6[3], |
397 | > | atomData6[4], |
398 | > | atomData6[5]); |
399 | ||
400 | + | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
401 | + | |
402 | + | } else { |
403 | + | |
404 | + | sprintf( writeLine, |
405 | + | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
406 | + | atomTypeString, |
407 | + | atomData13[0], |
408 | + | atomData13[1], |
409 | + | atomData13[2], |
410 | + | atomData13[3], |
411 | + | atomData13[4], |
412 | + | atomData13[5], |
413 | + | atomData13[6], |
414 | + | atomData13[7], |
415 | + | atomData13[8], |
416 | + | atomData13[9], |
417 | + | atomData13[10], |
418 | + | atomData13[11], |
419 | + | atomData13[12]); |
420 | + | |
421 | } | |
422 | ||
423 | < | outFile << writeLine; |
424 | < | outFile.flush(); |
423 | > | for(k = 0; k < outFile.size(); k++) |
424 | > | *outFile[k] << writeLine; |
425 | } | |
426 | ||
427 | < | // kill everyone off: |
428 | < | myStatus = -1; |
429 | < | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
430 | < | MPI_Send(&myStatus, 1, MPI_INT, j, |
431 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
263 | < | } |
427 | > | for(k = 0; k < outFile.size(); k++) |
428 | > | outFile[k]->flush(); |
429 | > | |
430 | > | sprintf( checkPointMsg, |
431 | > | "Sucessfully took a dump.\n"); |
432 | ||
433 | + | MPIcheckPoint(); |
434 | + | |
435 | + | delete[] potatoes; |
436 | + | |
437 | } else { | |
438 | + | |
439 | + | // worldRank != 0, so I'm a remote node. |
440 | + | |
441 | + | // Set my magic potato to 0: |
442 | + | |
443 | + | myPotato = 0; |
444 | + | currentIndex = 0; |
445 | ||
446 | < | done = 0; |
268 | < | while (!done) { |
446 | > | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
447 | ||
448 | < | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
271 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
272 | < | |
273 | < | if(!myStatus) anonymousNodeDie(); |
448 | > | // Am I the node which has this atom? |
449 | ||
450 | < | if(myStatus < 0) break; |
450 | > | if (AtomToProcMap[i] == worldRank) { |
451 | ||
452 | < | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
453 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
454 | < | |
455 | < | myStatus = 1; |
456 | < | local_index=-1; |
282 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
283 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
284 | < | } |
285 | < | if (local_index != -1) { |
286 | < | //format the line |
452 | > | if (myPotato + 3 >= MAXTAG) { |
453 | > | |
454 | > | // The potato was going to exceed the maximum value, |
455 | > | // so wrap this processor potato back to 0 (and block until |
456 | > | // node 0 says we can go: |
457 | ||
458 | < | atoms[local_index]->getPos(pos); |
459 | < | atoms[local_index]->getVel(vel); |
458 | > | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
459 | > | |
460 | > | } |
461 | > | which_atom = i; |
462 | > | local_index = indexArray[currentIndex].first; |
463 | > | |
464 | > | if (which_atom == indexArray[currentIndex].second) { |
465 | > | |
466 | > | atomTypeString = atoms[local_index]->getType(); |
467 | ||
468 | < | sprintf( tempBuffer, |
469 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
293 | < | atoms[local_index]->getType(), |
294 | < | pos[0], |
295 | < | pos[1], |
296 | < | pos[2], |
297 | < | vel[0], |
298 | < | vel[1], |
299 | < | vel[2]); // check here. |
300 | < | strcpy( writeLine, tempBuffer ); |
301 | < | |
302 | < | if( atoms[local_index]->isDirectional() ){ |
303 | < | |
304 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
305 | < | dAtom->getQ( q ); |
306 | < | |
307 | < | sprintf( tempBuffer, |
308 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
309 | < | q[0], |
310 | < | q[1], |
311 | < | q[2], |
312 | < | q[3], |
313 | < | dAtom->getJx(), |
314 | < | dAtom->getJy(), |
315 | < | dAtom->getJz()); |
316 | < | strcat( writeLine, tempBuffer ); |
317 | < | } |
318 | < | else{ |
319 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
320 | < | } |
321 | < | } |
322 | < | else { |
323 | < | sprintf(painCave.errMsg, |
324 | < | "Atom %d not found on processor %d\n", |
325 | < | which_atom, worldRank ); |
326 | < | myStatus = 0; |
327 | < | simError(); |
468 | > | atoms[local_index]->getPos(pos); |
469 | > | atoms[local_index]->getVel(vel); |
470 | ||
471 | < | strcpy( writeLine, "Hello, I'm an error.\n"); |
472 | < | } |
471 | > | atomData6[0] = pos[0]; |
472 | > | atomData6[1] = pos[1]; |
473 | > | atomData6[2] = pos[2]; |
474 | ||
475 | < | MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
476 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
477 | < | MPI_Send( &myStatus, 1, MPI_INT, 0, |
478 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
479 | < | } |
337 | < | } |
338 | < | outFile.flush(); |
339 | < | sprintf( checkPointMsg, |
340 | < | "Sucessfully took a dump.\n"); |
341 | < | MPIcheckPoint(); |
475 | > | atomData6[3] = vel[0]; |
476 | > | atomData6[4] = vel[1]; |
477 | > | atomData6[5] = vel[2]; |
478 | > | |
479 | > | isDirectional = 0; |
480 | ||
481 | < | // last thing last, enable fatalities. |
344 | < | painCave.isEventLoop = 0; |
481 | > | if( atoms[local_index]->isDirectional() ){ |
482 | ||
483 | < | #endif // is_mpi |
484 | < | } |
485 | < | |
486 | < | void DumpWriter::writeFinal(double finalTime){ |
487 | < | |
488 | < | char finalName[500]; |
489 | < | ofstream finalOut; |
490 | < | |
491 | < | const int BUFFERSIZE = 2000; |
492 | < | char tempBuffer[BUFFERSIZE]; |
493 | < | char writeLine[BUFFERSIZE]; |
494 | < | |
358 | < | double q[4]; |
359 | < | DirectionalAtom* dAtom; |
360 | < | Atom** atoms = entry_plug->atoms; |
361 | < | int i; |
362 | < | #ifdef IS_MPI |
363 | < | int j, which_node, done, which_atom, local_index; |
364 | < | #else //is_mpi |
365 | < | int nAtoms = entry_plug->n_atoms; |
366 | < | #endif //is_mpi |
483 | > | isDirectional = 1; |
484 | > | |
485 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
486 | > | dAtom->getQ( q ); |
487 | > | |
488 | > | for (int j = 0; j < 6 ; j++) |
489 | > | atomData13[j] = atomData6[j]; |
490 | > | |
491 | > | atomData13[6] = q[0]; |
492 | > | atomData13[7] = q[1]; |
493 | > | atomData13[8] = q[2]; |
494 | > | atomData13[9] = q[3]; |
495 | ||
496 | < | double pos[3], vel[3]; |
497 | < | |
498 | < | #ifdef IS_MPI |
499 | < | if(worldRank == 0 ){ |
372 | < | #endif // is_mpi |
373 | < | |
374 | < | strcpy( finalName, entry_plug->finalName ); |
375 | < | |
376 | < | finalOut.open( finalName, ios::out | ios::trunc ); |
377 | < | if( !finalOut ){ |
378 | < | sprintf( painCave.errMsg, |
379 | < | "Could not open \"%s\" for final dump output.\n", |
380 | < | finalName ); |
381 | < | painCave.isFatal = 1; |
382 | < | simError(); |
383 | < | } |
384 | < | |
385 | < | // finalOut.setf( ios::scientific ); |
386 | < | |
387 | < | #ifdef IS_MPI |
388 | < | } |
389 | < | |
390 | < | sprintf(checkPointMsg,"Opened file for final configuration\n"); |
391 | < | MPIcheckPoint(); |
392 | < | |
393 | < | #endif //is_mpi |
496 | > | atomData13[10] = dAtom->getJx(); |
497 | > | atomData13[11] = dAtom->getJy(); |
498 | > | atomData13[12] = dAtom->getJz(); |
499 | > | } |
500 | ||
501 | < | |
502 | < | #ifndef IS_MPI |
503 | < | |
504 | < | finalOut << nAtoms << "\n"; |
505 | < | |
506 | < | finalOut << finalTime << ";\t" |
507 | < | << entry_plug->Hmat[0][0] << "\t" |
402 | < | << entry_plug->Hmat[1][0] << "\t" |
403 | < | << entry_plug->Hmat[2][0] << ";\t" |
404 | < | |
405 | < | << entry_plug->Hmat[0][1] << "\t" |
406 | < | << entry_plug->Hmat[1][1] << "\t" |
407 | < | << entry_plug->Hmat[2][1] << ";\t" |
408 | < | |
409 | < | << entry_plug->Hmat[0][2] << "\t" |
410 | < | << entry_plug->Hmat[1][2] << "\t" |
411 | < | << entry_plug->Hmat[2][2] << ";\n"; |
412 | < | |
413 | < | for( i=0; i<nAtoms; i++ ){ |
414 | < | |
415 | < | atoms[i]->getPos(pos); |
416 | < | atoms[i]->getVel(vel); |
417 | < | |
418 | < | sprintf( tempBuffer, |
419 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
420 | < | atoms[i]->getType(), |
421 | < | pos[0], |
422 | < | pos[1], |
423 | < | pos[2], |
424 | < | vel[0], |
425 | < | vel[1], |
426 | < | vel[2]); |
427 | < | strcpy( writeLine, tempBuffer ); |
501 | > | } else { |
502 | > | sprintf(painCave.errMsg, |
503 | > | "Atom %d not found on processor %d\n", |
504 | > | i, worldRank ); |
505 | > | haveError= 1; |
506 | > | simError(); |
507 | > | } |
508 | ||
509 | < | if( atoms[i]->isDirectional() ){ |
430 | < | |
431 | < | dAtom = (DirectionalAtom *)atoms[i]; |
432 | < | dAtom->getQ( q ); |
433 | < | |
434 | < | sprintf( tempBuffer, |
435 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
436 | < | q[0], |
437 | < | q[1], |
438 | < | q[2], |
439 | < | q[3], |
440 | < | dAtom->getJx(), |
441 | < | dAtom->getJy(), |
442 | < | dAtom->getJz()); |
443 | < | strcat( writeLine, tempBuffer ); |
444 | < | } |
445 | < | else |
446 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
447 | < | |
448 | < | finalOut << writeLine; |
449 | < | } |
450 | < | finalOut.flush(); |
451 | < | finalOut.close(); |
509 | > | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
510 | ||
511 | < | #else // is_mpi |
512 | < | |
455 | < | // first thing first, suspend fatalities. |
456 | < | painCave.isEventLoop = 1; |
511 | > | // null terminate the string before sending (just in case): |
512 | > | MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
513 | ||
514 | < | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
515 | < | int haveError; |
514 | > | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
515 | > | myPotato, MPI_COMM_WORLD); |
516 | > | |
517 | > | myPotato++; |
518 | ||
519 | < | MPI_Status istatus; |
520 | < | int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
519 | > | MPI_Send(&isDirectional, 1, MPI_INT, 0, |
520 | > | myPotato, MPI_COMM_WORLD); |
521 | > | |
522 | > | myPotato++; |
523 | > | |
524 | > | if (isDirectional) { |
525 | ||
526 | < | // write out header and node 0's coordinates |
527 | < | |
528 | < | haveError = 0; |
529 | < | if( worldRank == 0 ){ |
468 | < | finalOut << mpiSim->getTotAtoms() << "\n"; |
469 | < | |
470 | < | finalOut << finalTime << ";\t" |
471 | < | << entry_plug->Hmat[0][0] << "\t" |
472 | < | << entry_plug->Hmat[1][0] << "\t" |
473 | < | << entry_plug->Hmat[2][0] << ";\t" |
474 | < | |
475 | < | << entry_plug->Hmat[0][1] << "\t" |
476 | < | << entry_plug->Hmat[1][1] << "\t" |
477 | < | << entry_plug->Hmat[2][1] << ";\t" |
478 | < | |
479 | < | << entry_plug->Hmat[0][2] << "\t" |
480 | < | << entry_plug->Hmat[1][2] << "\t" |
481 | < | << entry_plug->Hmat[2][2] << ";\n"; |
482 | < | |
483 | < | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
484 | < | // Get the Node number which has this molecule: |
485 | < | |
486 | < | which_node = AtomToProcMap[i]; |
487 | < | |
488 | < | if (which_node == mpiSim->getMyNode()) { |
526 | > | MPI_Send(atomData13, 13, MPI_DOUBLE, 0, |
527 | > | myPotato, MPI_COMM_WORLD); |
528 | > | |
529 | > | } else { |
530 | ||
531 | < | which_atom = i; |
532 | < | local_index=-1; |
492 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
493 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
531 | > | MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
532 | > | myPotato, MPI_COMM_WORLD); |
533 | } | |
495 | – | if (local_index != -1) { |
534 | ||
535 | < | atoms[local_index]->getPos(pos); |
536 | < | atoms[local_index]->getVel(vel); |
499 | < | |
500 | < | sprintf( tempBuffer, |
501 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
502 | < | atoms[local_index]->getType(), |
503 | < | pos[0], |
504 | < | pos[1], |
505 | < | pos[2], |
506 | < | vel[0], |
507 | < | vel[1], |
508 | < | vel[2]); |
509 | < | strcpy( writeLine, tempBuffer ); |
510 | < | |
511 | < | if( atoms[local_index]->isDirectional() ){ |
512 | < | |
513 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
514 | < | dAtom->getQ( q ); |
515 | < | |
516 | < | sprintf( tempBuffer, |
517 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
518 | < | q[0], |
519 | < | q[1], |
520 | < | q[2], |
521 | < | q[3], |
522 | < | dAtom->getJx(), |
523 | < | dAtom->getJy(), |
524 | < | dAtom->getJz()); |
525 | < | strcat( writeLine, tempBuffer ); |
526 | < | } |
527 | < | else |
528 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
529 | < | } |
530 | < | else { |
531 | < | sprintf(painCave.errMsg, |
532 | < | "Atom %d not found on processor %d\n", |
533 | < | i, worldRank ); |
534 | < | haveError= 1; |
535 | < | simError(); |
536 | < | } |
537 | < | |
538 | < | if(haveError) nodeZeroError(); |
539 | < | |
540 | < | } |
541 | < | else { |
542 | < | |
543 | < | myStatus = 1; |
544 | < | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
545 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
546 | < | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
547 | < | MPI_COMM_WORLD); |
548 | < | MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
549 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
550 | < | MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
551 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
552 | < | |
553 | < | if(!myStatus) nodeZeroError(); |
535 | > | myPotato++; |
536 | > | currentIndex++; |
537 | } | |
555 | – | |
556 | – | finalOut << writeLine; |
538 | } | |
558 | – | |
559 | – | // kill everyone off: |
560 | – | myStatus = -1; |
561 | – | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
562 | – | MPI_Send(&myStatus, 1, MPI_INT, j, |
563 | – | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
564 | – | } |
539 | ||
540 | < | } else { |
540 | > | sprintf( checkPointMsg, |
541 | > | "Sucessfully took a dump.\n"); |
542 | > | MPIcheckPoint(); |
543 | ||
544 | < | done = 0; |
569 | < | while (!done) { |
570 | < | |
571 | < | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
572 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
573 | < | |
574 | < | if(!myStatus) anonymousNodeDie(); |
575 | < | |
576 | < | if(myStatus < 0) break; |
577 | < | |
578 | < | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
579 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
580 | < | |
581 | < | myStatus = 1; |
582 | < | local_index=-1; |
583 | < | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
584 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
585 | < | } |
586 | < | if (local_index != -1) { |
587 | < | |
588 | < | atoms[local_index]->getPos(pos); |
589 | < | atoms[local_index]->getVel(vel); |
590 | < | |
591 | < | //format the line |
592 | < | sprintf( tempBuffer, |
593 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
594 | < | atoms[local_index]->getType(), |
595 | < | pos[0], |
596 | < | pos[1], |
597 | < | pos[2], |
598 | < | vel[0], |
599 | < | vel[1], |
600 | < | vel[2]); // check here. |
601 | < | strcpy( writeLine, tempBuffer ); |
602 | < | |
603 | < | if( atoms[local_index]->isDirectional() ){ |
604 | < | |
605 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
606 | < | dAtom->getQ( q ); |
607 | < | |
608 | < | sprintf( tempBuffer, |
609 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
610 | < | q[0], |
611 | < | q[1], |
612 | < | q[2], |
613 | < | q[3], |
614 | < | dAtom->getJx(), |
615 | < | dAtom->getJy(), |
616 | < | dAtom->getJz()); |
617 | < | strcat( writeLine, tempBuffer ); |
618 | < | } |
619 | < | else{ |
620 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
621 | < | } |
622 | < | } |
623 | < | else { |
624 | < | sprintf(painCave.errMsg, |
625 | < | "Atom %d not found on processor %d\n", |
626 | < | which_atom, worldRank ); |
627 | < | myStatus = 0; |
628 | < | simError(); |
629 | < | |
630 | < | strcpy( writeLine, "Hello, I'm an error.\n"); |
631 | < | } |
632 | < | |
633 | < | MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
634 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
635 | < | MPI_Send( &myStatus, 1, MPI_INT, 0, |
636 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
637 | < | } |
638 | < | } |
639 | < | finalOut.flush(); |
640 | < | sprintf( checkPointMsg, |
641 | < | "Sucessfully took a dump.\n"); |
642 | < | MPIcheckPoint(); |
544 | > | } |
545 | ||
644 | – | if( worldRank == 0 ) finalOut.close(); |
546 | #endif // is_mpi | |
547 | } | |
548 | ||
648 | – | |
649 | – | |
549 | #ifdef IS_MPI | |
550 | ||
551 | // a couple of functions to let us escape the write loop | |
552 | ||
553 | < | void dWrite::nodeZeroError( void ){ |
655 | < | int j, myStatus; |
656 | < | |
657 | < | myStatus = 0; |
658 | < | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
659 | < | MPI_Send( &myStatus, 1, MPI_INT, j, |
660 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
661 | < | } |
662 | < | |
553 | > | void dWrite::DieDieDie( void ){ |
554 | ||
555 | MPI_Finalize(); | |
556 | exit (0); | |
666 | – | |
557 | } | |
558 | ||
669 | – | void dWrite::anonymousNodeDie( void ){ |
670 | – | |
671 | – | MPI_Finalize(); |
672 | – | exit (0); |
673 | – | } |
674 | – | |
559 | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |