55 const word& objectType
60 objectType == decomposedBlockData::typeName
84 commsType_(commsType),
92 <<
"decomposedBlockData " <<
name()
93 <<
" constructed with IOobject::MUST_READ_IF_MODIFIED" 94 " but decomposedBlockData does not support automatic rereading." 124 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
126 if (!isDictFormat && tok.good())
130 charData.readList(is);
160 if (!is.good())
return false;
162 if (!is.good())
return false;
165 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
170 if (!is.good())
return false;
174 bool handled =
false;
177 if (tok.isCompound())
181 else if (tok.isLabel())
185 const label len = tok.labelToken();
196 is.read(
nullptr, std::streamsize(len));
229 const bool readHeader
238 if (is.good() && tok.isWord(
"FoamFile"))
240 dictionary headerDict(is);
242 if (headerDict.readIfPresent(
"version", tok))
246 is.format(headerDict.get<word>(
"format"));
259 while (is.good() && skipBlockEntry(is))
272 const UList<char>& charData
277 std::streamoff blockOffset =
os.
stdStream().tellp();
279 const word procName(
"processor" +
Foam::name(blocki));
283 os <<
nl <<
"// " << procName <<
nl;
284 charData.writeList(
os) <<
nl;
301 const std::string& content
306 const_cast<char*>(content.data()),
307 label(content.size())
320 const bool withLocalHeader
341 ok = ok &&
io.writeData(buf);
345 return std::streamoff(-1);
348 contentChars = buf.str();
365 Pout<<
"decomposedBlockData::readBlock:" 366 <<
" stream:" << is.
name() <<
" attempt to read block " << blocki
371 IOstreamOption streamOptData;
375 autoPtr<ISstream> realIsPtr;
383 realIsPtr.reset(
new IListStream(std::move(data)));
384 realIsPtr->name() = is.
name();
392 <<
"Problem while reading object header " 402 UIListStream headerStream(data);
406 <<
"Problem while reading object header " 410 streamOptData =
static_cast<IOstreamOption
>(headerStream);
411 labelWidth = headerStream.labelByteSize();
412 scalarWidth = headerStream.scalarByteSize();
415 for (label i = 1; i < blocki+1; i++)
420 realIsPtr.reset(
new IListStream(std::move(data)));
421 realIsPtr->name() = is.
name();
424 realIsPtr().format(streamOptData.format());
425 realIsPtr().version(streamOptData.version());
426 realIsPtr().setLabelByteSize(labelWidth);
427 realIsPtr().setScalarByteSize(scalarWidth);
437 autoPtr<ISstream>& isPtr,
444 Pout<<
"decomposedBlockData::readBlocks:" 445 <<
" stream:" << (isPtr ? isPtr->name() :
"invalid")
447 <<
" comm:" << comm <<
endl;
517 UOPstream
os(proci, pBufs);
522 pBufs.finishedScatters();
548 Pout<<
"decomposedBlockData::readBlocks:" 549 <<
" stream:" << (isPtr ? isPtr->
name() :
"invalid")
555 autoPtr<ISstream> realIsPtr;
565 realIsPtr.reset(
new IListStream(std::move(data)));
566 realIsPtr->name() = fName;
574 <<
"Problem while reading object header " 619 realIsPtr.reset(
new IListStream(std::move(data)));
620 realIsPtr->
name() = fName;
639 UOPstream
os(proci, pBufs);
646 pBufs.finishedScatters();
653 realIsPtr.reset(
new IListStream(std::move(data)));
654 realIsPtr->
name() = fName;
666 unsigned scalarWidth;
667 word headerName(headerIO.
name());
671 verValue = realIsPtr().version().canonical();
672 fmtValue =
static_cast<int>(realIsPtr().format());
673 labelWidth = realIsPtr().labelByteSize();
674 scalarWidth = realIsPtr().scalarByteSize();
693 realIsPtr().setLabelByteSize(labelWidth);
694 realIsPtr().setScalarByteSize(scalarWidth);
719 forAll(recvOffsets, proci)
724 int(reinterpret_cast<char*>(&datas[proci]) - data0Ptr);
726 recvSizes.
setSize(nProcs,
sizeof(label));
731 reinterpret_cast<const char*>(&data),
763 sliceSizes.
resize(numProcs, 0);
764 sliceOffsets.
resize(numProcs+1, 0);
767 const label endProci = fromProcs.
end_value();
770 for (
const label proci : fromProcs)
772 sliceSizes[proci] = int(recvSizes[proci]);
773 sliceOffsets[proci] = totalSize;
774 totalSize += sliceSizes[proci];
777 sliceOffsets[endProci] = totalSize;
778 recvData.
resize(totalSize);
780 else if (fromProcs.contains(myProci))
802 const off_t maxBufferSize,
804 const label startProci
809 label nSendProcs = 0;
812 off_t totalSize = recvSizes[startProci];
813 label proci = startProci+1;
814 while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
816 totalSize += recvSizes[proci];
820 nSendProcs = proci-startProci;
840 const bool syncReturnState
845 Pout<<
"decomposedBlockData::writeBlocks:" 846 <<
" stream:" << (osPtr ? osPtr->
name() :
"none")
847 <<
" data:" << masterData.
size()
848 <<
" (master only) slaveData:" << slaveData.size()
859 blockOffset.
resize(nProcs);
861 OSstream&
os = osPtr();
874 if (slaveData.size())
881 OSstream&
os = osPtr();
884 for (label proci = 1; proci < nProcs; ++proci)
903 OSstream&
os = osPtr();
906 label maxNonLocalSize = 0;
907 for (label proci = 1; proci < nProcs; ++proci)
909 maxNonLocalSize =
max(maxNonLocalSize, recvSizes[proci]);
912 DynamicList<char> elems(maxNonLocalSize);
913 for (label proci = 1; proci < nProcs; ++proci)
915 elems.resize_nocopy(recvSizes[proci]);
959 label nSendProcs = nProcs-1;
961 DynamicList<char> recvData;
963 while (nSendProcs > 0 && startProc < nProcs)
965 nSendProcs = calcNumProcs
970 fileOperations::masterUncollatedFileOperation::
971 maxMasterFileBufferSize
984 labelRange fromProcs(startProc, nSendProcs);
986 List<int> sliceOffsets;
1001 OSstream&
os = osPtr();
1004 for (
const label proci : fromProcs)
1006 SubList<char> dataSlice
1009 sliceOffsets[proci+1]-sliceOffsets[proci],
1013 blockOffset[proci] =
1023 startProc += nSendProcs;
1032 if (syncReturnState)
1053 return readBlocks(comm_, isPtr, contentData_, commsType_);
1073 verValue = headerStream.version().canonical();
1074 fmtValue =
static_cast<int>(headerStream.format());
1109 if (isA<OFstream>(
os))
1112 os.
writeRaw(contentData_.cdata(), contentData_.size_bytes());
1117 std::string str(contentData_.cdata(), contentData_.size_bytes());
1133 const bool writeOnProc
1154 static_cast<const IOobject&>(*
this)
1159 gather(comm_, label(contentData_.size_bytes()), recvSizes);
1161 List<std::streamoff> blockOffsets;
1162 PtrList<SubList<char>> slaveData;
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
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.
virtual bool read()
Read object.
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 label 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.
virtual const fileName & name() const
The name of the input serial stream. (eg, the name of the Fstream file name)
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.
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.
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, using an OSstream.
A range or interval of labels defined by a start and a size.
constexpr char nl
The newline '\n' character (0x0a)
virtual void rename(const word &newName)
Rename the object.
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.
virtual std::ostream & stdStream()
Access to underlying std::ostream.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
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 bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
bool writeHeader(Ostream &os) const
Write header with current type()
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
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 label getNumBlocks(Istream &is, const bool readHeader)
Extract number of blocks from decomposedBlockData file stream.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
#define forAll(list, i)
Loop across all elements in list.
void gather(const Type *sendData, Type *recvData, int count, MPI_Datatype datatype, const label comm, UPstream::Request *req=nullptr, label *requestID=nullptr)
int canonical() const noexcept
From version to canonical integer value.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
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 INVALID.
"scheduled" : (MPI_Send, MPI_Recv)
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.
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 std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Helper: write block of (binary) character data.
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...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
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)
Database for solution data, solver performance and other reduced data.
Input from file stream, using an ISstream.
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 processes in communicator.
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...
"nonBlocking" : (MPI_Isend, MPI_Irecv)
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.
Input/output streams with managed List storage.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
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.
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 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 ...