--- trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/01/13 20:04:28 934 +++ trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/01/15 14:22:16 947 @@ -40,15 +40,6 @@ DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ simError(); } - finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); - if( !finalOut ){ - sprintf( painCave.errMsg, - "Could not open \"%s\" for final dump output.\n", - entry_plug->finalName ); - painCave.isFatal = 1; - simError(); - } - #ifdef IS_MPI } @@ -68,7 +59,6 @@ DumpWriter::~DumpWriter( ){ #endif // is_mpi dumpFile.close(); - finalOut.close(); #ifdef IS_MPI } @@ -111,11 +101,20 @@ void DumpWriter::writeDump(double currentTime){ void DumpWriter::writeDump(double currentTime){ + ofstream finalOut; vector fileStreams; #ifdef IS_MPI if(worldRank == 0 ){ - finalOut.seekp(0); + + finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); + if( !finalOut ){ + sprintf( painCave.errMsg, + "Could not open \"%s\" for final dump output.\n", + entry_plug->finalName ); + painCave.isFatal = 1; + simError(); + } } #endif // is_mpi @@ -123,21 +122,40 @@ void DumpWriter::writeDump(double currentTime){ fileStreams.push_back(&dumpFile); writeFrame(fileStreams, currentTime); + +#ifdef IS_MPI + finalOut.close(); +#endif } void DumpWriter::writeFinal(double currentTime){ + ofstream finalOut; vector fileStreams; #ifdef IS_MPI if(worldRank == 0 ){ - finalOut.seekp(0); + + finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); + + if( !finalOut ){ + sprintf( painCave.errMsg, + "Could not open \"%s\" for final dump output.\n", + entry_plug->finalName ); + painCave.isFatal = 1; + simError(); + } + } #endif // is_mpi fileStreams.push_back(&finalOut); writeFrame(fileStreams, currentTime); + +#ifdef IS_MPI + finalOut.close(); +#endif } @@ -146,13 +164,50 @@ void DumpWriter::writeFrame( vector& outFil const int BUFFERSIZE = 2000; const int MINIBUFFERSIZE = 100; - char tempBuffer[BUFFERSIZE]; + char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; int i, k; #ifdef IS_MPI + /********************************************************************* + * Documentation? You want DOCUMENTATION? + * + * Why all the potatoes below? + * + * To make a long story short, the original version of DumpWriter + * worked in the most inefficient way possible. Node 0 would + * poke each of the node for an individual atom's formatted data + * as node 0 worked its way down the global index. This was particularly + * inefficient since the method blocked all processors at every atom + * (and did it twice!). + * + * An intermediate version of DumpWriter could be described from Node + * zero's perspective as follows: + * + * 1) Have 100 of your friends stand in a circle. + * 2) When you say go, have all of them start tossing potatoes at + * you (one at a time). + * 3) Catch the potatoes. + * + * It was an improvement, but MPI has buffers and caches that could + * best be described in this analogy as "potato nets", so there's no + * need to block the processors atom-by-atom. + * + * This new and improved DumpWriter works in an even more efficient + * way: + * + * 1) Have 100 of your friend stand in a circle. + * 2) When you say go, have them start tossing 5-pound bags of + * potatoes at you. + * 3) Once you've caught a friend's bag of potatoes, + * toss them a spud to let them know they can toss another bag. + * + * How's THAT for documentation? + * + *********************************************************************/ + int *potatoes; int myPotato;