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." 123 const bool isDictFormat = (tok.isWord() && !tok.isCompound());
125 if (!isDictFormat && tok.good())
129 charData.readList(is);
152 const UList<char>& charData
157 std::streamoff blockOffset =
os.
stdStream().tellp();
159 const word procName(
"processor" +
Foam::name(blocki));
162 os <<
nl <<
"// " << procName <<
nl;
163 charData.writeList(
os) <<
nl;
173 IOstreamOption streamOptData,
174 const regIOobject&
io,
176 const bool withLocalHeader
182 OStringStream
os(streamOptData);
197 ok = ok &&
io.writeData(
os);
201 return std::streamoff(-1);
204 contentChars =
os.str();
210 const_cast<char*>(contentChars.data()),
211 label(contentChars.size())
228 Pout<<
"decomposedBlockData::readBlock:" 229 <<
" stream:" << is.
name() <<
" attempt to read block " << blocki
234 IOstreamOption streamOptData;
238 autoPtr<ISstream> realIsPtr;
246 realIsPtr.reset(
new IListStream(std::move(data)));
247 realIsPtr->name() = is.
name();
255 <<
"Problem while reading object header " 265 UIListStream headerStream(data);
269 <<
"Problem while reading object header " 273 streamOptData =
static_cast<IOstreamOption
>(headerStream);
274 labelWidth = headerStream.labelByteSize();
275 scalarWidth = headerStream.scalarByteSize();
278 for (label i = 1; i < blocki+1; i++)
283 realIsPtr.reset(
new IListStream(std::move(data)));
284 realIsPtr->name() = is.
name();
287 realIsPtr().format(streamOptData.format());
288 realIsPtr().version(streamOptData.version());
289 realIsPtr().setLabelByteSize(labelWidth);
290 realIsPtr().setScalarByteSize(scalarWidth);
300 autoPtr<ISstream>& isPtr,
307 Pout<<
"decomposedBlockData::readBlocks:" 308 <<
" stream:" << (isPtr ? isPtr->name() :
"invalid")
310 <<
" comm:" << comm <<
endl;
380 UOPstream
os(proci, pBufs);
385 pBufs.finishedScatters();
411 Pout<<
"decomposedBlockData::readBlocks:" 412 <<
" stream:" << (isPtr ? isPtr->
name() :
"invalid")
418 autoPtr<ISstream> realIsPtr;
428 realIsPtr.reset(
new IListStream(std::move(data)));
429 realIsPtr->name() = fName;
437 <<
"Problem while reading object header " 482 realIsPtr.reset(
new IListStream(std::move(data)));
483 realIsPtr->
name() = fName;
502 UOPstream
os(proci, pBufs);
509 pBufs.finishedScatters();
516 realIsPtr.reset(
new IListStream(std::move(data)));
517 realIsPtr->
name() = fName;
529 unsigned scalarWidth;
530 word headerName(headerIO.
name());
534 verValue = realIsPtr().version().canonical();
535 fmtValue =
static_cast<int>(realIsPtr().format());
536 labelWidth = realIsPtr().labelByteSize();
537 scalarWidth = realIsPtr().scalarByteSize();
556 realIsPtr().setLabelByteSize(labelWidth);
557 realIsPtr().setScalarByteSize(scalarWidth);
582 forAll(recvOffsets, proci)
587 int(reinterpret_cast<char*>(&datas[proci]) - data0Ptr);
589 recvSizes.
setSize(nProcs,
sizeof(label));
594 reinterpret_cast<const char*>(&data),
610 const label startProc,
623 sliceSizes.
resize(numProcs, 0);
624 sliceOffsets.
resize(numProcs+1, 0);
627 label proci = startProc;
628 for (label i = 0; i < nProcs; i++)
630 sliceSizes[proci] = int(recvSizes[proci]);
631 sliceOffsets[proci] = totalSize;
632 totalSize += sliceSizes[proci];
635 sliceOffsets[proci] = totalSize;
667 const off_t maxBufferSize,
669 const label startProci
674 label nSendProcs = -1;
677 off_t totalSize = recvSizes[startProci];
678 label proci = startProci+1;
679 while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
681 totalSize += recvSizes[proci];
685 nSendProcs = proci-startProci;
692 reinterpret_cast<const char*>(&nSendProcs),
693 List<int>(nProcs,
sizeof(nSendProcs)),
694 List<int>(nProcs,
Zero),
695 reinterpret_cast<char*>(&
n),
715 const bool syncReturnState
720 Pout<<
"decomposedBlockData::writeBlocks:" 721 <<
" stream:" << (osPtr ? osPtr->
name() :
"invalid")
722 <<
" data:" << masterData.
size()
723 <<
" (master only) slaveData:" << slaveData.size()
734 blockOffset.
resize(nProcs);
736 OSstream&
os = *osPtr;
749 if (slaveData.size())
756 OSstream&
os = *osPtr;
759 for (label proci = 1; proci < nProcs; ++proci)
778 OSstream&
os = *osPtr;
781 DynamicList<char> elems;
782 for (label proci = 1; proci < nProcs; ++proci)
784 elems.resize(recvSizes[proci]);
828 label nSendProcs = nProcs-1;
830 while (nSendProcs > 0 && startProc < nProcs)
832 nSendProcs = calcNumProcs
837 fileOperations::masterUncollatedFileOperation::
838 maxMasterFileBufferSize
851 List<int> sliceOffsets;
868 OSstream&
os = *osPtr;
873 label proci = startProc;
874 proci < startProc+nSendProcs;
878 SubList<char> dataSlice
881 sliceOffsets[proci+1]-sliceOffsets[proci],
895 startProc += nSendProcs;
925 return readBlocks(comm_, isPtr, contentData_, commsType_);
945 verValue = headerStream.version().canonical();
946 fmtValue =
static_cast<int>(headerStream.format());
981 if (isA<OFstream>(
os))
984 os.
writeRaw(contentData_.cdata(), contentData_.size_bytes());
989 std::string str(contentData_.cdata(), contentData_.size_bytes());
1026 static_cast<const IOobject&>(*
this)
1031 gather(comm_, label(contentData_.size_bytes()), recvSizes);
1033 List<std::streamoff> blockOffsets;
1034 PtrList<SubList<char>> slaveData;
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &blockOffset, const UList< char > &masterData, const labelUList &recvSizes, const PtrList< SubList< char >> &slaveData, const UPstream::commsTypes, const bool syncReturnState=true)
Write *this. Ostream only valid on master.
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
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)
Write buffer contents to given processor.
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.
virtual const fileName & name() const
The name of the input serial stream. (eg, the name of the Fstream file name)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
commsTypes
Types of communications.
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.
Output to file stream, using an OSstream.
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.
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.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file 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)
Number of this process (starting from masterNo() = 0)
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
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 (READ_IF_PRESENT) bits are set.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
static void scatter(const char *sendData, const UList< int > &sendCounts, const UList< int > &sendOffsets, char *recvData, int recvCount, const label communicator=worldComm)
Send variable length char data to all ranks.
#define forAll(list, i)
Loop across all elements in list.
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) is 1 for serial run.
void setSize(const label n)
Alias for resize()
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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.
Reading required, file watched for runTime modification.
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
Process index of the master (always 0)
The decomposedBlockData comprise a List<char> for each output processor, typically with IO on the mas...
void gather(const Type *sendData, int sendCount, Type *recvData, int recvCount, MPI_Datatype datatype, const label comm, label *requestID=nullptr)
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 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.
bool isReadRequired() const noexcept
True if (MUST_READ | MUST_READ_IF_MODIFIED) bits are set.
static bool bannerEnabled() noexcept
Status of output file banner.
static void gatherSlaveData(const label comm, const UList< char > &data, const labelUList &recvSizes, const label startProc, const label nProcs, List< int > &recvOffsets, List< char > &recvData)
Helper: gather data from (subset of) slaves.
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.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
bool good() const noexcept
True if next operation might succeed.
static bool master(const label communicator=worldComm)
Am I the master rank.
versionNumber version() const noexcept
Get the stream version.
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)
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
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.
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Read buffer contents from given processor.
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.
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 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 ...
static constexpr const zero Zero
Global zero (0)