50 return (objectType == decomposedBlockData::typeName);
72 commsType_(commsType),
79 <<
"decomposedBlockData " <<
name()
80 <<
" constructed with READ_MODIFIED"
81 " but decomposedBlockData does not support automatic rereading."
105 std::streamoff blockOffset =
os.stdStream().tellp();
107 const word procName(
"processor" +
Foam::name(blocki));
110 constexpr bool isDictFormat =
false;
112 if constexpr (isDictFormat)
115 os <<
nl << procName <<
nl;
120 os <<
nl <<
"// " << procName <<
nl;
129 os << label(len) <<
nl;
137 os << label(0) <<
nl;
140 if constexpr (isDictFormat)
168 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
170 if (!isDictFormat && tok.good())
174 charData.readList(is);
204 if (!is.good())
return false;
206 if (!is.good())
return false;
210 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
215 if (!is.good())
return false;
219 bool handled =
false;
222 if (tok.isCompound())
226 else if (tok.isLabel())
230 const label len = tok.labelToken();
240 is.read(
nullptr, std::streamsize(len));
272 const label maxNumBlocks
282 if (is.good() && tok.isWord(
"FoamFile"))
286 if (headerDict.readIfPresent(
"version", tok))
292 if (headerDict.readIfPresent(
"format", formatName))
294 is.format(formatName);
310 while (is.good() && skipBlockEntry(is))
314 if (maxNumBlocks == nBlocks)
340 const bool withLocalHeader
356 ok =
io.writeHeader(buf);
362 ok = ok &&
io.writeData(buf);
366 return std::streamoff(-1);
387 Pout<<
"decomposedBlockData::readBlock:"
388 <<
" stream:" << is.
name() <<
" attempt to read block " << blocki
397 unsigned labelWidth = is.labelByteSize();
398 unsigned scalarWidth = is.scalarByteSize();
406 blockIsPtr.reset(
new ICharStream(std::move(data)));
407 blockIsPtr->name() = is.name();
412 if (!headerIO.readHeader(*blockIsPtr))
415 <<
"Problem while reading object header "
416 << is.relativeName() <<
nl
427 if (!headerIO.readHeader(headerStream))
430 <<
"Problem while reading object header "
431 << is.relativeName() <<
nl
435 labelWidth = headerStream.labelByteSize();
436 scalarWidth = headerStream.scalarByteSize();
440 for (label i = 1; i < blocki; ++i)
448 blockIsPtr.reset(
new ICharStream(std::move(data)));
449 blockIsPtr->name() = is.name();
453 auto& iss = blockIsPtr();
454 iss.format(streamOptData.format());
455 iss.version(streamOptData.version());
456 iss.setLabelByteSize(labelWidth);
457 iss.setScalarByteSize(scalarWidth);
475 Pout<<
"decomposedBlockData::readBlocks:"
476 <<
" stream:" << (isPtr ? isPtr->name() :
"<null>")
477 <<
" non-blocking comm:" << comm <<
endl;
503 auto& slot = procBuffers[proci];
526 const auto [fromProci, numBytes] =
535 slot.resize_nocopy(numBytes);
539 Pout<<
"probed to receive " << label(numBytes) <<
" from "
540 << fromProci <<
endl;
576 Pout<<
"decomposedBlockData::readBlocks:"
577 <<
" stream:" << (isPtr ? isPtr->name() :
"<null>")
578 <<
" non-blocking" <<
endl;
583 List<char> localData;
584 List<List<char>> procBuffers;
585 autoPtr<ISstream> blockIsPtr;
601 blockIsPtr.reset(
new ICharStream(std::move(localData)));
602 blockIsPtr->name() = fName;
610 <<
"Problem while reading object header "
611 << is.relativeName() <<
nl
620 auto& slot = procBuffers[proci];
643 const auto [fromProci, numBytes] =
652 slot.resize_nocopy(numBytes);
656 Pout<<
"probed to receive " << label(numBytes) <<
" from "
657 << fromProci <<
endl;
678 blockIsPtr.reset(
new ICharStream(std::move(localData)));
679 blockIsPtr->name() = fName;
687 unsigned labelWidth(0);
688 unsigned scalarWidth(0);
702 auto& iss = blockIsPtr();
703 verValue = iss.version().canonical();
704 fmtValue =
static_cast<int>(iss.format());
705 labelWidth = iss.labelByteSize();
706 scalarWidth = iss.scalarByteSize();
725 auto& iss = *blockIsPtr;
728 iss.setLabelByteSize(labelWidth);
729 iss.setScalarByteSize(scalarWidth);
732 headerIO.
rename(headerName);
746 const UList<char>& localData,
749 const labelRange& whichProcs,
751 List<int>& sliceOffsets,
752 DynamicList<char>& recvData,
767 List<int> sliceSizes;
770 sliceSizes.resize_nocopy(nProcs);
772 sliceOffsets.resize_nocopy(nProcs+1);
776 for (
const label proci : whichProcs)
778 const auto nRecvBytes =
static_cast<int>(recvSizes[proci]);
780 sliceOffsets[proci] = totalSize;
781 totalSize += nRecvBytes;
783 sliceSizes[proci] = nRecvBytes;
787 const label endProci = whichProcs.end_value();
789 sliceOffsets[endProci] = totalSize;
790 recvData.resize_nocopy(totalSize);
792 else if (whichProcs.contains(myRank) && !localData.empty())
795 nSendBytes =
static_cast<int>(localData.size_bytes());
802 for (
const label proci : whichProcs)
807 sliceOffsets[proci+1]-sliceOffsets[proci],
811 if (procSlice.empty())
822 localData.cbegin(procSlice.size()),
833 procSlice.data_bytes(),
834 procSlice.size_bytes(),
841 else if (whichProcs.contains(myRank) && !localData.empty())
848 localData.cdata_bytes(),
849 localData.size_bytes(),
878 autoPtr<OSstream>& osPtr,
879 List<std::streamoff>& blockOffset,
880 const UList<char>& localData,
883 const UList<std::string_view>& procData,
886 const bool syncReturnState
896 blockOffset.resize(nProcs);
900 label maxNonLocalSize = 0;
903 for (label proci = 1; proci < nProcs; ++proci)
905 maxNonLocalSize =
Foam::max(maxNonLocalSize, recvSizes[proci]);
911 Pout<<
" stream:" << (osPtr ? osPtr->name() :
"<null>")
912 <<
" data:" << localData.size()
913 <<
" proc-data:" << procData.size()
914 <<
" max-size:" << maxNonLocalSize
928 std::streamoff currOffset =
942 for (label proci = 1; proci < nProcs; ++proci)
952 if (blockOffset.size() > proci)
954 blockOffset[proci] = currOffset;
975 std::streamoff currOffset =
992 for (label proci = 1; proci < nProcs; ++proci)
994 recvData.resize_nocopy(recvSizes[proci]);
996 if (!recvData.empty())
1002 recvData.data_bytes(),
1003 recvData.size_bytes(),
1017 if (blockOffset.size() > proci)
1019 blockOffset[proci] = currOffset;
1031 localData.cdata_bytes(),
1032 localData.size_bytes(),
1050 labelList procOffsets(nProcs, Foam::zero{});
1053 label maxRecvCount = 0;
1063 maxMasterFileBufferSize
1067 if (maxBufferSize < off_t(maxNonLocalSize))
1069 maxBufferSize = off_t(maxNonLocalSize);
1073 off_t maxCollected = 0;
1075 for (label proci = 1, nChunks = 0; proci < nProcs; )
1077 procOffsets[nChunks] = proci;
1088 && (!total || (total + recvSizes[proci] < maxBufferSize))
1093 total += recvSizes[proci];
1095 if (maxCollected < total)
1097 maxCollected = total;
1101 procOffsets[++nChunks] = proci;
1104 maxRecvCount =
static_cast<label
>(maxCollected);
1111 for (label nChunks = 1; nChunks < nProcs; ++nChunks)
1115 procOffsets[nChunks-1],
1116 procOffsets[nChunks]-procOffsets[nChunks-1]
1119 if (whichProcs.start() >= nProcs || whichProcs.size() <= 0)
1124 ranges <<
' ' << whichProcs.min() <<
'-' << whichProcs.max();
1127 Pout<<
" write-schedule:" << ranges.str().c_str() <<
endl;
1134 recvData.resize_nocopy(label(maxRecvCount));
1140 std::streamoff currOffset =
1154 for (label nChunks = 1; nChunks < nProcs; ++nChunks)
1158 procOffsets[nChunks-1],
1159 procOffsets[nChunks]-procOffsets[nChunks-1]
1162 if (whichProcs.start() >= nProcs || whichProcs.size() <= 0)
1192 label currRequest = startOfRequests;
1193 for (
const label proci : whichProcs)
1198 recvOffsets[proci+1]-recvOffsets[proci],
1206 && !procSlice.empty()
1213 std::streamoff currOffset =
1221 if (blockOffset.size() > proci)
1223 blockOffset[proci] = currOffset;
1234 if (syncReturnState)
1274 io.readHeader(headerStream);
1276 verValue = headerStream.version().canonical();
1277 fmtValue =
static_cast<int>(headerStream.format());
1287 io.headerClassName(),
1303 io.headerClassName(),
1315 os.
writeRaw(contentData_.cdata(), contentData_.size_bytes());
1320 os.
writeQuoted(contentData_.cdata(), contentData_.size_bytes(),
false);
1335 const bool writeOnProc
1356 static_cast<const IOobject&
>(*
this)
1365 List<std::streamoff> blockOffsets;
1373 UList<std::string_view>(),
Input/output streams with (internal or external) character storage.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void resize_nocopy(const label len)
Alter addressable list size, allocating new space if required without necessarily recovering old cont...
An ISstream with internal List storage. Always UNCOMPRESSED.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
readOption readOpt() const noexcept
Get the read option.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
const word & headerClassName() const noexcept
Return name of the class name read from header.
bool readHeader(Istream &is)
Read header ('FoamFile' dictionary) and set the IOobject and stream characteristics.
static bool bannerEnabled() noexcept
Status of output file banner.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
const fileName & instance() const noexcept
Read access to instance path component.
virtual void rename(const word &newName)
Rename the object.
const string & note() const noexcept
Return the optional note.
fileName objectPath() const
The complete path + object name.
int canonical() const noexcept
From version to canonical integer value.
A simple container for options an IOstream can normally have.
versionNumber version() const noexcept
Get the stream version.
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary | coherent).
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
bool good() const noexcept
True if next operation might succeed.
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
fileName relativeName() const
Return the name of the stream relative to the current case.
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Generic input stream using a standard (STL) stream.
virtual const fileName & name() const override
The name of the input serial stream. (eg, the name of the Fstream file name).
IntType max() const noexcept
The (inclusive) upper value of the range, same as rbegin_value(). Ill-defined for an empty range.
IntType start() const noexcept
The (inclusive) lower value of the range.
IntType size() const noexcept
The size of the range.
bool contains(IntType value) const noexcept
True if the (global) value is within the range.
IntType min() const noexcept
The (inclusive) lower value of the range, same as start(), begin_value().
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
virtual Istream & read(token &)=0
Return next token from stream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
void resize(const label len)
Adjust allocated size of list.
void clear()
Clear the list, i.e. set size to zero.
Istream & readList(Istream &is)
Read List from Istream, discarding contents of existing List.
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
virtual Ostream & write(const char c) override
Write character.
An OSstream with internal List storage.
DynamicList< char > release()
Reset buffer and return contents.
void reserve(std::streamsize n)
Reserve output space for at least this amount.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Generic output stream using a standard (STL) stream.
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name).
virtual Ostream & writeRaw(const char *data, std::streamsize count) override
Low-level raw binary output.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Foam::string str() const
Get the string. As Foam::string instead of std::string (may change in future).
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static void broadcasts(const int communicator, Type &value, Args &&... values)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel.
A non-owning sub-view of a List (allocated or unallocated storage).
static std::streamsize read(const UPstream::commsTypes commsType, const int fromProcNo, Type *buffer, std::streamsize count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, UPstream::Request *req=nullptr)
Receive buffer contents (contiguous types) from given processor.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
T * data() noexcept
Return pointer to the underlying array serving as data storage.
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
void size(const label n)
Older name for setAddressableSize.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const Type *buffer, std::streamsize count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents (contiguous types only) to given processor.
static std::pair< int, int64_t > probeMessage(const UPstream::commsTypes commsType, const int fromProcNo, const int tag=UPstream::msgType(), const int communicator=worldComm)
Probe for an incoming message.
static void mpiGatherv(const Type *sendData, int sendCount, Type *recvData, const UList< int > &recvCounts, const UList< int > &recvOffsets, const int communicator=UPstream::worldComm)
Receive variable length data from all ranks.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests).
commsTypes
Communications types.
@ scheduled
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
@ nonBlocking
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
static int & msgType() noexcept
Message tag of standard messages.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm)
Gather individual values into list locations.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static bool is_subrank(const label communicator=worldComm)
True if process corresponds to a sub-rank in the given communicator.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
static void waitRequests()
Wait for all requests to finish.
@ broadcast
broadcast [MPI]
static void waitRequest(const label i)
Wait until request i has finished. Corresponds to MPI_Wait().
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
The decomposedBlockData comprise a List<char> for each output processor, typically with IO on the mas...
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
static bool readBlockEntry(Istream &is, List< char > &charData)
Helper: read block of (binary) character data.
static bool hasBlock(Istream &is, const label blockNumber)
True if the given block number (starts at 0) has a corresponding decomposedBlockData block entry....
static void gatherProcData(const label comm, const UList< char > &localData, const labelUList &recvSizes, const labelRange &whichProcs, List< int > &recvOffsets, DynamicList< char > &recvData, const UPstream::commsTypes commsType)
Helper: gather data from (subset of) sub-ranks.
virtual bool writeData(Ostream &os) const
Write separated content (assumes content is the serialised data).
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
const label comm_
Communicator for all parallel comms.
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 bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &blockOffset, const UList< char > &localData, const labelUList &recvSizes, const UList< std::string_view > &procData, const UPstream::commsTypes commsType, const bool syncReturnState=true)
Write *this. Ostream only valid on master.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const char *str, const size_t len)
Helper: write block of (binary) character data.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
List< char > contentData_
The block content.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &localData, const UPstream::commsTypes commsType)
Read data (on master) and transmit.
static bool skipBlockEntry(Istream &is)
Helper: skip a block of (binary) character data.
static label getNumBlocks(Istream &is, const label maxNumBlocks=-1)
Extract number of decomposedBlockData block entries, optionally with an upper limit....
virtual bool read()
Read object.
const UPstream::commsTypes commsType_
Type to use for gather.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
A class for handling file names.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
A range or interval of labels defined by a start and a size.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
virtual fileName filePath() const
Return complete path + object name if the file exists.
virtual void updateMetaData()
Update internal meta-data (eg, prior to writing).
bool headerOk()
Read and check header info. Does not check the headerClassName.
A token holds an item read from Istream.
@ END_STATEMENT
End entry [isseparator].
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
label labelToken() const
Return integer type as label value or Error.
bool isCompound() const noexcept
Token is COMPOUND.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
A class for handling words, derived from Foam::string.
static const word null
An empty word.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
constexpr char nl
The newline '\n' character (0x0a).