Go to the documentation of this file.
55 const word& objectType
60 objectType == decomposedBlockData::typeName
84 commsType_(commsType),
89 if (io.
readOpt() == IOobject::MUST_READ_IF_MODIFIED)
92 <<
"decomposedBlockData " <<
name()
93 <<
" constructed with IOobject::MUST_READ_IF_MODIFIED"
94 " but decomposedBlockData does not support automatic rereading."
100 io.
readOpt() == IOobject::MUST_READ
101 || io.
readOpt() == IOobject::MUST_READ_IF_MODIFIED
103 || (io.
readOpt() == IOobject::READ_IF_PRESENT && headerOk())
132 if (!isDictFormat && tok.
good())
145 if (tok.good() && !tok.isPunctuation(token::END_STATEMENT))
164 std::streamoff blockOffset =
os.stdStream().tellp();
169 os <<
nl <<
"// " << procName <<
nl;
183 const bool withLocalHeader
196 const bool old = IOobject::bannerEnabled(
false);
200 IOobject::bannerEnabled(old);
208 return std::streamoff(-1);
211 contentChars =
os.str();
217 const_cast<char*
>(contentChars.data()),
218 label(contentChars.size())
221 return decomposedBlockData::writeBlockEntry(
os, blocki, charData);
235 Pout<<
"decomposedBlockData::readBlock:"
236 <<
" stream:" << is.
name() <<
" attempt to read block " << blocki
249 decomposedBlockData::readBlockEntry(is,
data);
254 realIsPtr->name() = is.
name();
262 <<
"Problem while reading object header "
276 <<
"Problem while reading object header "
285 for (label i = 1; i < blocki+1; i++)
288 decomposedBlockData::readBlockEntry(is,
data);
291 realIsPtr->name() = is.
name();
294 realIsPtr().format(streamOptData.
format());
295 realIsPtr().version(streamOptData.
version());
296 realIsPtr().setLabelByteSize(labelWidth);
297 realIsPtr().setScalarByteSize(scalarWidth);
314 Pout<<
"decomposedBlockData::readBlocks:"
315 <<
" stream:" << (isPtr ? isPtr->name() :
"invalid")
316 <<
" commsType:" << Pstream::commsTypeNames[commsType]
317 <<
" comm:" << comm <<
endl;
322 if (UPstream::master(comm))
328 decomposedBlockData::readBlockEntry(is,
data);
331 if (commsType == UPstream::commsTypes::scheduled)
333 if (UPstream::master(comm))
340 for (
const int proci : UPstream::subProcs(comm))
343 decomposedBlockData::readBlockEntry(is, elems);
347 UPstream::commsTypes::scheduled,
362 UPstream::commsTypes::scheduled,
363 UPstream::masterNo(),
375 UPstream::commsTypes::nonBlocking,
380 if (UPstream::master(comm))
387 for (
const int proci : UPstream::subProcs(comm))
390 decomposedBlockData::readBlockEntry(is, elems);
400 if (!UPstream::master(comm))
402 UIPstream is(UPstream::masterNo(), pBufs);
407 Pstream::scatter(ok, Pstream::msgType(), comm);
424 Pout<<
"decomposedBlockData::readBlocks:"
425 <<
" stream:" << (isPtr ? isPtr->name() :
"invalid")
426 <<
" commsType:" << Pstream::commsTypeNames[commsType] <<
endl;
433 if (UPstream::master(comm))
439 decomposedBlockData::readBlockEntry(is,
data);
442 realIsPtr->name() = fName;
450 <<
"Problem while reading object header "
457 if (commsType == UPstream::commsTypes::scheduled)
459 if (UPstream::master(comm))
466 for (
const int proci : UPstream::subProcs(comm))
468 decomposedBlockData::readBlockEntry(is,
data);
472 UPstream::commsTypes::scheduled,
487 UPstream::commsTypes::scheduled,
488 UPstream::masterNo(),
496 realIsPtr->name() = fName;
503 UPstream::commsTypes::nonBlocking,
508 if (UPstream::master(comm))
515 for (
const int proci : UPstream::subProcs(comm))
518 decomposedBlockData::readBlockEntry(is, elems);
530 if (!UPstream::master(comm))
532 UIPstream is(UPstream::masterNo(), pBufs);
536 realIsPtr->name() = fName;
540 Pstream::scatter(ok, Pstream::msgType(), comm);
548 unsigned scalarWidth;
549 if (UPstream::master(comm))
551 verValue = realIsPtr().version().canonical();
552 fmtValue =
static_cast<int>(realIsPtr().format());
553 labelWidth = realIsPtr().labelByteSize();
554 scalarWidth = realIsPtr().scalarByteSize();
556 Pstream::scatter(verValue);
557 Pstream::scatter(fmtValue);
558 Pstream::scatter(labelWidth);
559 Pstream::scatter(scalarWidth);
561 realIsPtr().version(IOstreamOption::versionNumber::canonical(verValue));
563 realIsPtr().setLabelByteSize(labelWidth);
564 realIsPtr().setScalarByteSize(scalarWidth);
567 Pstream::scatter(
name, Pstream::msgType(), comm);
569 Pstream::scatter(headerIO.
headerClassName(), Pstream::msgType(), comm);
570 Pstream::scatter(headerIO.
note(), Pstream::msgType(), comm);
585 const label nProcs = UPstream::nProcs(comm);
588 char* data0Ptr = datas.data_bytes();
592 if (UPstream::master(comm))
595 forAll(recvOffsets, proci)
600 int(
reinterpret_cast<char*
>(&datas[proci]) - data0Ptr);
602 recvSizes.
setSize(nProcs,
sizeof(label));
607 reinterpret_cast<const char*
>(&
data),
623 const label startProc,
632 if (UPstream::master(comm))
634 const label numProcs = UPstream::nProcs(comm);
636 sliceSizes.
resize(numProcs, 0);
637 sliceOffsets.
resize(numProcs+1, 0);
640 label proci = startProc;
641 for (label i = 0; i < nProcs; i++)
643 sliceSizes[proci] = int(recvSizes[proci]);
644 sliceOffsets[proci] = totalSize;
645 totalSize += sliceSizes[proci];
648 sliceOffsets[proci] = totalSize;
655 !UPstream::master(comm)
656 && (UPstream::myProcNo(comm) >= startProc)
657 && (UPstream::myProcNo(comm) < startProc+nProcs)
661 nSend = int(
data.size_bytes());
680 const off_t maxBufferSize,
682 const label startProci
685 const label nProcs = UPstream::nProcs(comm);
687 label nSendProcs = -1;
688 if (UPstream::master(comm))
690 off_t totalSize = recvSizes[startProci];
691 label proci = startProci+1;
692 while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
694 totalSize += recvSizes[proci];
698 nSendProcs = proci-startProci;
705 reinterpret_cast<const char*
>(&nSendProcs),
708 reinterpret_cast<char*
>(&
n),
728 const bool syncReturnState
733 Pout<<
"decomposedBlockData::writeBlocks:"
734 <<
" stream:" << (osPtr ? osPtr->name() :
"invalid")
735 <<
" data:" << masterData.
size()
736 <<
" (master only) slaveData:" << slaveData.size()
737 <<
" commsType:" << Pstream::commsTypeNames[commsType] <<
endl;
740 const label nProcs = UPstream::nProcs(comm);
745 if (UPstream::master(comm))
747 blockOffset.
resize(nProcs);
751 blockOffset[UPstream::masterNo()] =
752 decomposedBlockData::writeBlockEntry
755 UPstream::masterNo(),
762 if (slaveData.size())
766 if (UPstream::master(comm))
772 for (label proci = 1; proci < nProcs; ++proci)
775 decomposedBlockData::writeBlockEntry
786 else if (commsType == UPstream::commsTypes::scheduled)
788 if (UPstream::master(comm))
795 for (label proci = 1; proci < nProcs; ++proci)
797 elems.
resize(recvSizes[proci]);
800 UPstream::commsTypes::scheduled,
809 decomposedBlockData::writeBlockEntry
823 UPstream::commsTypes::scheduled,
824 UPstream::masterNo(),
841 label nSendProcs = nProcs-1;
843 while (nSendProcs > 0 && startProc < nProcs)
845 nSendProcs = calcNumProcs
851 maxMasterFileBufferSize
879 if (UPstream::master(comm))
886 label proci = startProc;
887 proci < startProc+nSendProcs;
894 sliceOffsets[proci+1]-sliceOffsets[proci],
899 decomposedBlockData::writeBlockEntry
908 startProc += nSendProcs;
911 if (UPstream::master(comm))
921 Pstream::scatter(ok, Pstream::msgType(), comm);
957 fmtValue =
static_cast<int>(headerStream.
format());
975 fileName masterLocation(instance()/db().dbDir()/local());
993 if (isA<OFstream>(
os))
996 os.
writeRaw(contentData_.cdata(), contentData_.size_bytes());
1001 std::string str(contentData_.cdata(), contentData_.size_bytes());
1038 static_cast<const IOobject&
>(*
this)
1043 gather(comm_, label(contentData_.size_bytes()), recvSizes);
int debug
Static debugging option.
void resize(const label len)
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
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.
List< char > contentData_
The block content.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
int canonical() const noexcept
From version to canonical integer value.
A class for handling words, derived from Foam::string.
Output inter-processor communications stream operating on external buffer.
A class for handling file names.
void resize(const label len)
Adjust allocated size of list.
Istream & readList(Istream &is)
Read List from Istream, discarding contents of existing List.
static constexpr const zero Zero
Global zero (0)
Input from file stream, using an ISstream.
Output inter-processor communications stream.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
A List obtained as a section of another List.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
streamFormat format() const noexcept
Get the current stream format.
Generic input stream using a standard (STL) stream.
static bool master(const label communicator=worldComm)
Am I the master process.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
An ISstream with internal List storage. Always UNCOMPRESSED.
Input/output from string buffers.
const fileOperation & fileHandler()
Get current file handler.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A token holds an item read from Istream.
const word & headerClassName() const noexcept
Return name of the class name read from header.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
Input/output streams with managed List storage.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
#define forAll(list, i)
Loop across all elements in list.
bool good() const noexcept
True if next operation might succeed.
bool readHeader(Istream &is)
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
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.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void setSize(const label n)
Alias for resize()
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 void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
The IOstreamOption is a simple container for options an IOstream can normally have.
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.
bool good() const noexcept
True if the managed pointer is non-null.
const UPstream::commsTypes commsType_
Type to use for gather.
Generic output stream using a standard (STL) stream.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
virtual const fileName & name() const
Return the name of the stream.
void finishedSends(const bool block=true)
Mark all sends as having been done.
versionNumber version() const noexcept
Get the stream version.
static bool readBlockEntry(Istream &is, List< char > &charData)
Helper: read block of (binary) character data.
streamFormat
Data format (ascii | binary)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
OBJstream os(runTime.globalPath()/outputName)
fileName relativeName() const
Return the name of the stream relative to the current case.
virtual void rename(const word &newName)
Rename.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool writeData(Ostream &os) const
Write separated content (assumes content is the serialised data)
Output to file stream, using an OSstream.
readOption readOpt() const noexcept
The read option.
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
const word & name() const noexcept
Return name.
commsTypes
Types of communications.
const string & note() const noexcept
Return the optional note.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
static int & msgType() noexcept
Message tag of standard messages.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Helper: write block of (binary) character data.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
virtual fileName filePath() const
Return complete path + object name if the file exists.
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static const word null
An empty word.
bool isCompound() const noexcept
Token is COMPOUND.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
Input inter-processor communications stream.
bool writeHeader(Ostream &os) const
Write header with current type()
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void size(const label n)
Older name for setAddressableSize.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Input inter-processor communications stream operating on external buffer.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
Database for solution data, solver performance and other reduced data.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
virtual bool read()
Read object.