Go to the documentation of this file.
44 namespace fileOperations
50 collatedFileOperation,
60 "maxThreadFileBufferSize",
69 collatedFileOperationInitialise,
85 <<
"I/O : " << this->
type();
87 if (maxThreadFileBufferSize == 0)
90 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl
91 <<
" Writing may be slow for large file sizes."
97 <<
" [threaded] (maxThreadFileBufferSize = "
98 << maxThreadFileBufferSize <<
")." <<
nl
99 <<
" Requires buffer large enough to collect all data"
100 " or thread support" <<
nl
101 <<
" enabled in MPI. If MPI thread support cannot be"
102 " enabled, deactivate" <<
nl
103 <<
" threading by setting maxThreadFileBufferSize"
105 <<
" OpenFOAM etc/controlDict" <<
endl;
112 if (Pstream::master(comm_))
116 hosts[Pstream::myProcNo()] =
hostName();
118 Pstream::gatherList(hosts);
124 if (!hosts[ranki].empty())
126 offsetMaster.
append(ranki);
130 if (offsetMaster.size() > 1)
133 <<
"IO nodes:" <<
nl <<
'(' <<
nl;
135 offsetMaster.
append(Pstream::nProcs());
139 const label beg = offsetMaster[
group-1];
140 const label
end = offsetMaster[
group];
143 <<
" (" << hosts[beg].c_str() <<
' '
144 << (
end-beg) <<
')' <<
nl;
170 if (Pstream::parRun())
172 return Pstream::master(comm_);
174 else if (ioRanks_.size())
177 return ioRanks_.found(proci);
196 const label proci = detectProcessorPath(io.
objectPath());
200 Pout<<
"collatedFileOperation::writeObject :"
201 <<
" For local object : " << io.
name()
202 <<
" appending processor " << proci
203 <<
" data to " << pathName <<
endl;
208 <<
"Invalid processor path: " << pathName
212 const bool isMaster = isMasterRank(proci);
233 <<
"Cannot open for appending"
242 std::streamoff blockOffset = decomposedBlockData::writeBlockEntry
252 return (blockOffset >= 0) &&
os.good();
267 ? UPstream::allocateCommunicator
270 subRanks(Pstream::nProcs())
272 : UPstream::worldComm
277 writer_(
mag(maxThreadFileBufferSize), comm_),
278 nProcs_(Pstream::nProcs()),
283 this->printBanner(ioRanks_.size());
292 const word& typeName,
298 writer_(
mag(maxThreadFileBufferSize), comm),
299 nProcs_(Pstream::nProcs()),
304 this->printBanner(ioRanks_.size());
375 Pout<<
"collatedFileOperation::writeObject :"
376 <<
" For object : " << io.
name()
377 <<
" falling back to master-only output to " << io.
path()
409 fileName path(processorsPath(io, inst, processorsDir(io)));
418 Pout<<
"collatedFileOperation::writeObject :"
419 <<
" For global object : " << io.
name()
420 <<
" falling back to master-only output to " << pathName
455 Pout<<
"collatedFileOperation::writeObject :"
456 <<
" For object : " << io.
name()
457 <<
" appending to " << pathName <<
endl;
460 return appendObject(io, pathName, streamOpt);
466 const bool useThread = (maxThreadFileBufferSize != 0);
470 Pout<<
"collatedFileOperation::writeObject :"
471 <<
" For object : " << io.
name()
472 <<
" starting collating output to " << pathName
473 <<
" useThread:" << useThread <<
endl;
508 os.setHeaderEntries(
dict);
523 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
560 label proci = detectProcessorPath(fName);
566 label maxProc = nProcs_-1;
567 for (
const label ranki : ioRanks_)
569 if (ranki >= nProcs_)
573 else if (ranki <= proci)
611 Pout<<
"collatedFileOperation::setNProcs :"
612 <<
" Setting number of processors to " << nProcs_ <<
endl;
int debug
Static debugging option.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
virtual ~collatedFileOperation()
Destructor.
A class for handling file names.
constexpr const char *const group
Group name for atomic constants.
const fileName & instance() const noexcept
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
bool processorCase() const noexcept
Return true if this is a processor case.
static bool bannerEnabled() noexcept
Status of output file banner.
static bool master(const label communicator=worldComm)
Am I the master process.
virtual bool global() const
Is object global.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void writeHeader(Ostream &os, const word &fieldName)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const Time & time() const
Return Time associated with the objectRegistry.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
#define forAll(list, i)
Loop across all elements in list.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
static void writeExtraHeaderContent(dictionary &dict, IOstreamOption streamOptData, const IOobject &io)
Helper: generate additional entries for FoamFile header.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual void setNProcs(const label nProcs)
The IOstreamOption is a simple container for options an IOstream can normally have.
static List< int > & procID(label communicator)
Process ID of given process index.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
bool isMasterRank(const label proci) const
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
versionNumber version() const noexcept
Get the stream version.
Master-only drop-in replacement for OFstream.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
OBJstream os(runTime.globalPath()/outputName)
Macros for easy insertion into run-time selection tables.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
General fileOperation initialiser. Handles -ioRanks option, using it to set the FOAM_IORANKS environm...
int infoDetailLevel
Global for selective suppression of Info output.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
const word & name() const noexcept
Return name.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
static label worldComm
Default communicator (all processors)
static bool & parRun() noexcept
Test if this a parallel run.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
string hostName(bool full=false)
Return the system's host name, as per hostname(1)
static const word null
An empty word.
objectPath exists in 'processorsNN_first-last'
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
bool writeHeader(Ostream &os) const
Write header with current type()
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
collatedFileOperation(bool verbose)
Default construct.
fileName objectPath() const
The complete path + object name.
const label myComm_
Any communicator allocated by me.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
fileName path() const
The complete path.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static bool isAbsolute(const std::string &str)
Master-only drop-in replacement for OFstream.
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
defineTypeNameAndDebug(collatedFileOperation, 0)