# | Line 1 | Line 1 | |
---|---|---|
1 | < | #include <cstring> |
1 | > | #define _FILE_OFFSET_BITS 64 |
2 | > | |
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" | |
12 | < | #define TAKE_THIS_TAG 0 |
12 | > | |
13 | > | namespace dWrite{ |
14 | > | void DieDieDie( void ); |
15 | > | } |
16 | > | |
17 | > | using namespace dWrite; |
18 | #endif //is_mpi | |
19 | ||
20 | #include "ReadWrite.hpp" | |
21 | #include "simError.h" | |
22 | ||
14 | – | |
15 | – | |
16 | – | |
17 | – | |
23 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | |
24 | ||
25 | entry_plug = the_entry_plug; | |
# | Line 22 | Line 27 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | |
27 | #ifdef IS_MPI | |
28 | if(worldRank == 0 ){ | |
29 | #endif // is_mpi | |
30 | < | |
31 | < | |
32 | < | |
33 | < | strcpy( outName, entry_plug->sampleName ); |
34 | < | |
35 | < | outFile.open(outName, ios::out | ios::trunc ); |
31 | < | |
32 | < | if( !outFile ){ |
33 | < | |
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 | < | |
42 | > | |
43 | //outFile.setf( ios::scientific ); | |
44 | ||
45 | #ifdef IS_MPI | |
46 | } | |
47 | ||
48 | + | //sort the local atoms by global index |
49 | + | sortByGlobalIndex(); |
50 | + | |
51 | sprintf( checkPointMsg, | |
52 | "Sucessfully opened output file for dumping.\n"); | |
53 | MPIcheckPoint(); | |
# | Line 55 | Line 60 | DumpWriter::~DumpWriter( ){ | |
60 | if(worldRank == 0 ){ | |
61 | #endif // is_mpi | |
62 | ||
63 | < | outFile.close(); |
63 | > | dumpFile.close(); |
64 | ||
65 | #ifdef IS_MPI | |
66 | } | |
67 | #endif // is_mpi | |
68 | } | |
69 | ||
70 | < | void DumpWriter::writeDump( double currentTime ){ |
70 | > | #ifdef IS_MPI |
71 | > | |
72 | > | /** |
73 | > | * A hook function to load balancing |
74 | > | */ |
75 | > | |
76 | > | void DumpWriter::update(){ |
77 | > | sortByGlobalIndex(); |
78 | > | } |
79 | ||
80 | + | /** |
81 | + | * Auxiliary sorting function |
82 | + | */ |
83 | + | |
84 | + | bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){ |
85 | + | return p1.second < p2.second; |
86 | + | } |
87 | + | |
88 | + | /** |
89 | + | * Sorting the local index by global index |
90 | + | */ |
91 | + | |
92 | + | void DumpWriter::sortByGlobalIndex(){ |
93 | + | Atom** atoms = entry_plug->atoms; |
94 | + | |
95 | + | indexArray.clear(); |
96 | + | |
97 | + | for(int i = 0; i < mpiSim->getMyNlocal();i++) |
98 | + | indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex())); |
99 | + | |
100 | + | sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); |
101 | + | } |
102 | + | #endif |
103 | + | |
104 | + | void DumpWriter::writeDump(double currentTime){ |
105 | + | |
106 | + | // write to eor file |
107 | + | writeFinal(currentTime); |
108 | + | |
109 | + | //write to dump file |
110 | + | writeFrame(dumpFile, currentTime); |
111 | + | |
112 | + | } |
113 | + | |
114 | + | void DumpWriter::writeFinal(double currentTime){ |
115 | + | |
116 | + | ofstream finalOut; |
117 | + | |
118 | + | //Open eor file |
119 | + | #ifdef IS_MPI |
120 | + | if(worldRank == 0 ){ |
121 | + | #endif // is_mpi |
122 | + | |
123 | + | finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); |
124 | + | if( !finalOut ){ |
125 | + | sprintf( painCave.errMsg, |
126 | + | "Could not open \"%s\" for final dump output.\n", |
127 | + | entry_plug->finalName ); |
128 | + | painCave.isFatal = 1; |
129 | + | simError(); |
130 | + | } |
131 | + | |
132 | + | #ifdef IS_MPI |
133 | + | } |
134 | + | #endif |
135 | + | |
136 | + | //write to eor file |
137 | + | writeFrame(finalOut, currentTime); |
138 | + | |
139 | + | //close eor file |
140 | + | #ifdef IS_MPI |
141 | + | if(worldRank == 0 ){ |
142 | + | finalOut.close(); |
143 | + | } |
144 | + | #endif // is_mpi |
145 | + | |
146 | + | } |
147 | + | |
148 | + | void DumpWriter::writeFrame( ofstream& outFile, double currentTime ){ |
149 | + | |
150 | const int BUFFERSIZE = 2000; | |
151 | + | const int MINIBUFFERSIZE = 100; |
152 | + | |
153 | char tempBuffer[BUFFERSIZE]; | |
154 | char writeLine[BUFFERSIZE]; | |
155 | ||
156 | int i; | |
157 | + | |
158 | + | #ifdef IS_MPI |
159 | + | |
160 | + | int *potatoes; |
161 | + | int myPotato; |
162 | + | |
163 | + | int nProc; |
164 | + | int j, which_node, done, which_atom, local_index, currentIndex; |
165 | + | double atomData6[6]; |
166 | + | double atomData13[13]; |
167 | + | int isDirectional; |
168 | + | char* atomTypeString; |
169 | + | char MPIatomTypeString[MINIBUFFERSIZE]; |
170 | + | |
171 | + | #else //is_mpi |
172 | + | int nAtoms = entry_plug->n_atoms; |
173 | + | #endif //is_mpi |
174 | + | |
175 | double q[4]; | |
176 | DirectionalAtom* dAtom; | |
74 | – | int nAtoms = entry_plug->n_atoms; |
177 | Atom** atoms = entry_plug->atoms; | |
178 | < | |
178 | > | double pos[3], vel[3]; |
179 | ||
180 | #ifndef IS_MPI | |
181 | < | |
181 | > | |
182 | outFile << nAtoms << "\n"; | |
183 | < | |
184 | < | outFile << currentTime << "\t" |
185 | < | << entry_plug->box_x << "\t" |
186 | < | << entry_plug->box_y << "\t" |
187 | < | << entry_plug->box_z << "\n"; |
188 | < | |
183 | > | |
184 | > | outFile << currentTime << ";\t" |
185 | > | << entry_plug->Hmat[0][0] << "\t" |
186 | > | << entry_plug->Hmat[1][0] << "\t" |
187 | > | << entry_plug->Hmat[2][0] << ";\t" |
188 | > | |
189 | > | << entry_plug->Hmat[0][1] << "\t" |
190 | > | << entry_plug->Hmat[1][1] << "\t" |
191 | > | << entry_plug->Hmat[2][1] << ";\t" |
192 | > | |
193 | > | << entry_plug->Hmat[0][2] << "\t" |
194 | > | << entry_plug->Hmat[1][2] << "\t" |
195 | > | << entry_plug->Hmat[2][2] << ";"; |
196 | > | //write out additional parameters, such as chi and eta |
197 | > | outFile << entry_plug->the_integrator->getAdditionalParameters(); |
198 | > | outFile << endl; |
199 | > | |
200 | for( i=0; i<nAtoms; i++ ){ | |
88 | – | |
201 | ||
202 | + | atoms[i]->getPos(pos); |
203 | + | atoms[i]->getVel(vel); |
204 | + | |
205 | sprintf( tempBuffer, | |
206 | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | |
207 | atoms[i]->getType(), | |
208 | < | atoms[i]->getX(), |
209 | < | atoms[i]->getY(), |
210 | < | atoms[i]->getZ(), |
211 | < | atoms[i]->get_vx(), |
212 | < | atoms[i]->get_vy(), |
213 | < | atoms[i]->get_vz()); |
208 | > | pos[0], |
209 | > | pos[1], |
210 | > | pos[2], |
211 | > | vel[0], |
212 | > | vel[1], |
213 | > | vel[2]); |
214 | strcpy( writeLine, tempBuffer ); | |
215 | ||
216 | if( atoms[i]->isDirectional() ){ | |
217 | < | |
217 | > | |
218 | dAtom = (DirectionalAtom *)atoms[i]; | |
219 | dAtom->getQ( q ); | |
220 | < | |
220 | > | |
221 | sprintf( tempBuffer, | |
222 | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", | |
223 | q[0], | |
# | Line 116 | Line 231 | void DumpWriter::writeDump( double currentTime ){ | |
231 | } | |
232 | else | |
233 | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); | |
234 | < | |
234 | > | |
235 | outFile << writeLine; | |
236 | } | |
122 | – | outFile.flush(); |
237 | ||
238 | #else // is_mpi | |
239 | ||
240 | < | int masterIndex; |
241 | < | int nodeAtomsStart; |
242 | < | int nodeAtomsEnd; |
243 | < | int mpiErr; |
244 | < | int sendError; |
245 | < | int procIndex; |
246 | < | |
247 | < | MPI_Status istatus[MPI_STATUS_SIZE]; |
240 | > | /* code to find maximum tag value */ |
241 | > | |
242 | > | int *tagub, flag, MAXTAG; |
243 | > | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
244 | > | if (flag) { |
245 | > | MAXTAG = *tagub; |
246 | > | } else { |
247 | > | MAXTAG = 32767; |
248 | > | } |
249 | ||
250 | < | |
250 | > | int haveError; |
251 | > | |
252 | > | MPI_Status istatus; |
253 | > | int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
254 | > | |
255 | // write out header and node 0's coordinates | |
256 | ||
257 | if( worldRank == 0 ){ | |
258 | + | |
259 | + | // Node 0 needs a list of the magic potatoes for each processor; |
260 | + | |
261 | + | nProc = mpiSim->getNumberProcessors(); |
262 | + | potatoes = new int[nProc]; |
263 | + | |
264 | + | for (i = 0; i < nProc; i++) |
265 | + | potatoes[i] = 0; |
266 | + | |
267 | 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"; |
268 | ||
269 | < | masterIndex = 0; |
270 | < | for( i=0; i<nAtoms; i++ ){ |
271 | < | |
272 | < | sprintf( tempBuffer, |
150 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
151 | < | atoms[i]->getType(), |
152 | < | atoms[i]->getX(), |
153 | < | atoms[i]->getY(), |
154 | < | atoms[i]->getZ(), |
155 | < | atoms[i]->get_vx(), |
156 | < | atoms[i]->get_vy(), |
157 | < | atoms[i]->get_vz()); |
158 | < | strcpy( writeLine, tempBuffer ); |
159 | < | |
160 | < | 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 | < | } |
182 | < | outFile.flush(); |
183 | < | } |
269 | > | outFile << currentTime << ";\t" |
270 | > | << entry_plug->Hmat[0][0] << "\t" |
271 | > | << entry_plug->Hmat[1][0] << "\t" |
272 | > | << entry_plug->Hmat[2][0] << ";\t" |
273 | ||
274 | < | sprintf( checkPointMsg, |
275 | < | "Sucessfully wrote node 0's dump configuration.\n"); |
276 | < | MPIcheckPoint(); |
188 | < | |
189 | < | for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
190 | < | procIndex++){ |
274 | > | << entry_plug->Hmat[0][1] << "\t" |
275 | > | << entry_plug->Hmat[1][1] << "\t" |
276 | > | << entry_plug->Hmat[2][1] << ";\t" |
277 | ||
278 | < | if( worldRank == 0 ){ |
278 | > | << entry_plug->Hmat[0][2] << "\t" |
279 | > | << entry_plug->Hmat[1][2] << "\t" |
280 | > | << entry_plug->Hmat[2][2] << ";"; |
281 | > | |
282 | > | outFile << entry_plug->the_integrator->getAdditionalParameters(); |
283 | > | outFile << endl; |
284 | > | outFile.flush(); |
285 | > | |
286 | > | currentIndex = 0; |
287 | > | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
288 | ||
289 | < | mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
195 | < | TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
289 | > | // Get the Node number which has this atom; |
290 | ||
291 | < | mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
198 | < | TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
291 | > | which_node = AtomToProcMap[i]; |
292 | ||
293 | < | // Make sure where node 0 is writing to, matches where the |
201 | < | // receiving node expects it to be. |
202 | < | |
203 | < | if (masterIndex != nodeAtomsStart){ |
204 | < | sendError = 1; |
205 | < | mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
206 | < | MPI_COMM_WORLD); |
207 | < | sprintf(painCave.errMsg, |
208 | < | "DumpWriter error: atoms start index (%d) for " |
209 | < | "node %d not equal to master index (%d)", |
210 | < | nodeAtomsStart,procIndex,masterIndex ); |
211 | < | painCave.isFatal = 1; |
212 | < | simError(); |
213 | < | } |
214 | < | |
215 | < | sendError = 0; |
216 | < | mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
217 | < | MPI_COMM_WORLD); |
218 | < | |
219 | < | // recieve the nodes writeLines |
220 | < | |
221 | < | for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
222 | < | |
223 | < | mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
224 | < | TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
225 | < | |
226 | < | outFile << writeLine; |
227 | < | masterIndex++; |
228 | < | } |
229 | < | } |
293 | > | if (which_node != 0) { |
294 | ||
295 | < | else if( worldRank == procIndex ){ |
295 | > | if (potatoes[which_node] + 3 >= MAXTAG) { |
296 | > | // The potato was going to exceed the maximum value, |
297 | > | // so wrap this processor potato back to 0: |
298 | ||
299 | < | nodeAtomsStart = mpiSim->getMyAtomStart(); |
300 | < | nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
299 | > | potatoes[which_node] = 0; |
300 | > | MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
301 | > | |
302 | > | } |
303 | ||
304 | < | mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
305 | < | MPI_COMM_WORLD); |
306 | < | mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
307 | < | MPI_COMM_WORLD); |
304 | > | myPotato = potatoes[which_node]; |
305 | > | |
306 | > | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
307 | > | myPotato, MPI_COMM_WORLD, &istatus); |
308 | > | |
309 | > | atomTypeString = MPIatomTypeString; |
310 | ||
311 | < | sendError = -1; |
242 | < | mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
243 | < | MPI_COMM_WORLD, istatus); |
311 | > | myPotato++; |
312 | ||
313 | < | if (sendError) MPIcheckPoint(); |
313 | > | MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
314 | > | myPotato, MPI_COMM_WORLD, &istatus); |
315 | > | |
316 | > | myPotato++; |
317 | ||
318 | < | // send current node's configuration line by line. |
318 | > | if (isDirectional) { |
319 | > | MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node, |
320 | > | myPotato, MPI_COMM_WORLD, &istatus); |
321 | > | } else { |
322 | > | MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node, |
323 | > | myPotato, MPI_COMM_WORLD, &istatus); |
324 | > | } |
325 | > | |
326 | > | myPotato++; |
327 | > | potatoes[which_node] = myPotato; |
328 | ||
329 | < | for( i=0; i<nAtoms; i++ ){ |
329 | > | } else { |
330 | > | |
331 | > | haveError = 0; |
332 | > | which_atom = i; |
333 | > | |
334 | > | local_index = indexArray[currentIndex].first; |
335 | > | |
336 | > | if (which_atom == indexArray[currentIndex].second) { |
337 | > | |
338 | > | atomTypeString = atoms[local_index]->getType(); |
339 | ||
340 | < | sprintf( tempBuffer, |
341 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
253 | < | atoms[i]->getType(), |
254 | < | atoms[i]->getX(), |
255 | < | atoms[i]->getY(), |
256 | < | atoms[i]->getZ(), |
257 | < | atoms[i]->get_vx(), |
258 | < | atoms[i]->get_vy(), |
259 | < | atoms[i]->get_vz()); // check here. |
260 | < | strcpy( writeLine, tempBuffer ); |
261 | < | |
262 | < | if( atoms[i]->isDirectional() ){ |
263 | < | |
264 | < | dAtom = (DirectionalAtom *)atoms[i]; |
265 | < | dAtom->getQ( q ); |
266 | < | |
267 | < | sprintf( tempBuffer, |
268 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
269 | < | q[0], |
270 | < | q[1], |
271 | < | q[2], |
272 | < | q[3], |
273 | < | dAtom->getJx(), |
274 | < | dAtom->getJy(), |
275 | < | dAtom->getJz()); |
276 | < | strcat( writeLine, tempBuffer ); |
277 | < | } |
278 | < | else |
279 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
280 | < | |
281 | < | mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
282 | < | MPI_COMM_WORLD); |
283 | < | } |
284 | < | } |
285 | < | |
286 | < | sprintf(checkPointMsg,"Node %d sent dump configuration.", |
287 | < | procIndex); |
288 | < | MPIcheckPoint(); |
289 | < | } |
290 | < | |
291 | < | #endif // is_mpi |
292 | < | } |
340 | > | atoms[local_index]->getPos(pos); |
341 | > | atoms[local_index]->getVel(vel); |
342 | ||
343 | + | atomData6[0] = pos[0]; |
344 | + | atomData6[1] = pos[1]; |
345 | + | atomData6[2] = pos[2]; |
346 | ||
347 | + | atomData6[3] = vel[0]; |
348 | + | atomData6[4] = vel[1]; |
349 | + | atomData6[5] = vel[2]; |
350 | + | |
351 | + | isDirectional = 0; |
352 | ||
353 | < | void DumpWriter::writeFinal(){ |
353 | > | if( atoms[local_index]->isDirectional() ){ |
354 | > | |
355 | > | isDirectional = 1; |
356 | > | |
357 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
358 | > | dAtom->getQ( q ); |
359 | ||
360 | < | |
361 | < | const int BUFFERSIZE = 2000; |
362 | < | char tempBuffer[500]; |
363 | < | char writeLine[BUFFERSIZE]; |
364 | < | |
365 | < | char finalName[500]; |
366 | < | |
367 | < | int i; |
368 | < | double q[4]; |
369 | < | DirectionalAtom* dAtom; |
370 | < | int nAtoms = entry_plug->n_atoms; |
371 | < | Atom** atoms = entry_plug->atoms; |
372 | < | |
373 | < | ofstream finalOut; |
374 | < | |
375 | < | #ifdef IS_MPI |
376 | < | if(worldRank == 0 ){ |
377 | < | #endif // is_mpi |
378 | < | |
379 | < | strcpy( finalName, entry_plug->finalName ); |
380 | < | |
381 | < | finalOut.open( finalName, ios::out | ios::trunc ); |
382 | < | if( !finalOut ){ |
383 | < | sprintf( painCave.errMsg, |
384 | < | "Could not open \"%s\" for final dump output.\n", |
385 | < | finalName ); |
324 | < | painCave.isFatal = 1; |
325 | < | simError(); |
326 | < | } |
327 | < | |
328 | < | // finalOut.setf( ios::scientific ); |
329 | < | |
330 | < | #ifdef IS_MPI |
331 | < | } |
332 | < | |
333 | < | sprintf(checkPointMsg,"Opened file for final configuration\n"); |
334 | < | MPIcheckPoint(); |
335 | < | |
336 | < | #endif //is_mpi |
337 | < | |
338 | < | |
339 | < | |
340 | < | #ifndef IS_MPI |
341 | < | |
342 | < | finalOut << nAtoms << "\n"; |
343 | < | |
344 | < | finalOut << entry_plug->box_x << "\t" |
345 | < | << entry_plug->box_y << "\t" |
346 | < | << entry_plug->box_z << "\n"; |
347 | < | |
348 | < | for( i=0; i<nAtoms; i++ ){ |
360 | > | for (int j = 0; j < 6 ; j++) |
361 | > | atomData13[j] = atomData6[j]; |
362 | > | |
363 | > | atomData13[6] = q[0]; |
364 | > | atomData13[7] = q[1]; |
365 | > | atomData13[8] = q[2]; |
366 | > | atomData13[9] = q[3]; |
367 | > | |
368 | > | atomData13[10] = dAtom->getJx(); |
369 | > | atomData13[11] = dAtom->getJy(); |
370 | > | atomData13[12] = dAtom->getJz(); |
371 | > | } |
372 | > | |
373 | > | } else { |
374 | > | sprintf(painCave.errMsg, |
375 | > | "Atom %d not found on processor %d\n", |
376 | > | i, worldRank ); |
377 | > | haveError= 1; |
378 | > | simError(); |
379 | > | } |
380 | > | |
381 | > | if(haveError) DieDieDie(); |
382 | > | |
383 | > | currentIndex ++; |
384 | > | } |
385 | > | // If we've survived to here, format the line: |
386 | ||
387 | < | sprintf( tempBuffer, |
388 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
389 | < | atoms[i]->getType(), |
390 | < | atoms[i]->getX(), |
391 | < | atoms[i]->getY(), |
392 | < | atoms[i]->getZ(), |
393 | < | atoms[i]->get_vx(), |
394 | < | atoms[i]->get_vy(), |
395 | < | atoms[i]->get_vz()); |
396 | < | strcpy( writeLine, tempBuffer ); |
387 | > | if (!isDirectional) { |
388 | > | |
389 | > | sprintf( writeLine, |
390 | > | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
391 | > | atomTypeString, |
392 | > | atomData6[0], |
393 | > | atomData6[1], |
394 | > | atomData6[2], |
395 | > | atomData6[3], |
396 | > | atomData6[4], |
397 | > | atomData6[5]); |
398 | ||
399 | < | if( atoms[i]->isDirectional() ){ |
399 | > | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
400 | ||
401 | < | dAtom = (DirectionalAtom *)atoms[i]; |
364 | < | dAtom->getQ( q ); |
401 | > | } else { |
402 | ||
403 | < | sprintf( tempBuffer, |
404 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
405 | < | q[0], |
406 | < | q[1], |
407 | < | q[2], |
408 | < | q[3], |
409 | < | dAtom->getJx(), |
410 | < | dAtom->getJy(), |
411 | < | dAtom->getJz()); |
412 | < | strcat( writeLine, tempBuffer ); |
413 | < | } |
414 | < | else |
415 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
403 | > | sprintf( writeLine, |
404 | > | "%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", |
405 | > | atomTypeString, |
406 | > | atomData13[0], |
407 | > | atomData13[1], |
408 | > | atomData13[2], |
409 | > | atomData13[3], |
410 | > | atomData13[4], |
411 | > | atomData13[5], |
412 | > | atomData13[6], |
413 | > | atomData13[7], |
414 | > | atomData13[8], |
415 | > | atomData13[9], |
416 | > | atomData13[10], |
417 | > | atomData13[11], |
418 | > | atomData13[12]); |
419 | > | |
420 | > | } |
421 | ||
422 | < | finalOut << writeLine; |
423 | < | } |
424 | < | finalOut.flush(); |
422 | > | outFile << writeLine; |
423 | > | } |
424 | > | |
425 | ||
426 | < | #else // is_mpi |
426 | > | outFile.flush(); |
427 | > | sprintf( checkPointMsg, |
428 | > | "Sucessfully took a dump.\n"); |
429 | > | MPIcheckPoint(); |
430 | > | delete[] potatoes; |
431 | > | } else { |
432 | ||
433 | < | int masterIndex; |
387 | < | int nodeAtomsStart; |
388 | < | int nodeAtomsEnd; |
389 | < | int mpiErr; |
390 | < | int sendError; |
391 | < | int procIndex; |
392 | < | |
393 | < | MPI_Status istatus[MPI_STATUS_SIZE]; |
433 | > | // worldRank != 0, so I'm a remote node. |
434 | ||
435 | < | |
396 | < | // write out header and node 0's coordinates |
435 | > | // Set my magic potato to 0: |
436 | ||
437 | < | if( worldRank == 0 ){ |
438 | < | finalOut << mpiSim->getTotAtoms() << "\n"; |
400 | < | |
401 | < | finalOut << entry_plug->box_x << "\t" |
402 | < | << entry_plug->box_y << "\t" |
403 | < | << entry_plug->box_z << "\n"; |
437 | > | myPotato = 0; |
438 | > | currentIndex = 0; |
439 | ||
440 | < | masterIndex = 0; |
406 | < | |
407 | < | for( i=0; i<nAtoms; i++ ){ |
440 | > | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
441 | ||
442 | < | sprintf( tempBuffer, |
443 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
444 | < | 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++){ |
442 | > | // Am I the node which has this atom? |
443 | > | |
444 | > | if (AtomToProcMap[i] == worldRank) { |
445 | ||
446 | < | if( worldRank == 0 ){ |
449 | < | |
450 | < | mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
451 | < | TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
446 | > | if (myPotato + 3 >= MAXTAG) { |
447 | ||
448 | < | mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
449 | < | TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
450 | < | |
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); |
448 | > | // The potato was going to exceed the maximum value, |
449 | > | // so wrap this processor potato back to 0 (and block until |
450 | > | // node 0 says we can go: |
451 | ||
452 | < | // recieve the nodes writeLines |
452 | > | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
453 | > | |
454 | > | } |
455 | > | which_atom = i; |
456 | > | local_index = indexArray[currentIndex].first; |
457 | > | |
458 | > | if (which_atom == indexArray[currentIndex].second) { |
459 | > | |
460 | > | atomTypeString = atoms[local_index]->getType(); |
461 | ||
462 | < | for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
463 | < | |
479 | < | mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
480 | < | TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
462 | > | atoms[local_index]->getPos(pos); |
463 | > | atoms[local_index]->getVel(vel); |
464 | ||
465 | < | finalOut << writeLine; |
466 | < | masterIndex++; |
467 | < | } |
465 | > | atomData6[0] = pos[0]; |
466 | > | atomData6[1] = pos[1]; |
467 | > | atomData6[2] = pos[2]; |
468 | ||
469 | < | finalOut.flush(); |
470 | < | } |
469 | > | atomData6[3] = vel[0]; |
470 | > | atomData6[4] = vel[1]; |
471 | > | atomData6[5] = vel[2]; |
472 | > | |
473 | > | isDirectional = 0; |
474 | ||
475 | < | else if( worldRank == procIndex ){ |
475 | > | if( atoms[local_index]->isDirectional() ){ |
476 | ||
477 | < | nodeAtomsStart = mpiSim->getMyAtomStart(); |
478 | < | nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
479 | < | |
480 | < | mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
481 | < | MPI_COMM_WORLD); |
482 | < | mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
483 | < | MPI_COMM_WORLD); |
484 | < | |
485 | < | mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
486 | < | MPI_COMM_WORLD, istatus); |
487 | < | if (sendError) MPIcheckPoint(); |
477 | > | isDirectional = 1; |
478 | > | |
479 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
480 | > | dAtom->getQ( q ); |
481 | > | |
482 | > | for (int j = 0; j < 6 ; j++) |
483 | > | atomData13[j] = atomData6[j]; |
484 | > | |
485 | > | atomData13[6] = q[0]; |
486 | > | atomData13[7] = q[1]; |
487 | > | atomData13[8] = q[2]; |
488 | > | atomData13[9] = q[3]; |
489 | ||
490 | < | // send current node's configuration line by line. |
490 | > | atomData13[10] = dAtom->getJx(); |
491 | > | atomData13[11] = dAtom->getJy(); |
492 | > | atomData13[12] = dAtom->getJz(); |
493 | > | } |
494 | ||
495 | < | for( i=0; i<nAtoms; i++ ){ |
496 | < | |
497 | < | sprintf( tempBuffer, |
498 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
499 | < | atoms[i]->getType(), |
500 | < | atoms[i]->getX(), |
511 | < | atoms[i]->getY(), |
512 | < | atoms[i]->getZ(), |
513 | < | atoms[i]->get_vx(), |
514 | < | atoms[i]->get_vy(), |
515 | < | atoms[i]->get_vz()); |
516 | < | strcpy( writeLine, tempBuffer ); |
517 | < | |
518 | < | if( atoms[i]->isDirectional() ){ |
519 | < | |
520 | < | dAtom = (DirectionalAtom *)atoms[i]; |
521 | < | dAtom->getQ( q ); |
522 | < | |
523 | < | sprintf( tempBuffer, |
524 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
525 | < | q[0], |
526 | < | q[1], |
527 | < | q[2], |
528 | < | q[3], |
529 | < | dAtom->getJx(), |
530 | < | dAtom->getJy(), |
531 | < | dAtom->getJz()); |
532 | < | strcat( writeLine, tempBuffer ); |
495 | > | } else { |
496 | > | sprintf(painCave.errMsg, |
497 | > | "Atom %d not found on processor %d\n", |
498 | > | i, worldRank ); |
499 | > | haveError= 1; |
500 | > | simError(); |
501 | } | |
502 | < | else |
503 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
504 | < | |
505 | < | mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
506 | < | MPI_COMM_WORLD); |
502 | > | |
503 | > | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
504 | > | |
505 | > | // null terminate the string before sending (just in case): |
506 | > | MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
507 | > | |
508 | > | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 | > | myPotato, MPI_COMM_WORLD); |
510 | > | |
511 | > | myPotato++; |
512 | > | |
513 | > | MPI_Send(&isDirectional, 1, MPI_INT, 0, |
514 | > | myPotato, MPI_COMM_WORLD); |
515 | > | |
516 | > | myPotato++; |
517 | > | |
518 | > | if (isDirectional) { |
519 | > | |
520 | > | MPI_Send(atomData13, 13, MPI_DOUBLE, 0, |
521 | > | myPotato, MPI_COMM_WORLD); |
522 | > | |
523 | > | } else { |
524 | > | |
525 | > | MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
526 | > | myPotato, MPI_COMM_WORLD); |
527 | > | } |
528 | > | |
529 | > | myPotato++; |
530 | > | currentIndex++; |
531 | } | |
532 | } | |
541 | – | |
542 | – | sprintf(checkPointMsg,"Node %d sent dump configuration.", |
543 | – | procIndex); |
544 | – | MPIcheckPoint(); |
545 | – | } |
533 | ||
534 | < | if( worldRank == 0 ) finalOut.close(); |
535 | < | |
534 | > | sprintf( checkPointMsg, |
535 | > | "Sucessfully took a dump.\n"); |
536 | > | MPIcheckPoint(); |
537 | ||
538 | + | } |
539 | + | |
540 | #endif // is_mpi | |
541 | } | |
542 | + | |
543 | + | #ifdef IS_MPI |
544 | + | |
545 | + | // a couple of functions to let us escape the write loop |
546 | + | |
547 | + | void dWrite::DieDieDie( void ){ |
548 | + | |
549 | + | MPI_Finalize(); |
550 | + | exit (0); |
551 | + | } |
552 | + | |
553 | + | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |