# | Line 1 | Line 1 | |
---|---|---|
1 | < | #define _LARGEFILE_SOURCE64 |
2 | < | #define _FILE_OFFSET_BITS 64 |
1 | > | /* |
2 | > | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 | > | * |
4 | > | * The University of Notre Dame grants you ("Licensee") a |
5 | > | * non-exclusive, royalty free, license to use, modify and |
6 | > | * redistribute this software in source and binary code form, provided |
7 | > | * that the following conditions are met: |
8 | > | * |
9 | > | * 1. Acknowledgement of the program authors must be made in any |
10 | > | * publication of scientific results based in part on use of the |
11 | > | * program. An acceptable form of acknowledgement is citation of |
12 | > | * the article in which the program was described (Matthew |
13 | > | * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 | > | * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 | > | * Parallel Simulation Engine for Molecular Dynamics," |
16 | > | * J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 | > | * |
18 | > | * 2. Redistributions of source code must retain the above copyright |
19 | > | * notice, this list of conditions and the following disclaimer. |
20 | > | * |
21 | > | * 3. Redistributions in binary form must reproduce the above copyright |
22 | > | * notice, this list of conditions and the following disclaimer in the |
23 | > | * documentation and/or other materials provided with the |
24 | > | * distribution. |
25 | > | * |
26 | > | * This software is provided "AS IS," without a warranty of any |
27 | > | * kind. All express or implied conditions, representations and |
28 | > | * warranties, including any implied warranty of merchantability, |
29 | > | * fitness for a particular purpose or non-infringement, are hereby |
30 | > | * excluded. The University of Notre Dame and its licensors shall not |
31 | > | * be liable for any damages suffered by licensee as a result of |
32 | > | * using, modifying or distributing the software or its |
33 | > | * derivatives. In no event will the University of Notre Dame or its |
34 | > | * licensors be liable for any lost revenue, profit or data, or for |
35 | > | * direct, indirect, special, consequential, incidental or punitive |
36 | > | * damages, however caused and regardless of the theory of liability, |
37 | > | * arising out of the use of or inability to use software, even if the |
38 | > | * University of Notre Dame has been advised of the possibility of |
39 | > | * such damages. |
40 | > | */ |
41 | > | |
42 | > | #include "io/DumpWriter.hpp" |
43 | > | #include "primitives/Molecule.hpp" |
44 | > | #include "utils/simError.h" |
45 | ||
4 | – | #include <string.h> |
5 | – | #include <iostream> |
6 | – | #include <fstream> |
7 | – | #include <algorithm> |
8 | – | #include <utility> |
9 | – | |
46 | #ifdef IS_MPI | |
47 | #include <mpi.h> | |
12 | – | #include "brains/mpiSimulation.hpp" |
13 | – | |
14 | – | namespace dWrite{ |
15 | – | void DieDieDie( void ); |
16 | – | } |
17 | – | |
18 | – | using namespace dWrite; |
48 | #endif //is_mpi | |
49 | ||
50 | < | #include "io/ReadWrite.hpp" |
22 | < | #include "utils/simError.h" |
50 | > | namespace oopse { |
51 | ||
52 | < | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ |
53 | < | |
26 | < | entry_plug = the_entry_plug; |
27 | < | |
52 | > | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
53 | > | : info_(info), filename_(filename){ |
54 | #ifdef IS_MPI | |
55 | < | if(worldRank == 0 ){ |
55 | > | |
56 | > | if (worldRank == 0) { |
57 | #endif // is_mpi | |
58 | ||
59 | < | dumpFile.open(entry_plug->sampleName.c_str(), ios::out | ios::trunc ); |
59 | > | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
60 | ||
61 | < | if( !dumpFile ){ |
61 | > | if (!dumpFile_) { |
62 | > | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
63 | > | filename_.c_str()); |
64 | > | painCave.isFatal = 1; |
65 | > | simError(); |
66 | > | } |
67 | ||
68 | < | sprintf( painCave.errMsg, |
69 | < | "Could not open \"%s\" for dump output.\n", |
38 | < | entry_plug->sampleName.c_str()); |
39 | < | painCave.isFatal = 1; |
40 | < | simError(); |
68 | > | #ifdef IS_MPI |
69 | > | |
70 | } | |
71 | ||
72 | < | #ifdef IS_MPI |
73 | < | } |
72 | > | sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
73 | > | MPIcheckPoint(); |
74 | ||
46 | – | //sort the local atoms by global index |
47 | – | sortByGlobalIndex(); |
48 | – | |
49 | – | sprintf( checkPointMsg, |
50 | – | "Sucessfully opened output file for dumping.\n"); |
51 | – | MPIcheckPoint(); |
75 | #endif // is_mpi | |
76 | + | |
77 | } | |
78 | ||
79 | < | DumpWriter::~DumpWriter( ){ |
79 | > | DumpWriter::~DumpWriter() { |
80 | ||
81 | #ifdef IS_MPI | |
82 | < | if(worldRank == 0 ){ |
82 | > | |
83 | > | if (worldRank == 0) { |
84 | #endif // is_mpi | |
85 | ||
86 | < | dumpFile.close(); |
86 | > | dumpFile_.close(); |
87 | ||
88 | #ifdef IS_MPI | |
89 | < | } |
89 | > | |
90 | > | } |
91 | > | |
92 | #endif // is_mpi | |
93 | + | |
94 | } | |
95 | ||
96 | < | #ifdef IS_MPI |
96 | > | void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
97 | ||
98 | < | /** |
99 | < | * A hook function to load balancing |
100 | < | */ |
98 | > | double currentTime; |
99 | > | Mat3x3d hmat; |
100 | > | double chi; |
101 | > | double integralOfChiDt; |
102 | > | Mat3x3d eta; |
103 | > | |
104 | > | currentTime = s->getTime(); |
105 | > | hmat = s->getHmat(); |
106 | > | chi = s->getChi(); |
107 | > | integralOfChiDt = s->getIntegralOfChiDt(); |
108 | > | eta = s->getEta(); |
109 | > | |
110 | > | os << currentTime << ";\t" |
111 | > | << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
112 | > | << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
113 | > | << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
114 | ||
115 | < | void DumpWriter::update(){ |
75 | < | sortByGlobalIndex(); |
76 | < | } |
77 | < | |
78 | < | /** |
79 | < | * Auxiliary sorting function |
80 | < | */ |
81 | < | |
82 | < | bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){ |
83 | < | return p1.second < p2.second; |
84 | < | } |
115 | > | //write out additional parameters, such as chi and eta |
116 | ||
117 | < | /** |
118 | < | * Sorting the local index by global index |
119 | < | */ |
120 | < | |
121 | < | void DumpWriter::sortByGlobalIndex(){ |
122 | < | Molecule* mols = entry_plug->molecules; |
123 | < | indexArray.clear(); |
93 | < | |
94 | < | for(int i = 0; i < entry_plug->n_mol;i++) |
95 | < | indexArray.push_back(make_pair(i, mols[i].getGlobalIndex())); |
96 | < | |
97 | < | sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); |
117 | > | os << chi << "\t" << integralOfChiDt << "\t;"; |
118 | > | |
119 | > | os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" |
120 | > | << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
121 | > | << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
122 | > | |
123 | > | os << std::endl; |
124 | } | |
125 | ||
126 | < | #endif |
126 | > | void DumpWriter::writeFrame(std::ostream& os) { |
127 | > | const int BUFFERSIZE = 2000; |
128 | > | const int MINIBUFFERSIZE = 100; |
129 | ||
130 | < | void DumpWriter::writeDump(double currentTime){ |
130 | > | char tempBuffer[BUFFERSIZE]; |
131 | > | char writeLine[BUFFERSIZE]; |
132 | ||
133 | < | ofstream finalOut; |
134 | < | vector<ofstream*> fileStreams; |
133 | > | Quat4d q; |
134 | > | Vector3d ji; |
135 | > | Vector3d pos; |
136 | > | Vector3d vel; |
137 | ||
138 | < | #ifdef IS_MPI |
139 | < | if(worldRank == 0 ){ |
140 | < | #endif |
141 | < | finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc ); |
142 | < | if( !finalOut ){ |
143 | < | sprintf( painCave.errMsg, |
144 | < | "Could not open \"%s\" for final dump output.\n", |
114 | < | entry_plug->finalName.c_str() ); |
115 | < | painCave.isFatal = 1; |
116 | < | simError(); |
117 | < | } |
118 | < | #ifdef IS_MPI |
119 | < | } |
120 | < | #endif // is_mpi |
138 | > | Molecule* mol; |
139 | > | StuntDouble* integrableObject; |
140 | > | SimInfo::MoleculeIterator mi; |
141 | > | Molecule::IntegrableObjectIterator ii; |
142 | > | |
143 | > | int nTotObjects; |
144 | > | nTotObjects = info_->getNGlobalIntegrableObjects(); |
145 | ||
146 | < | fileStreams.push_back(&finalOut); |
123 | < | fileStreams.push_back(&dumpFile); |
146 | > | #ifndef IS_MPI |
147 | ||
125 | – | writeFrame(fileStreams, currentTime); |
148 | ||
149 | < | #ifdef IS_MPI |
150 | < | finalOut.close(); |
151 | < | #endif |
130 | < | |
131 | < | } |
149 | > | os << nTotObjects << "\n"; |
150 | > | |
151 | > | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
152 | ||
153 | < | void DumpWriter::writeFinal(double currentTime){ |
153 | > | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
154 | ||
155 | < | ofstream finalOut; |
156 | < | vector<ofstream*> fileStreams; |
155 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
156 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
157 | > | |
158 | ||
159 | < | #ifdef IS_MPI |
160 | < | if(worldRank == 0 ){ |
140 | < | #endif // is_mpi |
159 | > | pos = integrableObject->getPos(); |
160 | > | vel = integrableObject->getVel(); |
161 | ||
162 | < | finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc ); |
162 | > | sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
163 | > | integrableObject->getType().c_str(), |
164 | > | pos[0], pos[1], pos[2], |
165 | > | vel[0], vel[1], vel[2]); |
166 | ||
167 | < | if( !finalOut ){ |
145 | < | sprintf( painCave.errMsg, |
146 | < | "Could not open \"%s\" for final dump output.\n", |
147 | < | entry_plug->finalName.c_str() ); |
148 | < | painCave.isFatal = 1; |
149 | < | simError(); |
150 | < | } |
167 | > | strcpy(writeLine, tempBuffer); |
168 | ||
169 | < | #ifdef IS_MPI |
170 | < | } |
171 | < | #endif // is_mpi |
155 | < | |
156 | < | fileStreams.push_back(&finalOut); |
157 | < | writeFrame(fileStreams, currentTime); |
169 | > | if (integrableObject->isDirectional()) { |
170 | > | q = integrableObject->getQ(); |
171 | > | ji = integrableObject->getJ(); |
172 | ||
173 | < | #ifdef IS_MPI |
174 | < | finalOut.close(); |
175 | < | #endif |
176 | < | |
177 | < | } |
173 | > | sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
174 | > | q[0], q[1], q[2], q[3], |
175 | > | ji[0], ji[1], ji[2]); |
176 | > | strcat(writeLine, tempBuffer); |
177 | > | } else { |
178 | > | strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
179 | > | } |
180 | ||
181 | < | void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){ |
181 | > | os << writeLine; |
182 | ||
183 | < | const int BUFFERSIZE = 2000; |
184 | < | const int MINIBUFFERSIZE = 100; |
183 | > | } |
184 | > | } |
185 | ||
186 | < | char tempBuffer[BUFFERSIZE]; |
187 | < | char writeLine[BUFFERSIZE]; |
188 | < | |
189 | < | int i; |
190 | < | unsigned int k; |
186 | > | #else // is_mpi |
187 | > | /********************************************************************* |
188 | > | * Documentation? You want DOCUMENTATION? |
189 | > | * |
190 | > | * Why all the potatoes below? |
191 | > | * |
192 | > | * To make a long story short, the original version of DumpWriter |
193 | > | * worked in the most inefficient way possible. Node 0 would |
194 | > | * poke each of the node for an individual atom's formatted data |
195 | > | * as node 0 worked its way down the global index. This was particularly |
196 | > | * inefficient since the method blocked all processors at every atom |
197 | > | * (and did it twice!). |
198 | > | * |
199 | > | * An intermediate version of DumpWriter could be described from Node |
200 | > | * zero's perspective as follows: |
201 | > | * |
202 | > | * 1) Have 100 of your friends stand in a circle. |
203 | > | * 2) When you say go, have all of them start tossing potatoes at |
204 | > | * you (one at a time). |
205 | > | * 3) Catch the potatoes. |
206 | > | * |
207 | > | * It was an improvement, but MPI has buffers and caches that could |
208 | > | * best be described in this analogy as "potato nets", so there's no |
209 | > | * need to block the processors atom-by-atom. |
210 | > | * |
211 | > | * This new and improved DumpWriter works in an even more efficient |
212 | > | * way: |
213 | > | * |
214 | > | * 1) Have 100 of your friend stand in a circle. |
215 | > | * 2) When you say go, have them start tossing 5-pound bags of |
216 | > | * potatoes at you. |
217 | > | * 3) Once you've caught a friend's bag of potatoes, |
218 | > | * toss them a spud to let them know they can toss another bag. |
219 | > | * |
220 | > | * How's THAT for documentation? |
221 | > | * |
222 | > | *********************************************************************/ |
223 | > | const int masterNode = 0; |
224 | ||
225 | < | #ifdef IS_MPI |
226 | < | |
227 | < | /********************************************************************* |
228 | < | * Documentation? You want DOCUMENTATION? |
229 | < | * |
230 | < | * Why all the potatoes below? |
231 | < | * |
232 | < | * To make a long story short, the original version of DumpWriter |
233 | < | * worked in the most inefficient way possible. Node 0 would |
234 | < | * poke each of the node for an individual atom's formatted data |
235 | < | * as node 0 worked its way down the global index. This was particularly |
236 | < | * inefficient since the method blocked all processors at every atom |
188 | < | * (and did it twice!). |
189 | < | * |
190 | < | * An intermediate version of DumpWriter could be described from Node |
191 | < | * zero's perspective as follows: |
192 | < | * |
193 | < | * 1) Have 100 of your friends stand in a circle. |
194 | < | * 2) When you say go, have all of them start tossing potatoes at |
195 | < | * you (one at a time). |
196 | < | * 3) Catch the potatoes. |
197 | < | * |
198 | < | * It was an improvement, but MPI has buffers and caches that could |
199 | < | * best be described in this analogy as "potato nets", so there's no |
200 | < | * need to block the processors atom-by-atom. |
201 | < | * |
202 | < | * This new and improved DumpWriter works in an even more efficient |
203 | < | * way: |
204 | < | * |
205 | < | * 1) Have 100 of your friend stand in a circle. |
206 | < | * 2) When you say go, have them start tossing 5-pound bags of |
207 | < | * potatoes at you. |
208 | < | * 3) Once you've caught a friend's bag of potatoes, |
209 | < | * toss them a spud to let them know they can toss another bag. |
210 | < | * |
211 | < | * How's THAT for documentation? |
212 | < | * |
213 | < | *********************************************************************/ |
214 | < | |
215 | < | int *potatoes; |
216 | < | int myPotato; |
217 | < | |
218 | < | int nProc; |
219 | < | int j, which_node, done, which_atom, local_index, currentIndex; |
220 | < | double atomData[13]; |
221 | < | int isDirectional; |
222 | < | char* atomTypeString; |
223 | < | char MPIatomTypeString[MINIBUFFERSIZE]; |
224 | < | int nObjects; |
225 | < | int msgLen; // the length of message actually recieved at master nodes |
226 | < | #endif //is_mpi |
227 | < | |
228 | < | double q[4], ji[3]; |
229 | < | DirectionalAtom* dAtom; |
230 | < | double pos[3], vel[3]; |
231 | < | int nTotObjects; |
232 | < | StuntDouble* sd; |
233 | < | char* molName; |
234 | < | vector<StuntDouble*> integrableObjects; |
235 | < | vector<StuntDouble*>::iterator iter; |
236 | < | nTotObjects = entry_plug->getTotIntegrableObjects(); |
237 | < | #ifndef IS_MPI |
238 | < | |
239 | < | for(k = 0; k < outFile.size(); k++){ |
240 | < | *outFile[k] << nTotObjects << "\n"; |
241 | < | |
242 | < | *outFile[k] << currentTime << ";\t" |
243 | < | << entry_plug->Hmat[0][0] << "\t" |
244 | < | << entry_plug->Hmat[1][0] << "\t" |
245 | < | << entry_plug->Hmat[2][0] << ";\t" |
246 | < | |
247 | < | << entry_plug->Hmat[0][1] << "\t" |
248 | < | << entry_plug->Hmat[1][1] << "\t" |
249 | < | << entry_plug->Hmat[2][1] << ";\t" |
250 | < | |
251 | < | << entry_plug->Hmat[0][2] << "\t" |
252 | < | << entry_plug->Hmat[1][2] << "\t" |
253 | < | << entry_plug->Hmat[2][2] << ";"; |
254 | < | |
255 | < | //write out additional parameters, such as chi and eta |
256 | < | *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; |
257 | < | } |
258 | < | |
259 | < | for( i=0; i< entry_plug->n_mol; i++ ){ |
260 | < | |
261 | < | integrableObjects = entry_plug->molecules[i].getIntegrableObjects(); |
262 | < | molName = (entry_plug->compStamps[entry_plug->molecules[i].getStampID()])->getID(); |
225 | > | int * potatoes; |
226 | > | int myPotato; |
227 | > | int nProc; |
228 | > | int which_node; |
229 | > | double atomData[13]; |
230 | > | int isDirectional; |
231 | > | const char * atomTypeString; |
232 | > | char MPIatomTypeString[MINIBUFFERSIZE]; |
233 | > | int msgLen; // the length of message actually recieved at master nodes |
234 | > | int haveError; |
235 | > | MPI_Status istatus; |
236 | > | int nCurObj; |
237 | ||
238 | < | for( iter = integrableObjects.begin();iter != integrableObjects.end(); ++iter){ |
239 | < | sd = *iter; |
240 | < | sd->getPos(pos); |
241 | < | sd->getVel(vel); |
238 | > | // code to find maximum tag value |
239 | > | int * tagub; |
240 | > | int flag; |
241 | > | int MAXTAG; |
242 | > | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
243 | ||
244 | < | sprintf( tempBuffer, |
245 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
246 | < | sd->getType(), |
247 | < | pos[0], |
248 | < | pos[1], |
274 | < | pos[2], |
275 | < | vel[0], |
276 | < | vel[1], |
277 | < | vel[2]); |
278 | < | strcpy( writeLine, tempBuffer ); |
244 | > | if (flag) { |
245 | > | MAXTAG = *tagub; |
246 | > | } else { |
247 | > | MAXTAG = 32767; |
248 | > | } |
249 | ||
250 | < | if( sd->isDirectional() ){ |
250 | > | if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
251 | ||
252 | < | sd->getQ( q ); |
283 | < | sd->getJ( ji ); |
252 | > | // Node 0 needs a list of the magic potatoes for each processor; |
253 | ||
254 | < | sprintf( tempBuffer, |
255 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
287 | < | q[0], |
288 | < | q[1], |
289 | < | q[2], |
290 | < | q[3], |
291 | < | ji[0], |
292 | < | ji[1], |
293 | < | ji[2]); |
294 | < | strcat( writeLine, tempBuffer ); |
295 | < | } |
296 | < | else |
297 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
298 | < | |
299 | < | for(k = 0; k < outFile.size(); k++) |
300 | < | *outFile[k] << writeLine; |
301 | < | } |
254 | > | MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
255 | > | potatoes = new int[nProc]; |
256 | ||
257 | < | } |
257 | > | //write out the comment lines |
258 | > | for(int i = 0; i < nProc; i++) { |
259 | > | potatoes[i] = 0; |
260 | > | } |
261 | ||
305 | – | #else // is_mpi |
262 | ||
263 | < | /* code to find maximum tag value */ |
264 | < | |
309 | < | int *tagub, flag, MAXTAG; |
310 | < | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
311 | < | if (flag) { |
312 | < | MAXTAG = *tagub; |
313 | < | } else { |
314 | < | MAXTAG = 32767; |
315 | < | } |
263 | > | os << nTotObjects << "\n"; |
264 | > | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
265 | ||
266 | < | int haveError; |
266 | > | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
267 | ||
268 | < | MPI_Status istatus; |
320 | < | int nCurObj; |
321 | < | int *MolToProcMap = mpiSim->getMolToProcMap(); |
268 | > | // Get the Node number which has this atom; |
269 | ||
270 | < | // write out header and node 0's coordinates |
270 | > | which_node = info_->getMolToProc(i); |
271 | ||
272 | < | if( worldRank == 0 ){ |
272 | > | if (which_node != masterNode) { //current molecule is in slave node |
273 | > | if (potatoes[which_node] + 1 >= MAXTAG) { |
274 | > | // The potato was going to exceed the maximum value, |
275 | > | // so wrap this processor potato back to 0: |
276 | ||
277 | < | // Node 0 needs a list of the magic potatoes for each processor; |
277 | > | potatoes[which_node] = 0; |
278 | > | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
279 | > | MPI_COMM_WORLD); |
280 | > | } |
281 | ||
282 | < | nProc = mpiSim->getNProcessors(); |
330 | < | potatoes = new int[nProc]; |
282 | > | myPotato = potatoes[which_node]; |
283 | ||
284 | < | //write out the comment lines |
285 | < | for (i = 0; i < nProc; i++) |
286 | < | potatoes[i] = 0; |
287 | < | |
336 | < | for(k = 0; k < outFile.size(); k++){ |
337 | < | *outFile[k] << nTotObjects << "\n"; |
284 | > | //recieve the number of integrableObject in current molecule |
285 | > | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
286 | > | MPI_COMM_WORLD, &istatus); |
287 | > | myPotato++; |
288 | ||
289 | < | *outFile[k] << currentTime << ";\t" |
290 | < | << entry_plug->Hmat[0][0] << "\t" |
291 | < | << entry_plug->Hmat[1][0] << "\t" |
292 | < | << entry_plug->Hmat[2][0] << ";\t" |
289 | > | for(int l = 0; l < nCurObj; l++) { |
290 | > | if (potatoes[which_node] + 2 >= MAXTAG) { |
291 | > | // The potato was going to exceed the maximum value, |
292 | > | // so wrap this processor potato back to 0: |
293 | ||
294 | < | << entry_plug->Hmat[0][1] << "\t" |
295 | < | << entry_plug->Hmat[1][1] << "\t" |
296 | < | << entry_plug->Hmat[2][1] << ";\t" |
294 | > | potatoes[which_node] = 0; |
295 | > | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
296 | > | 0, MPI_COMM_WORLD); |
297 | > | } |
298 | ||
299 | < | << entry_plug->Hmat[0][2] << "\t" |
300 | < | << entry_plug->Hmat[1][2] << "\t" |
301 | < | << entry_plug->Hmat[2][2] << ";"; |
351 | < | |
352 | < | *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; |
353 | < | } |
299 | > | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
300 | > | which_node, myPotato, MPI_COMM_WORLD, |
301 | > | &istatus); |
302 | ||
303 | < | currentIndex = 0; |
303 | > | atomTypeString = MPIatomTypeString; |
304 | ||
305 | < | for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { |
358 | < | |
359 | < | // Get the Node number which has this atom; |
360 | < | |
361 | < | which_node = MolToProcMap[i]; |
362 | < | |
363 | < | if (which_node != 0) { |
364 | < | |
365 | < | if (potatoes[which_node] + 1 >= MAXTAG) { |
366 | < | // The potato was going to exceed the maximum value, |
367 | < | // so wrap this processor potato back to 0: |
305 | > | myPotato++; |
306 | ||
307 | < | potatoes[which_node] = 0; |
308 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
309 | < | |
372 | < | } |
307 | > | MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
308 | > | MPI_COMM_WORLD, &istatus); |
309 | > | myPotato++; |
310 | ||
311 | < | myPotato = potatoes[which_node]; |
311 | > | MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
312 | ||
313 | < | //recieve the number of integrableObject in current molecule |
314 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, |
315 | < | myPotato, MPI_COMM_WORLD, &istatus); |
316 | < | myPotato++; |
380 | < | |
381 | < | for(int l = 0; l < nCurObj; l++){ |
313 | > | if (msgLen == 13) |
314 | > | isDirectional = 1; |
315 | > | else |
316 | > | isDirectional = 0; |
317 | ||
318 | < | if (potatoes[which_node] + 2 >= MAXTAG) { |
384 | < | // The potato was going to exceed the maximum value, |
385 | < | // so wrap this processor potato back to 0: |
318 | > | // If we've survived to here, format the line: |
319 | ||
320 | < | potatoes[which_node] = 0; |
321 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
322 | < | |
323 | < | } |
320 | > | if (!isDirectional) { |
321 | > | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
322 | > | atomTypeString, atomData[0], |
323 | > | atomData[1], atomData[2], |
324 | > | atomData[3], atomData[4], |
325 | > | atomData[5]); |
326 | ||
327 | < | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
328 | < | myPotato, MPI_COMM_WORLD, &istatus); |
327 | > | strcat(writeLine, |
328 | > | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
329 | > | } else { |
330 | > | sprintf(writeLine, |
331 | > | "%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", |
332 | > | atomTypeString, |
333 | > | atomData[0], |
334 | > | atomData[1], |
335 | > | atomData[2], |
336 | > | atomData[3], |
337 | > | atomData[4], |
338 | > | atomData[5], |
339 | > | atomData[6], |
340 | > | atomData[7], |
341 | > | atomData[8], |
342 | > | atomData[9], |
343 | > | atomData[10], |
344 | > | atomData[11], |
345 | > | atomData[12]); |
346 | > | } |
347 | ||
348 | < | atomTypeString = MPIatomTypeString; |
348 | > | os << writeLine; |
349 | ||
350 | < | myPotato++; |
350 | > | } // end for(int l =0) |
351 | ||
352 | < | MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, MPI_COMM_WORLD, &istatus); |
353 | < | myPotato++; |
352 | > | potatoes[which_node] = myPotato; |
353 | > | } else { //master node has current molecule |
354 | ||
355 | < | MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
355 | > | mol = info_->getMoleculeByGlobalIndex(i); |
356 | ||
357 | < | if(msgLen == 13) |
358 | < | isDirectional = 1; |
359 | < | else |
360 | < | isDirectional = 0; |
361 | < | |
362 | < | // If we've survived to here, format the line: |
363 | < | |
364 | < | if (!isDirectional) { |
365 | < | |
366 | < | sprintf( writeLine, |
414 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
415 | < | atomTypeString, |
416 | < | atomData[0], |
417 | < | atomData[1], |
418 | < | atomData[2], |
419 | < | atomData[3], |
420 | < | atomData[4], |
421 | < | atomData[5]); |
422 | < | |
423 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
424 | < | |
425 | < | } |
426 | < | else { |
427 | < | |
428 | < | sprintf( writeLine, |
429 | < | "%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", |
430 | < | atomTypeString, |
431 | < | atomData[0], |
432 | < | atomData[1], |
433 | < | atomData[2], |
434 | < | atomData[3], |
435 | < | atomData[4], |
436 | < | atomData[5], |
437 | < | atomData[6], |
438 | < | atomData[7], |
439 | < | atomData[8], |
440 | < | atomData[9], |
441 | < | atomData[10], |
442 | < | atomData[11], |
443 | < | atomData[12]); |
444 | < | |
445 | < | } |
446 | < | |
447 | < | for(k = 0; k < outFile.size(); k++) |
448 | < | *outFile[k] << writeLine; |
357 | > | if (mol == NULL) { |
358 | > | sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
359 | > | painCave.isFatal = 1; |
360 | > | simError(); |
361 | > | } |
362 | > | |
363 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
364 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
365 | > | |
366 | > | atomTypeString = integrableObject->getType().c_str(); |
367 | ||
368 | < | }// end for(int l =0) |
369 | < | potatoes[which_node] = myPotato; |
368 | > | pos = integrableObject->getPos(); |
369 | > | vel = integrableObject->getVel(); |
370 | ||
371 | < | } |
372 | < | else { |
373 | < | |
456 | < | haveError = 0; |
457 | < | |
458 | < | local_index = indexArray[currentIndex].first; |
371 | > | atomData[0] = pos[0]; |
372 | > | atomData[1] = pos[1]; |
373 | > | atomData[2] = pos[2]; |
374 | ||
375 | < | integrableObjects = (entry_plug->molecules[local_index]).getIntegrableObjects(); |
375 | > | atomData[3] = vel[0]; |
376 | > | atomData[4] = vel[1]; |
377 | > | atomData[5] = vel[2]; |
378 | ||
379 | < | for(iter= integrableObjects.begin(); iter != integrableObjects.end(); ++iter){ |
463 | < | sd = *iter; |
464 | < | atomTypeString = sd->getType(); |
465 | < | |
466 | < | sd->getPos(pos); |
467 | < | sd->getVel(vel); |
468 | < | |
469 | < | atomData[0] = pos[0]; |
470 | < | atomData[1] = pos[1]; |
471 | < | atomData[2] = pos[2]; |
379 | > | isDirectional = 0; |
380 | ||
381 | < | atomData[3] = vel[0]; |
382 | < | atomData[4] = vel[1]; |
475 | < | atomData[5] = vel[2]; |
476 | < | |
477 | < | isDirectional = 0; |
381 | > | if (integrableObject->isDirectional()) { |
382 | > | isDirectional = 1; |
383 | ||
384 | < | if( sd->isDirectional() ){ |
384 | > | q = integrableObject->getQ(); |
385 | > | ji = integrableObject->getJ(); |
386 | ||
387 | < | isDirectional = 1; |
388 | < | |
389 | < | sd->getQ( q ); |
484 | < | sd->getJ( ji ); |
387 | > | for(int j = 0; j < 6; j++) { |
388 | > | atomData[j] = atomData[j]; |
389 | > | } |
390 | ||
391 | < | for (int j = 0; j < 6 ; j++) |
392 | < | atomData[j] = atomData[j]; |
393 | < | |
394 | < | atomData[6] = q[0]; |
490 | < | atomData[7] = q[1]; |
491 | < | atomData[8] = q[2]; |
492 | < | atomData[9] = q[3]; |
493 | < | |
494 | < | atomData[10] = ji[0]; |
495 | < | atomData[11] = ji[1]; |
496 | < | atomData[12] = ji[2]; |
497 | < | } |
498 | < | |
499 | < | // If we've survived to here, format the line: |
500 | < | |
501 | < | if (!isDirectional) { |
502 | < | |
503 | < | sprintf( writeLine, |
504 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
505 | < | atomTypeString, |
506 | < | atomData[0], |
507 | < | atomData[1], |
508 | < | atomData[2], |
509 | < | atomData[3], |
510 | < | atomData[4], |
511 | < | atomData[5]); |
512 | < | |
513 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
514 | < | |
515 | < | } |
516 | < | else { |
517 | < | |
518 | < | sprintf( writeLine, |
519 | < | "%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", |
520 | < | atomTypeString, |
521 | < | atomData[0], |
522 | < | atomData[1], |
523 | < | atomData[2], |
524 | < | atomData[3], |
525 | < | atomData[4], |
526 | < | atomData[5], |
527 | < | atomData[6], |
528 | < | atomData[7], |
529 | < | atomData[8], |
530 | < | atomData[9], |
531 | < | atomData[10], |
532 | < | atomData[11], |
533 | < | atomData[12]); |
534 | < | |
535 | < | } |
536 | < | |
537 | < | for(k = 0; k < outFile.size(); k++) |
538 | < | *outFile[k] << writeLine; |
539 | < | |
540 | < | |
541 | < | }//end for(iter = integrableObject.begin()) |
542 | < | |
543 | < | currentIndex++; |
544 | < | } |
391 | > | atomData[6] = q[0]; |
392 | > | atomData[7] = q[1]; |
393 | > | atomData[8] = q[2]; |
394 | > | atomData[9] = q[3]; |
395 | ||
396 | < | }//end for(i = 0; i < mpiSim->getNmol()) |
397 | < | |
398 | < | for(k = 0; k < outFile.size(); k++) |
399 | < | outFile[k]->flush(); |
550 | < | |
551 | < | sprintf( checkPointMsg, |
552 | < | "Sucessfully took a dump.\n"); |
553 | < | |
554 | < | MPIcheckPoint(); |
555 | < | |
556 | < | delete[] potatoes; |
557 | < | |
558 | < | } else { |
396 | > | atomData[10] = ji[0]; |
397 | > | atomData[11] = ji[1]; |
398 | > | atomData[12] = ji[2]; |
399 | > | } |
400 | ||
401 | < | // worldRank != 0, so I'm a remote node. |
401 | > | // If we've survived to here, format the line: |
402 | ||
403 | < | // Set my magic potato to 0: |
403 | > | if (!isDirectional) { |
404 | > | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
405 | > | atomTypeString, atomData[0], |
406 | > | atomData[1], atomData[2], |
407 | > | atomData[3], atomData[4], |
408 | > | atomData[5]); |
409 | ||
410 | < | myPotato = 0; |
411 | < | currentIndex = 0; |
412 | < | |
413 | < | for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { |
414 | < | |
415 | < | // Am I the node which has this integrableObject? |
416 | < | |
417 | < | if (MolToProcMap[i] == worldRank) { |
410 | > | strcat(writeLine, |
411 | > | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
412 | > | } else { |
413 | > | sprintf(writeLine, |
414 | > | "%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", |
415 | > | atomTypeString, |
416 | > | atomData[0], |
417 | > | atomData[1], |
418 | > | atomData[2], |
419 | > | atomData[3], |
420 | > | atomData[4], |
421 | > | atomData[5], |
422 | > | atomData[6], |
423 | > | atomData[7], |
424 | > | atomData[8], |
425 | > | atomData[9], |
426 | > | atomData[10], |
427 | > | atomData[11], |
428 | > | atomData[12]); |
429 | > | } |
430 | ||
431 | ||
432 | < | if (myPotato + 1 >= MAXTAG) { |
575 | < | |
576 | < | // The potato was going to exceed the maximum value, |
577 | < | // so wrap this processor potato back to 0 (and block until |
578 | < | // node 0 says we can go: |
579 | < | |
580 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
581 | < | |
582 | < | } |
432 | > | os << writeLine; |
433 | ||
434 | < | local_index = indexArray[currentIndex].first; |
435 | < | integrableObjects = entry_plug->molecules[local_index].getIntegrableObjects(); |
436 | < | |
587 | < | nCurObj = integrableObjects.size(); |
588 | < | |
589 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, |
590 | < | myPotato, MPI_COMM_WORLD); |
591 | < | myPotato++; |
434 | > | } //end for(iter = integrableObject.begin()) |
435 | > | } |
436 | > | } //end for(i = 0; i < mpiSim->getNmol()) |
437 | ||
438 | < | for( iter = integrableObjects.begin(); iter != integrableObjects.end(); iter++){ |
438 | > | os.flush(); |
439 | > | std::cout << "master" << std::endl; |
440 | > | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
441 | ||
442 | < | if (myPotato + 2 >= MAXTAG) { |
596 | < | |
597 | < | // The potato was going to exceed the maximum value, |
598 | < | // so wrap this processor potato back to 0 (and block until |
599 | < | // node 0 says we can go: |
600 | < | |
601 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
602 | < | |
603 | < | } |
604 | < | |
605 | < | sd = *iter; |
606 | < | |
607 | < | atomTypeString = sd->getType(); |
442 | > | MPIcheckPoint(); |
443 | ||
444 | < | sd->getPos(pos); |
445 | < | sd->getVel(vel); |
444 | > | delete [] potatoes; |
445 | > | } else { |
446 | ||
447 | < | atomData[0] = pos[0]; |
613 | < | atomData[1] = pos[1]; |
614 | < | atomData[2] = pos[2]; |
447 | > | // worldRank != 0, so I'm a remote node. |
448 | ||
449 | < | atomData[3] = vel[0]; |
617 | < | atomData[4] = vel[1]; |
618 | < | atomData[5] = vel[2]; |
619 | < | |
620 | < | isDirectional = 0; |
449 | > | // Set my magic potato to 0: |
450 | ||
451 | < | if( sd->isDirectional() ){ |
451 | > | myPotato = 0; |
452 | ||
453 | < | isDirectional = 1; |
453 | > | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
454 | > | |
455 | > | // Am I the node which has this integrableObject? |
456 | > | int whichNode = info_->getMolToProc(i); |
457 | > | if (whichNode == worldRank) { |
458 | > | if (myPotato + 1 >= MAXTAG) { |
459 | > | |
460 | > | // The potato was going to exceed the maximum value, |
461 | > | // so wrap this processor potato back to 0 (and block until |
462 | > | // node 0 says we can go: |
463 | > | |
464 | > | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
465 | > | &istatus); |
466 | > | } |
467 | > | |
468 | > | mol = info_->getMoleculeByGlobalIndex(i); |
469 | > | |
470 | ||
471 | < | sd->getQ( q ); |
627 | < | sd->getJ( ji ); |
628 | < | |
629 | < | |
630 | < | atomData[6] = q[0]; |
631 | < | atomData[7] = q[1]; |
632 | < | atomData[8] = q[2]; |
633 | < | atomData[9] = q[3]; |
634 | < | |
635 | < | atomData[10] = ji[0]; |
636 | < | atomData[11] = ji[1]; |
637 | < | atomData[12] = ji[2]; |
638 | < | } |
471 | > | nCurObj = mol->getNIntegrableObjects(); |
472 | ||
473 | < | |
474 | < | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
473 | > | MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
474 | > | myPotato++; |
475 | ||
476 | < | // null terminate the string before sending (just in case): |
477 | < | MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
476 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
477 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
478 | ||
479 | < | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
647 | < | myPotato, MPI_COMM_WORLD); |
648 | < | |
649 | < | myPotato++; |
650 | < | |
651 | < | if (isDirectional) { |
479 | > | if (myPotato + 2 >= MAXTAG) { |
480 | ||
481 | < | MPI_Send(atomData, 13, MPI_DOUBLE, 0, |
482 | < | myPotato, MPI_COMM_WORLD); |
483 | < | |
656 | < | } else { |
481 | > | // The potato was going to exceed the maximum value, |
482 | > | // so wrap this processor potato back to 0 (and block until |
483 | > | // node 0 says we can go: |
484 | ||
485 | < | MPI_Send(atomData, 6, MPI_DOUBLE, 0, |
486 | < | myPotato, MPI_COMM_WORLD); |
487 | < | } |
485 | > | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
486 | > | &istatus); |
487 | > | } |
488 | ||
489 | < | myPotato++; |
489 | > | atomTypeString = integrableObject->getType().c_str(); |
490 | ||
491 | < | } |
491 | > | pos = integrableObject->getPos(); |
492 | > | vel = integrableObject->getVel(); |
493 | ||
494 | < | currentIndex++; |
495 | < | |
496 | < | } |
669 | < | |
670 | < | } |
494 | > | atomData[0] = pos[0]; |
495 | > | atomData[1] = pos[1]; |
496 | > | atomData[2] = pos[2]; |
497 | ||
498 | < | sprintf( checkPointMsg, |
499 | < | "Sucessfully took a dump.\n"); |
500 | < | MPIcheckPoint(); |
675 | < | |
676 | < | } |
498 | > | atomData[3] = vel[0]; |
499 | > | atomData[4] = vel[1]; |
500 | > | atomData[5] = vel[2]; |
501 | ||
502 | + | isDirectional = 0; |
503 | ||
504 | < | |
505 | < | #endif // is_mpi |
681 | < | } |
504 | > | if (integrableObject->isDirectional()) { |
505 | > | isDirectional = 1; |
506 | ||
507 | < | #ifdef IS_MPI |
507 | > | q = integrableObject->getQ(); |
508 | > | ji = integrableObject->getJ(); |
509 | ||
510 | < | // a couple of functions to let us escape the write loop |
510 | > | atomData[6] = q[0]; |
511 | > | atomData[7] = q[1]; |
512 | > | atomData[8] = q[2]; |
513 | > | atomData[9] = q[3]; |
514 | ||
515 | < | void dWrite::DieDieDie( void ){ |
515 | > | atomData[10] = ji[0]; |
516 | > | atomData[11] = ji[1]; |
517 | > | atomData[12] = ji[2]; |
518 | > | } |
519 | ||
520 | < | MPI_Finalize(); |
521 | < | exit (0); |
520 | > | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
521 | > | |
522 | > | // null terminate the std::string before sending (just in case): |
523 | > | MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
524 | > | |
525 | > | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
526 | > | myPotato, MPI_COMM_WORLD); |
527 | > | |
528 | > | myPotato++; |
529 | > | |
530 | > | if (isDirectional) { |
531 | > | MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, |
532 | > | MPI_COMM_WORLD); |
533 | > | } else { |
534 | > | MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, |
535 | > | MPI_COMM_WORLD); |
536 | > | } |
537 | > | |
538 | > | myPotato++; |
539 | > | } |
540 | > | |
541 | > | } |
542 | > | |
543 | > | } |
544 | > | std::cout << "slave" << std::endl; |
545 | > | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
546 | > | MPIcheckPoint(); |
547 | > | } |
548 | > | |
549 | > | #endif // is_mpi |
550 | > | |
551 | } | |
552 | ||
553 | < | #endif //is_mpi |
553 | > | }//end namespace oopse |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |