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

Comparing branches/new_design/OOPSE-4/src/io/DumpWriter.cpp (file contents):
Revision 1683, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1808 by tim, Tue Nov 30 23:14:29 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines