55 const word& objectType
60 objectType == decomposedBlockData::typeName
84 commsType_(commsType),
92 <<
"decomposedBlockData " <<
name()
93 <<
" constructed with READ_MODIFIED" 94 " but decomposedBlockData does not support automatic rereading." 118 std::streamoff blockOffset =
os.
stdStream().tellp();
120 const word procName(
"processor" +
Foam::name(blocki));
129 os <<
nl <<
"// " << procName <<
nl;
136 os << label(len) <<
nl;
144 os << label(0) <<
nl;
196 if (!isDictFormat && tok.
good())
230 if (!is.good())
return false;
232 if (!is.good())
return false;
235 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
240 if (!is.good())
return false;
244 bool handled =
false;
247 if (tok.isCompound())
251 else if (tok.isLabel())
255 const label len = tok.labelToken();
265 is.read(
nullptr, std::streamsize(len));
297 const label maxNumBlocks
307 if (is.good() && tok.isWord(
"FoamFile"))
311 if (headerDict.readIfPresent(
"version", tok))
317 if (headerDict.readIfPresent(
"format", formatName))
319 is.format(formatName);
335 while (is.good() && skipBlockEntry(is))
339 if (maxNumBlocks == nBlocks)
354 && (blockNumber < getNumBlocks(is, blockNumber+1))
365 const bool withLocalHeader
386 ok = ok &&
io.writeData(buf);
390 return std::streamoff(-1);
393 contentChars = buf.
str();
410 Pout<<
"decomposedBlockData::readBlock:" 411 <<
" stream:" << is.
name() <<
" attempt to read block " << blocki
416 IOstreamOption streamOptData;
420 autoPtr<ISstream> realIsPtr;
428 realIsPtr.reset(
new ICharStream(std::move(data)));
429 realIsPtr->name() = is.
name();
437 <<
"Problem while reading object header " 447 ISpanStream headerStream(data);
451 <<
"Problem while reading object header " 455 streamOptData =
static_cast<IOstreamOption
>(headerStream);
456 labelWidth = headerStream.labelByteSize();
457 scalarWidth = headerStream.scalarByteSize();
460 for (label i = 1; i < blocki+1; i++)
465 realIsPtr.reset(
new ICharStream(std::move(data)));
466 realIsPtr->name() = is.
name();
469 realIsPtr().format(streamOptData.format());
470 realIsPtr().version(streamOptData.version());
471 realIsPtr().setLabelByteSize(labelWidth);
472 realIsPtr().setScalarByteSize(scalarWidth);
482 autoPtr<ISstream>& isPtr,
489 Pout<<
"decomposedBlockData::readBlocks:" 490 <<
" stream:" << (isPtr ? isPtr->name() :
"invalid")
492 <<
" comm:" << comm <<
endl;
548 PstreamBuffers pBufs(comm);
562 UOPstream
os(proci, pBufs);
567 pBufs.finishedScatters();
593 Pout<<
"decomposedBlockData::readBlocks:" 594 <<
" stream:" << (isPtr ? isPtr->
name() :
"invalid")
600 autoPtr<ISstream> realIsPtr;
610 realIsPtr.reset(
new ICharStream(std::move(data)));
611 realIsPtr->name() = fName;
619 <<
"Problem while reading object header " 664 realIsPtr.reset(
new ICharStream(std::move(data)));
665 realIsPtr->
name() = fName;
670 PstreamBuffers pBufs(comm);
684 UOPstream
os(proci, pBufs);
691 pBufs.finishedScatters();
698 realIsPtr.reset(
new ICharStream(std::move(data)));
699 realIsPtr->
name() = fName;
711 unsigned scalarWidth;
712 word headerName(headerIO.
name());
716 verValue = realIsPtr().version().canonical();
717 fmtValue =
static_cast<int>(realIsPtr().format());
718 labelWidth = realIsPtr().labelByteSize();
719 scalarWidth = realIsPtr().scalarByteSize();
738 realIsPtr().setLabelByteSize(labelWidth);
739 realIsPtr().setScalarByteSize(scalarWidth);
764 forAll(recvOffsets, proci)
769 int(reinterpret_cast<char*>(&datas[proci]) - data0Ptr);
771 recvSizes.
setSize(nProcs,
sizeof(label));
776 reinterpret_cast<const char*>(&data),
808 sliceSizes.
resize(numProcs, 0);
809 sliceOffsets.
resize(numProcs+1, 0);
812 const label endProci = fromProcs.
end_value();
815 for (
const label proci : fromProcs)
817 sliceSizes[proci] = int(recvSizes[proci]);
818 sliceOffsets[proci] = totalSize;
819 totalSize += sliceSizes[proci];
822 sliceOffsets[endProci] = totalSize;
823 recvData.
resize(totalSize);
825 else if (fromProcs.contains(myProci))
847 const off_t maxBufferSize,
849 const label startProci
854 label nSendProcs = 0;
857 off_t totalSize = recvSizes[startProci];
858 label proci = startProci+1;
859 while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
861 totalSize += recvSizes[proci];
865 nSendProcs = proci-startProci;
885 const bool syncReturnState
890 Pout<<
"decomposedBlockData::writeBlocks:" 891 <<
" stream:" << (osPtr ? osPtr->
name() :
"none")
892 <<
" data:" << masterData.
size()
893 <<
" (master only) slaveData:" << slaveData.size()
904 blockOffset.
resize(nProcs);
906 OSstream&
os = osPtr();
919 if (slaveData.size())
926 OSstream&
os = osPtr();
929 for (label proci = 1; proci < nProcs; ++proci)
948 OSstream&
os = osPtr();
951 label maxNonLocalSize = 0;
952 for (label proci = 1; proci < nProcs; ++proci)
954 maxNonLocalSize =
max(maxNonLocalSize, recvSizes[proci]);
957 DynamicList<char> elems(maxNonLocalSize);
958 for (label proci = 1; proci < nProcs; ++proci)
960 elems.resize_nocopy(recvSizes[proci]);
1003 label startProc = 1;
1004 label nSendProcs = nProcs-1;
1006 DynamicList<char> recvData;
1008 while (nSendProcs > 0 && startProc < nProcs)
1010 nSendProcs = calcNumProcs
1015 fileOperations::masterUncollatedFileOperation::
1016 maxMasterFileBufferSize
1022 if (nSendProcs == 0)
1029 labelRange fromProcs(startProc, nSendProcs);
1031 List<int> sliceOffsets;
1046 OSstream&
os = osPtr();
1049 for (
const label proci : fromProcs)
1051 SubList<char> dataSlice
1054 sliceOffsets[proci+1]-sliceOffsets[proci],
1058 blockOffset[proci] =
1068 startProc += nSendProcs;
1077 if (syncReturnState)
1098 return readBlocks(comm_, isPtr, contentData_, commsType_);
1118 verValue = headerStream.version().canonical();
1119 fmtValue =
static_cast<int>(headerStream.format());
1154 if (isA<OFstream>(
os))
1157 os.
writeRaw(contentData_.cdata(), contentData_.size_bytes());
1162 std::string str(contentData_.cdata(), contentData_.size_bytes());
1178 const bool writeOnProc
1199 static_cast<const IOobject&>(*
this)
1204 gather(comm_, label(contentData_.size_bytes()), recvSizes);
1206 List<std::streamoff> blockOffsets;
1207 PtrList<SubList<char>> slaveData;
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Generic output stream using a standard (STL) stream.
void size(const label n)
Older name for setAddressableSize.
fileName relativeName() const
Return the name of the stream relative to the current case.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
virtual bool read()
Read object.
Input/output streams with (internal or external) character storage.
A class for handling file names.
readOption readOpt() const noexcept
Get the read option.
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
static void gatherSlaveData(const label comm, const UList< char > &data, const labelUList &recvSizes, const labelRange &fromProcs, List< int > &recvOffsets, DynamicList< char > &recvData)
Helper: gather data from (subset of) slaves.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &blockOffset, const UList< char > &masterData, const labelUList &recvSizes, const UPtrList< SubList< char >> &slaveData, const UPstream::commsTypes commsType, const bool syncReturnState=true)
Write *this. Ostream only valid on master.
virtual Ostream & write(const char c) override
Write character.
void resize(const label len)
Adjust allocated size of list.
commsTypes
Communications types.
Input/output from string buffers.
const word & name() const noexcept
Return the object name.
bool isCompound() const noexcept
Token is COMPOUND.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
A range or interval of labels defined by a start and a size.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
virtual void rename(const word &newName)
Rename the object.
A token holds an item read from Istream.
T * data() noexcept
Return pointer to the underlying array serving as data storage.
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content...
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool headerOk()
Read and check header info. Does not check the headerClassName.
const string & note() const noexcept
Return the optional note.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &contentChars, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
static int & msgType() noexcept
Message tag of standard messages.
A simple container for options an IOstream can normally have.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
virtual Ostream & writeRaw(const char *data, std::streamsize count) override
Low-level raw binary output.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
bool writeHeader(Ostream &os) const
Write header with current type()
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
IntType end_value() const noexcept
The value 1 beyond the end of the range.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
void gather(const Type *sendData, Type *recvData, int count, MPI_Datatype datatype, const label comm, UPstream::Request *req=nullptr, label *requestID=nullptr)
#define forAll(list, i)
Loop across all elements in list.
Foam::string str() const
Get the string. As Foam::string instead of std::string (may change in future)
int canonical() const noexcept
From version to canonical integer value.
virtual const std::ostream & stdStream() const override
Const access to underlying std::ostream.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const char *str, const size_t len)
Helper: write block of (binary) character data.
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
A List obtained as a section of another List.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
void setSize(const label n)
Alias for resize()
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
static bool hasBlock(Istream &is, const label blockNumber)
True if the given block number (starts at 0) has a corresponding decomposedBlockData block entry...
A class for handling words, derived from Foam::string.
static bool readBlockEntry(Istream &is, List< char > &charData)
Helper: read block of (binary) character data.
static void gather(const char *sendData, int sendCount, char *recvData, const UList< int > &recvCounts, const UList< int > &recvOffsets, const label communicator=worldComm)
Receive variable length char data from all ranks.
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
The decomposedBlockData comprise a List<char> for each output processor, typically with IO on the mas...
static const word null
An empty word.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
virtual const fileName & name() const override
The name of the input serial stream. (eg, the name of the Fstream file name)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
Istream & readList(Istream &is)
Read List from Istream, discarding contents of existing List.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
static bool bannerEnabled() noexcept
Status of output file banner.
static void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel. ...
static label getNumBlocks(Istream &is, const label maxNumBlocks=-1)
Extract number of decomposedBlockData block entries, optionally with an upper limit. The input stream should be in a rewound state (or only have read the header) before calling.
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits into maxBufferSize.
const word & headerClassName() const noexcept
Return name of the class name read from header.
Generic input stream using a standard (STL) stream.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
bool good() const noexcept
True if next operation might succeed.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
versionNumber version() const noexcept
Get the stream version.
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents to given processor.
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
List< label > labelList
A List of labels.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
bool readHeader(Istream &is)
Read header ('FoamFile' dictionary) and set the IOobject and stream characteristics.
Defines the attributes of an object for which implicit objectRegistry management is supported...
virtual bool writeData(Ostream &os) const
Write separated content (assumes content is the serialised data)
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
streamFormat format() const noexcept
Get the current stream format.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
static bool skipBlockEntry(Istream &is)
Helper: skip a block of (binary) character data.
static void writeHeader(Ostream &os, IOstreamOption streamOptContainer, const word &objectType, const string ¬e, const fileName &location, const word &objectName, const dictionary &extraEntries)
Helper: write FoamFile IOobject header.
static std::streamsize read(const UPstream::commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr)
Read buffer contents from given processor.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...