Commit 46f1df81 authored by mattijs's avatar mattijs
Browse files

unallocated Pstream

parent 86af21c8
......@@ -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<label, 2> 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<label, 2> list3(fromSlave);
Serr<< list3 << endl;
......
......@@ -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"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -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)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -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
......
......@@ -114,7 +114,7 @@ void Foam::ParSortableList<Type>::checkAndSend
}
{
OPstream toSlave(destProcI);
OPstream toSlave(Pstream::blocking, destProcI);
toSlave << values << indices;
}
}
......@@ -311,7 +311,7 @@ void Foam::ParSortableList<Type>::sort()
Pout<< "Receiving from " << procI << endl;
}
IPstream fromSlave(procI);
IPstream fromSlave(Pstream::blocking, procI);
fromSlave >> recValues >> recIndices;
......
......@@ -24,291 +24,22 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void Foam::IPstream::checkEof()
{
if (bufPosition_ == messageSize_)
{
setEof();
}
}
template<class T>
inline void Foam::IPstream::readFromBuffer(T& t)
{
const size_t align = sizeof(T);
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
t = reinterpret_cast<T&>(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<char*>(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_)
{}
// ************************************************************************* //
......@@ -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<class T>
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;
};
......
......@@ -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 <cctype>
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
template<class T>
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<const char*>(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);