diff --git a/applications/test/FixedList/FixedListTest.C b/applications/test/FixedList/FixedListTest.C index e46e910d3a..97292f1363 100644 --- a/applications/test/FixedList/FixedListTest.C +++ b/applications/test/FixedList/FixedListTest.C @@ -78,10 +78,7 @@ int main(int argc, char *argv[]) Serr<< "slave sending to master " << Pstream::masterNo() << endl; - OPstream toMaster - ( - Pstream::blocking, Pstream::masterNo(), IOstream::ASCII - ); + OPstream toMaster(Pstream::blocking, Pstream::masterNo()); FixedList list3; list3[0] = 0; @@ -98,10 +95,7 @@ int main(int argc, char *argv[]) ) { Serr << "master receiving from slave " << slave << endl; - IPstream fromSlave - ( - Pstream::blocking, slave, IOstream::ASCII - ); + IPstream fromSlave(Pstream::blocking, slave); FixedList list3(fromSlave); Serr<< list3 << endl; diff --git a/applications/test/router/Gather/GatherBase.C b/applications/test/router/Gather/GatherBase.C index e171fd45c5..9950bc9753 100644 --- a/applications/test/router/Gather/GatherBase.C +++ b/applications/test/router/Gather/GatherBase.C @@ -22,13 +22,9 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ #include "GatherBase.H" -#include "IPstream.H" -#include "OPstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/etc/cshrc b/etc/cshrc index 39a5210ca0..5b698ab110 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -32,7 +32,7 @@ #------------------------------------------------------------------------------ setenv WM_PROJECT OpenFOAM -setenv WM_PROJECT_VERSION dev +setenv WM_PROJECT_VERSION UPstream ################################################################################ # USER EDITABLE PART @@ -96,8 +96,8 @@ if ( ! $?WM_PRECISION_OPTION ) setenv WM_PRECISION_OPTION DP if ( ! $?WM_COMPILE_OPTION ) setenv WM_COMPILE_OPTION Opt # WM_MPLIB = | OPENMPI | MPICH | MPICH-GM | HPMPI | GAMMA | MPI | QSMPI -if ( ! $?WM_MPLIB ) setenv WM_MPLIB OPENMPI - +#if ( ! $?WM_MPLIB ) setenv WM_MPLIB OPENMPI +setenv WM_MPLIB OPENMPI # Run options (floating-point signal handling and memory initialisation) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 6ba6b90cf1..cda0ade7b4 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -108,11 +108,14 @@ StringStreams = $(Streams)/StringStreams $(StringStreams)/StringStreamsPrint.C Pstreams = $(Streams)/Pstreams -$(Pstreams)/Pstream.C -$(Pstreams)/PstreamCommsStruct.C +$(Pstreams)/UIPstream.C $(Pstreams)/IPstream.C +$(Pstreams)/UPstream.C +$(Pstreams)/UPstreamCommsStruct.C +$(Pstreams)/Pstream.C +$(Pstreams)/UOPstream.C $(Pstreams)/OPstream.C -$(Pstreams)/PstreamsPrint.C +$(Pstreams)/PstreamBuffers.C dictionary = db/dictionary $(dictionary)/dictionary.C diff --git a/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C b/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C index aa6118dc42..0d6084671e 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/ParSortableList.C @@ -114,7 +114,7 @@ void Foam::ParSortableList::checkAndSend } { - OPstream toSlave(destProcI); + OPstream toSlave(Pstream::blocking, destProcI); toSlave << values << indices; } } @@ -311,7 +311,7 @@ void Foam::ParSortableList::sort() Pout<< "Receiving from " << procI << endl; } - IPstream fromSlave(procI); + IPstream fromSlave(Pstream::blocking, procI); fromSlave >> recValues >> recIndices; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C index 4ad3f6bbec..a970d6104c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C @@ -24,291 +24,22 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" #include "IPstream.H" -#include "int.H" -#include "token.H" -#include +// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * // - -inline void Foam::IPstream::checkEof() -{ - if (bufPosition_ == messageSize_) - { - setEof(); - } -} - - -template -inline void Foam::IPstream::readFromBuffer(T& t) -{ - const size_t align = sizeof(T); - bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1)); - - t = reinterpret_cast(buf_[bufPosition_]); - bufPosition_ += sizeof(T); - checkEof(); -} - - -inline void Foam::IPstream::readFromBuffer +Foam::IPstream::IPstream ( - void* data, - size_t count, - size_t align + const commsTypes commsType, + const int fromProcNo, + const label bufSize, + streamFormat format, + versionNumber version ) -{ - if (align > 1) - { - bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1)); - } - - register const char* bufPtr = &buf_[bufPosition_]; - register char* dataPtr = reinterpret_cast(data); - register size_t i = count; - while (i--) *dataPtr++ = *bufPtr++; - bufPosition_ += count; - checkEof(); -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::IPstream::~IPstream() -{ - if (bufPosition_ < messageSize_) - { - FatalErrorIn("IPstream::~IPstream()") - << "Message not fully consumed. messageSize:" << messageSize_ - << " bytes of which only " << bufPosition_ - << " consumed." << Foam::abort(FatalError); - } -} - - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -Foam::Istream& Foam::IPstream::read(token& t) -{ - // Return the put back token if it exists - if (Istream::getBack(t)) - { - return *this; - } - - char c; - - // return on error - if (!read(c)) - { - t.setBad(); - return *this; - } - - // Set the line number of this token to the current stream line number - t.lineNumber() = lineNumber(); - - // Analyse input starting with this character. - switch (c) - { - // Punctuation - case token::END_STATEMENT : - case token::BEGIN_LIST : - case token::END_LIST : - case token::BEGIN_SQR : - case token::END_SQR : - case token::BEGIN_BLOCK : - case token::END_BLOCK : - case token::COLON : - case token::COMMA : - case token::ASSIGN : - case token::ADD : - case token::SUBTRACT : - case token::MULTIPLY : - case token::DIVIDE : - { - t = token::punctuationToken(c); - return *this; - } - - // Word - case token::WORD : - { - word* pval = new word; - if (read(*pval)) - { - if (token::compound::isCompound(*pval)) - { - t = token::compound::New(*pval, *this).ptr(); - delete pval; - } - else - { - t = pval; - } - } - else - { - delete pval; - t.setBad(); - } - return *this; - } - - // String - case token::STRING : - { - string* pval = new string; - if (read(*pval)) - { - t = pval; - } - else - { - delete pval; - t.setBad(); - } - return *this; - } - - // Label - case token::LABEL : - { - label val; - if (read(val)) - { - t = val; - } - else - { - t.setBad(); - } - return *this; - } - - // floatScalar - case token::FLOAT_SCALAR : - { - floatScalar val; - if (read(val)) - { - t = val; - } - else - { - t.setBad(); - } - return *this; - } - - // doubleScalar - case token::DOUBLE_SCALAR : - { - doubleScalar val; - if (read(val)) - { - t = val; - } - else - { - t.setBad(); - } - return *this; - } - - // Character (returned as a single character word) or error - default: - { - if (isalpha(c)) - { - t = word(c); - return *this; - } - - setBad(); - t.setBad(); - - return *this; - } - } -} - - -Foam::Istream& Foam::IPstream::read(char& c) -{ - c = buf_[bufPosition_]; - bufPosition_++; - checkEof(); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(word& str) -{ - size_t len; - readFromBuffer(len); - str = &buf_[bufPosition_]; - bufPosition_ += len + 1; - checkEof(); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(string& str) -{ - size_t len; - readFromBuffer(len); - str = &buf_[bufPosition_]; - bufPosition_ += len + 1; - checkEof(); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(label& val) -{ - readFromBuffer(val); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(floatScalar& val) -{ - readFromBuffer(val); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(doubleScalar& val) -{ - readFromBuffer(val); - return *this; -} - - -Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count) -{ - if (format() != BINARY) - { - FatalErrorIn("IPstream::read(char*, std::streamsize)") - << "stream format not binary" - << Foam::abort(FatalError); - } - - readFromBuffer(data, count, 8); - return *this; -} - - -Foam::Istream& Foam::IPstream::rewind() -{ - bufPosition_ = 0; - return *this; -} +: + Pstream(commsType, bufSize), + UIPstream(commsType, fromProcNo, buf_) +{} // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H index db40ccfd4f..acc59de87b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H @@ -38,7 +38,7 @@ SourceFiles #ifndef IPstream_H #define IPstream_H -#include "Istream.H" +#include "UIPstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,26 +52,8 @@ namespace Foam class IPstream : public Pstream, - public Istream + public UIPstream { - // Private data - - int fromProcNo_; - label messageSize_; - - - // Private member functions - - //- Check the bufferPosition_ against messageSize_ for EOF - inline void checkEof(); - - //- Read a T from the transfer buffer - template - inline void readFromBuffer(T&); - - //- Read data from the transfer buffer - inline void readFromBuffer(void* data, size_t count, size_t align); - public: @@ -88,76 +70,6 @@ public: versionNumber version=currentVersion ); - - // Destructor - - ~IPstream(); - - - // Member functions - - // Inquiry - - //- Return flags of output stream - ios_base::fmtflags flags() const - { - return ios_base::fmtflags(0); - } - - - // Read functions - - //- Read into given buffer from given processor and return the - // message size - static label read - ( - const commsTypes commsType, - const int fromProcNo, - char* buf, - const std::streamsize bufSize - ); - - //- Return next token from stream - Istream& read(token&); - - //- Read a character - Istream& read(char&); - - //- Read a word - Istream& read(word&); - - // Read a string (including enclosing double-quotes) - Istream& read(string&); - - //- Read a label - Istream& read(label&); - - //- Read a floatScalar - Istream& read(floatScalar&); - - //- Read a doubleScalar - Istream& read(doubleScalar&); - - //- Read binary block - Istream& read(char*, std::streamsize); - - //- Rewind and return the stream so that it may be read again - Istream& rewind(); - - - // Edit - - //- Set flags of stream - ios_base::fmtflags flags(const ios_base::fmtflags) - { - return ios_base::fmtflags(0); - } - - - // Print - - //- Print description of IOstream to Ostream - void print(Ostream&) const; }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C index ab576d0ef4..86684e8016 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C @@ -22,68 +22,9 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - Write primitive and binary block from OPstream - \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "OPstream.H" -#include "int.H" -#include "token.H" - -#include - -// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * // - -template -inline void Foam::OPstream::writeToBuffer(const T& t) -{ - writeToBuffer(&t, sizeof(T), sizeof(T)); -} - - -inline void Foam::OPstream::writeToBuffer(const char& c) -{ - if (size_t(buf_.size()) < bufPosition_ + 1U) - { - enlargeBuffer(1); - } - - buf_[bufPosition_] = c; - bufPosition_ ++; -} - - -inline void Foam::OPstream::writeToBuffer -( - const void* data, - size_t count, - size_t align -) -{ - label oldPos = bufPosition_; - - if (align > 1) - { - // Align bufPosition. Pads bufPosition_ - oldPos characters. - bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1)); - } - - if (size_t(buf_.size()) < bufPosition_ + count) - { - enlargeBuffer(bufPosition_ - oldPos + count); - } - - register char* bufPtr = &buf_[bufPosition_]; - register const char* dataPtr = reinterpret_cast(data); - register size_t i = count; - while (i--) *bufPtr++ = *dataPtr++; - - bufPosition_ += count; -} - // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // @@ -92,137 +33,14 @@ Foam::OPstream::OPstream const commsTypes commsType, const int toProcNo, const label bufSize, + const label tag, streamFormat format, versionNumber version ) : Pstream(commsType, bufSize), - Ostream(format, version), - toProcNo_(toProcNo) -{ - setOpened(); - setGood(); - - if (!bufSize) - { - buf_.setSize(1000); - } -} - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -Foam::Ostream& Foam::OPstream::write(const token&) -{ - notImplemented("Ostream& OPstream::write(const token&)"); - setBad(); - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const char c) -{ - if (!isspace(c)) - { - writeToBuffer(c); - } - - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const char* str) -{ - word nonWhiteChars(string::validate(str)); - - if (nonWhiteChars.size() == 1) - { - return write(nonWhiteChars.c_str()[1]); - } - else if (nonWhiteChars.size()) - { - return write(nonWhiteChars); - } - else - { - return *this; - } -} - - -Foam::Ostream& Foam::OPstream::write(const word& str) -{ - write(char(token::WORD)); - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); - - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const string& str) -{ - write(char(token::STRING)); - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); - - return *this; -} - - -Foam::Ostream& Foam::OPstream::writeQuoted(const std::string& str, const bool) -{ - write(char(token::STRING)); - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); - - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const label val) -{ - write(char(token::LABEL)); - writeToBuffer(val); - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const floatScalar val) -{ - write(char(token::FLOAT_SCALAR)); - writeToBuffer(val); - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const doubleScalar val) -{ - write(char(token::DOUBLE_SCALAR)); - writeToBuffer(val); - return *this; -} - - -Foam::Ostream& Foam::OPstream::write(const char* data, std::streamsize count) -{ - if (format() != BINARY) - { - FatalErrorIn("Ostream::write(const char*, std::streamsize)") - << "stream format not binary" - << Foam::abort(FatalError); - } - - writeToBuffer(data, count, 8); - - return *this; -} + UOPstream(commsType, toProcNo, buf_, tag, true, format, version) +{} // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H index bccb5b08ef..f8aa3e8987 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H @@ -38,7 +38,7 @@ SourceFiles #ifndef OPstream_H #define OPstream_H -#include "Ostream.H" +#include "UOPstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,25 +52,8 @@ namespace Foam class OPstream : public Pstream, - public Ostream + public UOPstream { - // Private data - - int toProcNo_; - - - // Private member functions - - //- Write a T to the transfer buffer - template - inline void writeToBuffer(const T&); - - //- Write a char to the transfer buffer - inline void writeToBuffer(const char&); - - //- Write data to the transfer buffer - inline void writeToBuffer(const void* data, size_t count, size_t align); - public: @@ -83,126 +66,11 @@ public: const commsTypes commsType, const int toProcNo, const label bufSize = 0, + const label tag = UPstream::msgType(), streamFormat format=BINARY, versionNumber version=currentVersion ); - - // Destructor - - ~OPstream(); - - - // Member functions - - // Inquiry - - //- Return flags of output stream - ios_base::fmtflags flags() const - { - return ios_base::fmtflags(0); - } - - - // Write functions - - //- Write given buffer to given processor - static bool write - ( - const commsTypes commsType, - const int toProcNo, - const char* buf, - const std::streamsize bufSize - ); - - //- Write next token to stream - Ostream& write(const token&); - - //- Write character - Ostream& write(const char); - - //- Write character string - Ostream& write(const char*); - - //- Write word - Ostream& write(const word&); - - //- Write string - Ostream& write(const string&); - - //- Write std::string surrounded by quotes. - // Optional write without quotes. - Ostream& writeQuoted - ( - const std::string&, - const bool quoted=true - ); - - //- Write label - Ostream& write(const label); - - //- Write floatScalar - Ostream& write(const floatScalar); - - //- Write doubleScalar - Ostream& write(const doubleScalar); - - //- Write binary block - Ostream& write(const char*, std::streamsize); - - //- Add indentation characters - void indent() - {} - - - // Stream state functions - - //- Flush stream - void flush() - {} - - //- Add newline and flush stream - void endl() - {} - - //- Get width of output field - int width() const - { - return 0; - } - - //- Set width of output field (and return old width) - int width(const int) - { - return 0; - } - - //- Get precision of output field - int precision() const - { - return 0; - } - - //- Set precision of output field (and return old precision) - int precision(const int) - { - return 0; - } - - - // Edit - - //- Set flags of stream - ios_base::fmtflags flags(const ios_base::fmtflags) - { - return ios_base::fmtflags(0); - } - - - // Print - - //- Print description of IOstream to Ostream - void print(Ostream&) const; }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C index 213ae54c76..5c62c47a99 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.C @@ -25,226 +25,16 @@ License \*---------------------------------------------------------------------------*/ #include "Pstream.H" -#include "debug.H" -#include "dictionary.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(Foam::Pstream, 0); -template<> -const char* Foam::NamedEnum::names[] = -{ - "blocking", - "scheduled", - "nonBlocking" -}; - -const Foam::NamedEnum - Foam::Pstream::commsTypeNames; - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::Pstream::setParRun() -{ - parRun_ = true; - - Pout.prefix() = '[' + name(myProcNo()) + "] "; - Perr.prefix() = '[' + name(myProcNo()) + "] "; -} - - -void Foam::Pstream::calcLinearComm(const label nProcs) -{ - linearCommunication_.setSize(nProcs); - - // Master - labelList belowIDs(nProcs - 1); - forAll(belowIDs, i) - { - belowIDs[i] = i + 1; - } - - linearCommunication_[0] = commsStruct - ( - nProcs, - 0, - -1, - belowIDs, - labelList(0) - ); - - // Slaves. Have no below processors, only communicate up to master - for (label procID = 1; procID < nProcs; procID++) - { - linearCommunication_[procID] = commsStruct - ( - nProcs, - procID, - 0, - labelList(0), - labelList(0) - ); - } -} - - -// Append my children (and my children children etc.) to allReceives. -void Foam::Pstream::collectReceives -( - const label procID, - const List >& receives, - DynamicList