ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/io/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/io/DumpWriter.cpp (file contents):
Revision 1490 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
Revision 2060 by tim, Thu Feb 24 20:55:07 2005 UTC

# Line 1 | Line 1
1 < #define _LARGEFILE_SOURCE64
2 < #define _FILE_OFFSET_BITS 64
3 <
4 < #include <string.h>
5 < #include <iostream>
6 < #include <fstream>
7 < #include <algorithm>
8 < #include <utility>
9 <
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 > #include "io/basic_teebuf.hpp"
46   #ifdef IS_MPI
47   #include <mpi.h>
12 #include "mpiSimulation.hpp"
13
14 namespace dWrite{
15  void DieDieDie( void );
16 }
17
18 using namespace dWrite;
48   #endif //is_mpi
49  
50 < #include "ReadWrite.hpp"
22 < #include "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)
53 >                   : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){
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  
55 DumpWriter::~DumpWriter( ){
79  
80 + DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
81 +                   : info_(info), filename_(filename){
82   #ifdef IS_MPI
83 <  if(worldRank == 0 ){
83 >
84 >    if (worldRank == 0) {
85   #endif // is_mpi
86  
87 <    dumpFile.close();
87 >        eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";
88 >        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
89  
90 < #ifdef IS_MPI
91 <  }
92 < #endif // is_mpi
93 < }
90 >        if (!dumpFile_) {
91 >            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
92 >                    filename_.c_str());
93 >            painCave.isFatal = 1;
94 >            simError();
95 >        }
96  
97   #ifdef IS_MPI
98  
99 < /**
71 < * A hook function to load balancing
72 < */
99 >    }
100  
101 < void DumpWriter::update(){
102 <  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 < }
101 >    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
102 >    MPIcheckPoint();
103  
104 < /**
105 < * Sorting the local index by global index
88 < */
89 <
90 < void DumpWriter::sortByGlobalIndex(){
91 <  Molecule* mols = entry_plug->molecules;  
92 <  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);    
104 > #endif // is_mpi
105 >
106   }
107  
108 < #endif
108 > DumpWriter::~DumpWriter() {
109  
110 < void DumpWriter::writeDump(double currentTime){
110 > #ifdef IS_MPI
111  
112 <  ofstream finalOut;
113 <  vector<ofstream*> fileStreams;
112 >    if (worldRank == 0) {
113 > #endif // is_mpi
114  
115 +        dumpFile_.close();
116 +
117   #ifdef IS_MPI
118 <  if(worldRank == 0 ){
109 < #endif    
110 <    finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc );
111 <    if( !finalOut ){
112 <      sprintf( painCave.errMsg,
113 <               "Could not open \"%s\" for final dump output.\n",
114 <               entry_plug->finalName.c_str() );
115 <      painCave.isFatal = 1;
116 <      simError();
118 >
119      }
120 < #ifdef IS_MPI
119 <  }
120 >
121   #endif // is_mpi
122  
123 <  fileStreams.push_back(&finalOut);
123 <  fileStreams.push_back(&dumpFile);
123 > }
124  
125 <  writeFrame(fileStreams, currentTime);
125 > void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
126  
127 < #ifdef IS_MPI
128 <  finalOut.close();
129 < #endif
130 <        
131 < }
127 >    double currentTime;
128 >    Mat3x3d hmat;
129 >    double chi;
130 >    double integralOfChiDt;
131 >    Mat3x3d eta;
132 >    
133 >    currentTime = s->getTime();
134 >    hmat = s->getHmat();
135 >    chi = s->getChi();
136 >    integralOfChiDt = s->getIntegralOfChiDt();
137 >    eta = s->getEta();
138 >    
139 >    os << currentTime << ";\t"
140 >         << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
141 >         << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
142 >         << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
143  
144 < void DumpWriter::writeFinal(double currentTime){
144 >    //write out additional parameters, such as chi and eta
145  
146 <  ofstream finalOut;
136 <  vector<ofstream*> fileStreams;
146 >    os << chi << "\t" << integralOfChiDt << "\t;";
147  
148 < #ifdef IS_MPI
149 <  if(worldRank == 0 ){
150 < #endif // is_mpi
148 >    os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
149 >         << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
150 >         << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
151 >        
152 >    os << "\n";
153 > }
154  
155 <    finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc );
155 > void DumpWriter::writeFrame(std::ostream& os) {
156 >    const int BUFFERSIZE = 2000;
157 >    const int MINIBUFFERSIZE = 100;
158  
159 <    if( !finalOut ){
160 <      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 <    }
159 >    char tempBuffer[BUFFERSIZE];
160 >    char writeLine[BUFFERSIZE];
161  
162 < #ifdef IS_MPI
163 <  }
164 < #endif // is_mpi
165 <  
156 <  fileStreams.push_back(&finalOut);  
157 <  writeFrame(fileStreams, currentTime);
162 >    Quat4d q;
163 >    Vector3d ji;
164 >    Vector3d pos;
165 >    Vector3d vel;
166  
167 < #ifdef IS_MPI
168 <  finalOut.close();
169 < #endif
167 >    Molecule* mol;
168 >    StuntDouble* integrableObject;
169 >    SimInfo::MoleculeIterator mi;
170 >    Molecule::IntegrableObjectIterator ii;
171    
172 < }
172 >    int nTotObjects;    
173 >    nTotObjects = info_->getNGlobalIntegrableObjects();
174  
175 < void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){
175 > #ifndef IS_MPI
176  
167  const int BUFFERSIZE = 2000;
168  const int MINIBUFFERSIZE = 100;
177  
178 <  char tempBuffer[BUFFERSIZE];  
179 <  char writeLine[BUFFERSIZE];
178 >    os << nTotObjects << "\n";
179 >        
180 >    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
181  
182 <  int i;
174 <  unsigned int k;
182 >    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
183  
184 < #ifdef IS_MPI
185 <  
186 <  /*********************************************************************
179 <   * Documentation?  You want DOCUMENTATION?
180 <   *
181 <   * Why all the potatoes below?  
182 <   *
183 <   * To make a long story short, the original version of DumpWriter
184 <   * worked in the most inefficient way possible.  Node 0 would
185 <   * poke each of the node for an individual atom's formatted data
186 <   * as node 0 worked its way down the global index. This was particularly
187 <   * 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 <   *********************************************************************/
184 >        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
185 >            integrableObject = mol->nextIntegrableObject(ii)) {
186 >                
187  
188 <  int *potatoes;
189 <  int myPotato;
188 >            pos = integrableObject->getPos();
189 >            vel = integrableObject->getVel();
190  
191 <  int nProc;
192 <  int j, which_node, done, which_atom, local_index, currentIndex;
193 <  double atomData[13];
194 <  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
191 >            sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
192 >                    integrableObject->getType().c_str(),
193 >                    pos[0], pos[1], pos[2],
194 >                    vel[0], vel[1], vel[2]);
195  
196 <  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";
196 >            strcpy(writeLine, tempBuffer);
197  
198 <    *outFile[k] << currentTime << ";\t"
199 <               << entry_plug->Hmat[0][0] << "\t"
200 <                     << 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"
198 >            if (integrableObject->isDirectional()) {
199 >                q = integrableObject->getQ();
200 >                ji = integrableObject->getJ();
201  
202 <                     << entry_plug->Hmat[0][2] << "\t"
203 <                     << entry_plug->Hmat[1][2] << "\t"
204 <                     << entry_plug->Hmat[2][2] << ";";
202 >                sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
203 >                        q[0], q[1], q[2], q[3],
204 >                        ji[0], ji[1], ji[2]);
205 >                strcat(writeLine, tempBuffer);
206 >            } else {
207 >                strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
208 >            }
209  
210 <    //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++ ){
210 >            os << writeLine;
211  
212 <    integrableObjects = entry_plug->molecules[i].getIntegrableObjects();
262 <    molName = (entry_plug->compStamps[entry_plug->molecules[i].getStampID()])->getID();
263 <    
264 <    for( iter = integrableObjects.begin();iter !=  integrableObjects.end(); ++iter){
265 <      sd = *iter;
266 <      sd->getPos(pos);
267 <      sd->getVel(vel);
268 <
269 <      sprintf( tempBuffer,
270 <             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
271 <             sd->getType(),
272 <             pos[0],
273 <             pos[1],
274 <             pos[2],
275 <             vel[0],
276 <             vel[1],
277 <             vel[2]);
278 <      strcpy( writeLine, tempBuffer );
279 <
280 <      if( sd->isDirectional() ){
281 <
282 <        sd->getQ( q );
283 <        sd->getJ( ji );
284 <
285 <        sprintf( tempBuffer,
286 <               "%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;      
212 >        }
213      }
214  
215 < }
304 <
215 >    os.flush();
216   #else // is_mpi
217 +    /*********************************************************************
218 +     * Documentation?  You want DOCUMENTATION?
219 +     *
220 +     * Why all the potatoes below?  
221 +     *
222 +     * To make a long story short, the original version of DumpWriter
223 +     * worked in the most inefficient way possible.  Node 0 would
224 +     * poke each of the node for an individual atom's formatted data
225 +     * as node 0 worked its way down the global index. This was particularly
226 +     * inefficient since the method blocked all processors at every atom
227 +     * (and did it twice!).
228 +     *
229 +     * An intermediate version of DumpWriter could be described from Node
230 +     * zero's perspective as follows:
231 +     *
232 +     *  1) Have 100 of your friends stand in a circle.
233 +     *  2) When you say go, have all of them start tossing potatoes at
234 +     *     you (one at a time).
235 +     *  3) Catch the potatoes.
236 +     *
237 +     * It was an improvement, but MPI has buffers and caches that could
238 +     * best be described in this analogy as "potato nets", so there's no
239 +     * need to block the processors atom-by-atom.
240 +     *
241 +     * This new and improved DumpWriter works in an even more efficient
242 +     * way:
243 +     *
244 +     *  1) Have 100 of your friend stand in a circle.
245 +     *  2) When you say go, have them start tossing 5-pound bags of
246 +     *     potatoes at you.
247 +     *  3) Once you've caught a friend's bag of potatoes,
248 +     *     toss them a spud to let them know they can toss another bag.
249 +     *
250 +     * How's THAT for documentation?
251 +     *
252 +     *********************************************************************/
253 +    const int masterNode = 0;
254  
255 <  /* code to find maximum tag value */
256 <  
257 <  int *tagub, flag, MAXTAG;
258 <  MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
259 <  if (flag) {
260 <    MAXTAG = *tagub;
261 <  } else {
262 <    MAXTAG = 32767;
263 <  }  
255 >    int * potatoes;
256 >    int myPotato;
257 >    int nProc;
258 >    int which_node;
259 >    double atomData[13];
260 >    int isDirectional;
261 >    const char * atomTypeString;
262 >    char MPIatomTypeString[MINIBUFFERSIZE];
263 >    int msgLen; // the length of message actually recieved at master nodes
264 >    int haveError;
265 >    MPI_Status istatus;
266 >    int nCurObj;
267 >    
268 >    // code to find maximum tag value
269 >    int * tagub;
270 >    int flag;
271 >    int MAXTAG;
272 >    MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
273  
274 <  int haveError;
274 >    if (flag) {
275 >        MAXTAG = *tagub;
276 >    } else {
277 >        MAXTAG = 32767;
278 >    }
279  
280 <  MPI_Status istatus;
320 <  int nCurObj;
321 <  int *MolToProcMap = mpiSim->getMolToProcMap();
280 >    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
281  
282 <  // write out header and node 0's coordinates
282 >        // Node 0 needs a list of the magic potatoes for each processor;
283  
284 <  if( worldRank == 0 ){
284 >        MPI_Comm_size(MPI_COMM_WORLD, &nProc);
285 >        potatoes = new int[nProc];
286  
287 <    // Node 0 needs a list of the magic potatoes for each processor;
287 >        //write out the comment lines
288 >        for(int i = 0; i < nProc; i++) {
289 >            potatoes[i] = 0;
290 >        }
291  
329    nProc = mpiSim->getNProcessors();
330    potatoes = new int[nProc];
292  
293 <    //write out the comment lines
294 <    for (i = 0; i < nProc; i++)
334 <      potatoes[i] = 0;
335 <    
336 <      for(k = 0; k < outFile.size(); k++){
337 <        *outFile[k] << nTotObjects << "\n";
293 >        os << nTotObjects << "\n";
294 >        writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
295  
296 <        *outFile[k] << currentTime << ";\t"
340 <                         << entry_plug->Hmat[0][0] << "\t"
341 <                         << entry_plug->Hmat[1][0] << "\t"
342 <                         << entry_plug->Hmat[2][0] << ";\t"
296 >        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
297  
298 <                         << entry_plug->Hmat[0][1] << "\t"
345 <                         << entry_plug->Hmat[1][1] << "\t"
346 <                         << entry_plug->Hmat[2][1] << ";\t"
298 >            // Get the Node number which has this atom;
299  
300 <                         << entry_plug->Hmat[0][2] << "\t"
349 <                         << entry_plug->Hmat[1][2] << "\t"
350 <                         << entry_plug->Hmat[2][2] << ";";
351 <  
352 <        *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
353 <    }
300 >            which_node = info_->getMolToProc(i);
301  
302 <    currentIndex = 0;
302 >            if (which_node != masterNode) { //current molecule is in slave node
303 >                if (potatoes[which_node] + 1 >= MAXTAG) {
304 >                    // The potato was going to exceed the maximum value,
305 >                    // so wrap this processor potato back to 0:        
306  
307 <    for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) {
308 <      
309 <      // Get the Node number which has this atom;
310 <      
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:        
307 >                    potatoes[which_node] = 0;
308 >                    MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
309 >                             MPI_COMM_WORLD);
310 >                }
311  
312 <          potatoes[which_node] = 0;          
370 <          MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD);
371 <          
372 <        }
312 >                myPotato = potatoes[which_node];
313  
314 <        myPotato = potatoes[which_node];        
314 >                //recieve the number of integrableObject in current molecule
315 >                MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
316 >                         MPI_COMM_WORLD, &istatus);
317 >                myPotato++;
318  
319 <        //recieve the number of integrableObject in current molecule
320 <        MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
321 <                 myPotato, MPI_COMM_WORLD, &istatus);
322 <        myPotato++;
380 <        
381 <        for(int l = 0; l < nCurObj; l++){
319 >                for(int l = 0; l < nCurObj; l++) {
320 >                    if (potatoes[which_node] + 2 >= MAXTAG) {
321 >                        // The potato was going to exceed the maximum value,
322 >                        // so wrap this processor potato back to 0:        
323  
324 <          if (potatoes[which_node] + 2 >= MAXTAG) {
325 <            // The potato was going to exceed the maximum value,
326 <            // so wrap this processor potato back to 0:        
324 >                        potatoes[which_node] = 0;
325 >                        MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
326 >                                 0, MPI_COMM_WORLD);
327 >                    }
328  
329 <            potatoes[which_node] = 0;          
330 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD);
331 <            
390 <          }
329 >                    MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
330 >                             which_node, myPotato, MPI_COMM_WORLD,
331 >                             &istatus);
332  
333 <          MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
393 <          myPotato, MPI_COMM_WORLD, &istatus);
333 >                    atomTypeString = MPIatomTypeString;
334  
335 <          atomTypeString = MPIatomTypeString;
335 >                    myPotato++;
336  
337 <          myPotato++;
338 <
339 <          MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, MPI_COMM_WORLD, &istatus);
400 <          myPotato++;
401 <
402 <          MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
403 <
404 <          if(msgLen  == 13)
405 <            isDirectional = 1;
406 <          else
407 <            isDirectional = 0;
408 <          
409 <          // If we've survived to here, format the line:
410 <            
411 <          if (!isDirectional) {
412 <        
413 <            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;            
337 >                    MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
338 >                             MPI_COMM_WORLD, &istatus);
339 >                    myPotato++;
340  
341 <        }// end for(int l =0)
451 <        potatoes[which_node] = myPotato;
341 >                    MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
342  
343 <      }
344 <      else {
345 <        
346 <        haveError = 0;
457 <        
458 <            local_index = indexArray[currentIndex].first;        
343 >                    if (msgLen == 13)
344 >                        isDirectional = 1;
345 >                    else
346 >                        isDirectional = 0;
347  
348 <        integrableObjects = (entry_plug->molecules[local_index]).getIntegrableObjects();
348 >                    // If we've survived to here, format the line:
349  
350 <        for(iter= integrableObjects.begin(); iter != integrableObjects.end(); ++iter){    
351 <                sd = *iter;
352 <            atomTypeString = sd->getType();
353 <            
354 <            sd->getPos(pos);
355 <            sd->getVel(vel);          
468 <          
469 <            atomData[0] = pos[0];
470 <            atomData[1] = pos[1];
471 <            atomData[2] = pos[2];
350 >                    if (!isDirectional) {
351 >                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
352 >                                atomTypeString, atomData[0],
353 >                                atomData[1], atomData[2],
354 >                                atomData[3], atomData[4],
355 >                                atomData[5]);
356  
357 <            atomData[3] = vel[0];
358 <            atomData[4] = vel[1];
359 <            atomData[5] = vel[2];
360 <              
361 <            isDirectional = 0;
357 >                        strcat(writeLine,
358 >                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
359 >                    } else {
360 >                        sprintf(writeLine,
361 >                                "%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",
362 >                                atomTypeString,
363 >                                atomData[0],
364 >                                atomData[1],
365 >                                atomData[2],
366 >                                atomData[3],
367 >                                atomData[4],
368 >                                atomData[5],
369 >                                atomData[6],
370 >                                atomData[7],
371 >                                atomData[8],
372 >                                atomData[9],
373 >                                atomData[10],
374 >                                atomData[11],
375 >                                atomData[12]);
376 >                    }
377  
378 <            if( sd->isDirectional() ){
378 >                    os << writeLine;
379  
380 <              isDirectional = 1;
482 <                
483 <              sd->getQ( q );
484 <              sd->getJ( ji );
380 >                } // end for(int l =0)
381  
382 <              for (int j = 0; j < 6 ; j++)
383 <                atomData[j] = atomData[j];            
488 <              
489 <              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 <      }
382 >                potatoes[which_node] = myPotato;
383 >            } else { //master node has current molecule
384  
385 <    }//end for(i = 0; i < mpiSim->getNmol())
547 <    
548 <    for(k = 0; k < outFile.size(); k++)
549 <      outFile[k]->flush();
550 <    
551 <    sprintf( checkPointMsg,
552 <             "Sucessfully took a dump.\n");
553 <    
554 <    MPIcheckPoint();        
555 <    
556 <    delete[] potatoes;
557 <    
558 <  } else {
385 >                mol = info_->getMoleculeByGlobalIndex(i);
386  
387 <    // worldRank != 0, so I'm a remote node.  
387 >                if (mol == NULL) {
388 >                    sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
389 >                    painCave.isFatal = 1;
390 >                    simError();
391 >                }
392 >                
393 >                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
394 >                    integrableObject = mol->nextIntegrableObject(ii)) {
395 >                        
396 >                    atomTypeString = integrableObject->getType().c_str();
397  
398 <    // Set my magic potato to 0:
398 >                    pos = integrableObject->getPos();
399 >                    vel = integrableObject->getVel();
400  
401 <    myPotato = 0;
402 <    currentIndex = 0;
403 <    
567 <    for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) {
568 <      
569 <      // Am I the node which has this integrableObject?
570 <      
571 <      if (MolToProcMap[i] == worldRank) {
401 >                    atomData[0] = pos[0];
402 >                    atomData[1] = pos[1];
403 >                    atomData[2] = pos[2];
404  
405 +                    atomData[3] = vel[0];
406 +                    atomData[4] = vel[1];
407 +                    atomData[5] = vel[2];
408  
409 <        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 <        }
409 >                    isDirectional = 0;
410  
411 <          local_index = indexArray[currentIndex].first;        
412 <          integrableObjects = entry_plug->molecules[local_index].getIntegrableObjects();
586 <          
587 <          nCurObj = integrableObjects.size();
588 <                      
589 <          MPI_Send(&nCurObj, 1, MPI_INT, 0,
590 <                             myPotato, MPI_COMM_WORLD);
591 <          myPotato++;
411 >                    if (integrableObject->isDirectional()) {
412 >                        isDirectional = 1;
413  
414 <          for( iter = integrableObjects.begin(); iter  != integrableObjects.end(); iter++){
414 >                        q = integrableObject->getQ();
415 >                        ji = integrableObject->getJ();
416  
417 <            if (myPotato + 2 >= MAXTAG) {
418 <          
419 <              // 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();
417 >                        for(int j = 0; j < 6; j++) {
418 >                            atomData[j] = atomData[j];
419 >                        }
420  
421 <            sd->getPos(pos);
422 <            sd->getVel(vel);
421 >                        atomData[6] = q[0];
422 >                        atomData[7] = q[1];
423 >                        atomData[8] = q[2];
424 >                        atomData[9] = q[3];
425  
426 <            atomData[0] = pos[0];
427 <            atomData[1] = pos[1];
428 <            atomData[2] = pos[2];
426 >                        atomData[10] = ji[0];
427 >                        atomData[11] = ji[1];
428 >                        atomData[12] = ji[2];
429 >                    }
430  
431 <            atomData[3] = vel[0];
617 <            atomData[4] = vel[1];
618 <            atomData[5] = vel[2];
619 <              
620 <            isDirectional = 0;
431 >                    // If we've survived to here, format the line:
432  
433 <            if( sd->isDirectional() ){
434 <
435 <                isDirectional = 1;
433 >                    if (!isDirectional) {
434 >                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
435 >                                atomTypeString, atomData[0],
436 >                                atomData[1], atomData[2],
437 >                                atomData[3], atomData[4],
438 >                                atomData[5]);
439 >
440 >                        strcat(writeLine,
441 >                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
442 >                    } else {
443 >                        sprintf(writeLine,
444 >                                "%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",
445 >                                atomTypeString,
446 >                                atomData[0],
447 >                                atomData[1],
448 >                                atomData[2],
449 >                                atomData[3],
450 >                                atomData[4],
451 >                                atomData[5],
452 >                                atomData[6],
453 >                                atomData[7],
454 >                                atomData[8],
455 >                                atomData[9],
456 >                                atomData[10],
457 >                                atomData[11],
458 >                                atomData[12]);
459 >                    }
460 >
461 >
462 >                    os << writeLine;
463 >
464 >                } //end for(iter = integrableObject.begin())
465 >            }
466 >        } //end for(i = 0; i < mpiSim->getNmol())
467 >
468 >        os.flush();
469 >        
470 >        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
471 >        MPIcheckPoint();
472 >
473 >        delete [] potatoes;
474 >    } else {
475 >
476 >        // worldRank != 0, so I'm a remote node.  
477 >
478 >        // Set my magic potato to 0:
479 >
480 >        myPotato = 0;
481 >
482 >        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
483 >
484 >            // Am I the node which has this integrableObject?
485 >            int whichNode = info_->getMolToProc(i);
486 >            if (whichNode == worldRank) {
487 >                if (myPotato + 1 >= MAXTAG) {
488 >
489 >                    // The potato was going to exceed the maximum value,
490 >                    // so wrap this processor potato back to 0 (and block until
491 >                    // node 0 says we can go:
492 >
493 >                    MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
494 >                             &istatus);
495 >                }
496 >
497 >                mol = info_->getMoleculeByGlobalIndex(i);
498 >
499                  
500 <                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 <              }
500 >                nCurObj = mol->getNIntegrableObjects();
501  
502 <            
503 <            strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
502 >                MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD);
503 >                myPotato++;
504  
505 <            // null terminate the string before sending (just in case):
506 <            MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
505 >                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
506 >                    integrableObject = mol->nextIntegrableObject(ii)) {
507  
508 <            MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
647 <                             myPotato, MPI_COMM_WORLD);
648 <            
649 <            myPotato++;
650 <            
651 <            if (isDirectional) {
508 >                    if (myPotato + 2 >= MAXTAG) {
509  
510 <              MPI_Send(atomData, 13, MPI_DOUBLE, 0,
511 <                       myPotato, MPI_COMM_WORLD);
512 <              
656 <            } else {
510 >                        // The potato was going to exceed the maximum value,
511 >                        // so wrap this processor potato back to 0 (and block until
512 >                        // node 0 says we can go:
513  
514 <              MPI_Send(atomData, 6, MPI_DOUBLE, 0,
515 <                       myPotato, MPI_COMM_WORLD);
516 <            }
514 >                        MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
515 >                                 &istatus);
516 >                    }
517  
518 <            myPotato++;  
518 >                    atomTypeString = integrableObject->getType().c_str();
519  
520 <          }
520 >                    pos = integrableObject->getPos();
521 >                    vel = integrableObject->getVel();
522  
523 <          currentIndex++;    
524 <          
525 <        }
669 <      
670 <      }
523 >                    atomData[0] = pos[0];
524 >                    atomData[1] = pos[1];
525 >                    atomData[2] = pos[2];
526  
527 <    sprintf( checkPointMsg,
528 <             "Sucessfully took a dump.\n");
529 <    MPIcheckPoint();                
530 <    
527 >                    atomData[3] = vel[0];
528 >                    atomData[4] = vel[1];
529 >                    atomData[5] = vel[2];
530 >
531 >                    isDirectional = 0;
532 >
533 >                    if (integrableObject->isDirectional()) {
534 >                        isDirectional = 1;
535 >
536 >                        q = integrableObject->getQ();
537 >                        ji = integrableObject->getJ();
538 >
539 >                        atomData[6] = q[0];
540 >                        atomData[7] = q[1];
541 >                        atomData[8] = q[2];
542 >                        atomData[9] = q[3];
543 >
544 >                        atomData[10] = ji[0];
545 >                        atomData[11] = ji[1];
546 >                        atomData[12] = ji[2];
547 >                    }
548 >
549 >                    strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
550 >
551 >                    // null terminate the  std::string before sending (just in case):
552 >                    MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
553 >
554 >                    MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
555 >                             myPotato, MPI_COMM_WORLD);
556 >
557 >                    myPotato++;
558 >
559 >                    if (isDirectional) {
560 >                        MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato,
561 >                                 MPI_COMM_WORLD);
562 >                    } else {
563 >                        MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato,
564 >                                 MPI_COMM_WORLD);
565 >                    }
566 >
567 >                    myPotato++;
568 >                }
569 >                    
570 >            }
571 >            
572 >        }
573 >        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
574 >        MPIcheckPoint();
575      }
576  
577 + #endif // is_mpi
578  
579 <  
579 > }
580 >
581 > void DumpWriter::writeDump() {
582 >    writeFrame(dumpFile_);
583 >
584 > }
585 >
586 > void DumpWriter::writeEor() {
587 >    std::ofstream eorStream;
588 >    
589 > #ifdef IS_MPI
590 >    if (worldRank == 0) {
591   #endif // is_mpi
592 +
593 +        eorStream.open(eorFilename_.c_str());
594 +        if (!eorStream.is_open()) {
595 +            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
596 +                    eorFilename_.c_str());
597 +            painCave.isFatal = 1;
598 +            simError();
599 +        }
600 +
601 + #ifdef IS_MPI
602 +    }
603 + #endif // is_mpi    
604 +
605 +    writeFrame(eorStream);
606   }
607  
608 +
609 + void DumpWriter::writeDumpAndEor() {
610 +    std::ofstream eorStream;
611 +    std::vector<std::streambuf*> buffers;
612   #ifdef IS_MPI
613 +    if (worldRank == 0) {
614 + #endif // is_mpi
615  
616 < // a couple of functions to let us escape the write loop
616 >        buffers.push_back(dumpFile_.rdbuf());
617  
618 < void dWrite::DieDieDie( void ){
618 >        eorStream.open(eorFilename_.c_str());
619 >        if (!eorStream.is_open()) {
620 >            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
621 >                    eorFilename_.c_str());
622 >            painCave.isFatal = 1;
623 >            simError();
624 >        }
625  
626 <  MPI_Finalize();
627 <  exit (0);
626 >        buffers.push_back(eorStream.rdbuf());
627 >        
628 > #ifdef IS_MPI
629 >    }
630 > #endif // is_mpi    
631 >
632 >    TeeBuf tbuf(buffers.begin(), buffers.end());
633 >    std::ostream os(&tbuf);
634 >
635 >    writeFrame(os);
636 >    
637   }
638  
639 < #endif //is_mpi
639 >
640 >
641 > }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines