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