48inline static void processFlags(Istream& is,
int flagMask)
62inline static label
byteAlign(
const label
pos,
const size_t align)
67 ? (align + ((
pos - 1) & ~(align - 1)))
77 const word& compoundType,
82 return tok.readCompoundToken(compoundType, is);
90inline void Foam::UIPstreamBase::checkEof()
99inline void Foam::UIPstreamBase::prepareBuffer(
const size_t align)
101 recvBufPos_ =
byteAlign(recvBufPos_, align);
106inline void Foam::UIPstreamBase::readFromBuffer(
T& val)
108 prepareBuffer(
sizeof(
T));
110 val =
reinterpret_cast<T&
>(recvBuf_[recvBufPos_]);
111 recvBufPos_ +=
sizeof(
T);
116inline void Foam::UIPstreamBase::readFromBuffer
124 const char*
const __restrict__ buf = &recvBuf_[recvBufPos_];
125 char*
const __restrict__ output =
reinterpret_cast<char*
>(data);
127 for (
size_t i = 0; i <
count; ++i)
133 recvBufPos_ +=
count;
138inline Foam::Istream& Foam::UIPstreamBase::readString(std::string& str)
148 str.assign(&recvBuf_[recvBufPos_], len);
166 const int fromProcNo,
168 label& receiveBufPosition,
170 const int communicator,
171 const bool clearAtEnd,
177 fromProcNo_(fromProcNo),
181 storedRecvBufPos_(0),
182 clearAtEnd_(clearAtEnd),
183 recvBuf_(receiveBuf),
193 const int fromProcNo,
199 fromProcNo_(fromProcNo),
201 comm_(buffers.comm()),
203 storedRecvBufPos_(0),
204 clearAtEnd_(buffers.allowClearRecv()),
205 recvBuf_(buffers.accessRecvBuffer(fromProcNo)),
206 recvBufPos_(buffers.accessRecvPosition(fromProcNo))
215 <<
"PstreamBuffers::finishedSends() never called." << endl
216 <<
"Please call PstreamBuffers::finishedSends() after doing"
217 <<
" all your sends (using UOPstream) and before doing any"
218 <<
" receives (using UIPstream)" << Foam::exit(FatalError);
260 Perr<<
"UIPstreamBase Destructor : tag:" <<
tag_
262 <<
" clearing receive buffer of size "
309 if (
char flagVal;
read(flagVal))
350 if (
word val; readString(val))
376 if (
string val; readString(val))
391 if (int32_t val;
read(val))
405 if (int64_t val;
read(val))
419 if (uint32_t val;
read(val))
433 if (uint64_t val;
read(val))
447 if (
float val;
read(val))
461 if (
double val;
read(val))
501 return readString(str);
507 return readString(str);
560 readRaw(data, count);
574 readFromBuffer(data, count);
584 <<
"stream format not binary"
636 os <<
"Reading from processor " << fromProcNo_
637 <<
" using communicator " << comm_
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary | coherent).
@ ASCII
"ascii" (normal default)
void setBad() noexcept
Set stream state to be 'bad'.
label lineNumber() const noexcept
Const access to the current stream line number.
void setEof() noexcept
Set stream state as reached 'eof'.
bool eof() const noexcept
True if end of input seen.
void setGood() noexcept
Set stream state to be good.
void setOpened() noexcept
Set stream opened.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool getBack(token &tok)
Retrieve the put-back token if there is one.
virtual void rewind()=0
Rewind the stream so that it may be read again.
Istream(const Istream &)=default
Copy construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Buffers for inter-processor communications streams (UOPstream, UIPstream).
bool finished() const noexcept
True if finishedSends() or finishedNeighbourSends() has been called.
label storedRecvBufPos_
Receive position in buffer data, if ony If there is no external location for recvBufPos_.
virtual void rewind() override
Rewind the receive stream position so that it may be read again.
virtual Istream & read(token &) override
Return next token from stream.
const int fromProcNo_
Source rank for the data.
virtual bool endRawRead() override
End of low-level raw binary read.
void print(Ostream &os) const override
Print stream description to Ostream.
label remaining() const noexcept
The number of characters remaining in the get buffer.
const int tag_
Message tag for communication.
const int comm_
The communicator index.
virtual bool beginRawRead() override
Start of low-level raw binary read.
label messageSize_
The message size, read on bufferIPCrecv or set directly.
UIPstreamBase(const UPstream::commsTypes commsType, const int fromProcNo, DynamicList< char > &receiveBuf, label &receiveBufPosition, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, const bool clearAtEnd=false, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct given process index to read from using the given attached receive buffer,...
const bool clearAtEnd_
Clear the receive buffer on termination (in the destructor).
virtual ~UIPstreamBase()
Destructor. Optionally clears external receive buffer.
DynamicList< char > & recvBuf_
Reference to the receive buffer data.
virtual Istream & readRaw(char *data, std::streamsize count) override
Low-level raw binary read. Reading into a null pointer behaves like a forward seek of count character...
label & recvBufPos_
Reference to the receive position in buffer data.
void size(const label n)
Older name for setAddressableSize.
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Inter-processor communications stream.
static constexpr int commSelf() noexcept
Communicator within the current rank only.
commsTypes
Communications types.
@ scheduled
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
@ nonBlocking
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
static int & msgType() noexcept
Message tag of standard messages.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
commsTypes commsType() const noexcept
Get the communications type of the stream.
UPstream(const commsTypes commsType) noexcept
Construct for given communication type.
static bool isCompound(const word &compoundType)
True if a known (registered) compound type.
A token holds an item read from Istream.
tokenType
Enumeration defining the types of token.
@ DOUBLE
double (double-precision) type
@ FLAG
stream flag (1-byte bitmask)
@ UNSIGNED_INTEGER_32
uint32 type
@ CHAR_DATA
String-variant: plain character content.
@ FLOAT
float (single-precision) type
@ UNSIGNED_INTEGER_64
uint64 type
@ STRING
Foam::string (usually double-quoted).
label lineNumber() const noexcept
The line number for the token.
punctuationToken
Standard punctuation tokens (a character).
@ DIVIDE
Divide [isseparator].
@ BEGIN_BLOCK
Begin block [isseparator].
@ BEGIN_SQR
Begin dimensions [isseparator].
@ COLON
Colon [isseparator].
@ END_BLOCK
End block [isseparator].
@ ASSIGN
Assignment/equals [isseparator].
@ END_STATEMENT
End entry [isseparator].
@ BEGIN_LIST
Begin list [isseparator].
@ PLUS
Addition [isseparator].
@ END_LIST
End list [isseparator].
@ END_SQR
End dimensions [isseparator].
@ MULTIPLY
Multiply [isseparator].
@ MINUS
Subtract or start of negative number.
@ COMMA
Comma [isseparator].
void setBad()
Clear token and set to be ERROR.
bool readCompoundToken(const word &compoundType, Istream &is, const bool readContent=true)
Default construct the specified compound type and read from stream.
@ BINARY
BINARY-mode stream.
@ ASCII
ASCII-mode stream.
uint32_t uint32Token() const
Return int32 value, convert from other integer type or Error.
bool isFlag() const noexcept
Token is FLAG.
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
int flagToken() const
Return flag bitmask value.
int64_t int64Token() const
Return int64 value, convert from other integer type or Error.
void reset()
Reset token to UNDEFINED and clear any allocated storage.
int32_t int32Token() const
Return int32 value, convert from other integer type or Error.
uint64_t uint64Token() const
Return int64 value, convert from other integer type or Error.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for handling debugging switches.
dimensionedScalar pos(const dimensionedScalar &ds)
static Foam::word charToWord(char c)
bool read(const char *buf, int32_t &val)
Same as readInt32.
static void processFlags(Istream &is, int flagMask)
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static label byteAlign(const label pos, const size_t align)
errorManip< error > abort(error &err)
static bool readCompoundToken(token &tok, const word &compoundType, Istream &is)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
word format(conversionProperties.get< word >("format"))