Go to the documentation of this file.
44 namespace fileOperations
50 collatedFileOperation,
60 "maxThreadFileBufferSize",
69 collatedFileOperationInitialise,
85 <<
"I/O : " << this->
type();
90 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl
91 <<
" Writing may be slow for large file sizes."
97 <<
" [threaded] (maxThreadFileBufferSize = "
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;
124 if (!hosts[ranki].empty())
126 offsetMaster.append(ranki);
130 if (offsetMaster.size() > 1)
133 <<
"IO nodes:" <<
nl <<
'(' <<
nl;
139 const label beg = offsetMaster[
group-1];
140 const label
end = offsetMaster[
group];
143 <<
" (" << hosts[beg].c_str() <<
' '
144 << (
end-beg) <<
')' <<
nl;
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);
217 const_cast<regIOobject&
>(io).updateMetaData();
233 <<
"Cannot open for appending"
252 return (blockOffset >= 0) &&
os.good();
277 writer_(
mag(maxThreadFileBufferSize), comm_),
292 const word& typeName,
296 masterUncollatedFileOperation(comm, false),
298 writer_(
mag(maxThreadFileBufferSize), comm),
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;
481 threadedCollatedOFstream
os
508 os.setHeaderEntries(
dict);
523 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
555 word procDir(processorsBaseDir+
Foam::name(nProcs_));
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;
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static void writeHeader(Ostream &os, IOstreamOption streamOptContainer, const word &objectType, const string ¬e, const fileName &location, const word &objectName, const dictionary &extraEntries)
static float maxThreadFileBufferSize
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()
A class for handling file names.
constexpr const char *const group
virtual word processorsDir(const IOobject &) const
static Ostream & writeEndDivider(Ostream &os)
virtual bool writeData(Ostream &) const =0
bool processorCase() const noexcept
@ OBJECT
io.objectPath() exists
static bool bannerEnabled() noexcept
static bool master(const label communicator=worldComm)
virtual bool global() const
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
List< string > stringList
A List of strings.
Ostream & endl(Ostream &os)
static void writeHeader(Ostream &os, const word &fieldName)
const Time & time() const
virtual fileName objectPath(const IOobject &io, const word &typeName) const
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
static void writeExtraHeaderContent(dictionary &dict, IOstreamOption streamOptData, const IOobject &io)
Ostream & flush(Ostream &os)
Inter-processor communications stream.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
DynamicList< T, SizeMin > & append(const T &val)
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)
static void freeCommunicator(const label communicator, const bool doPstream=true)
bool isMasterRank(const label proci) const
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
versionNumber version() const noexcept
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())
General fileOperation initialiser. Handles -ioRanks option, using it to set the FOAM_IORANKS environm...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
const word & name() const noexcept
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual void flush() const
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
#define FatalErrorInFunction
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
float floatOptimisationSwitch(const char *name, const float deflt=0)
static int myProcNo(const label communicator=worldComm)
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Inter-processor communications stream.
void printBanner(const bool printRanks=false) const
static bool & parRun() noexcept
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
string hostName(bool full=false)
@ PROCOBJECT
objectPath exists in 'processorsNN_first-last'
const fileName & instance() const noexcept
word name(const expressions::valueTypeCode typeCode)
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
bool writeHeader(Ostream &os) const
#define FatalIOErrorInFunction(ios)
collatedFileOperation(bool verbose)
fileName objectPath() const
bool mkDir(const fileName &pathName, mode_t mode=0777)
virtual void flush() const
static bool isAbsolute(const std::string &str)
Master-only drop-in replacement for OFstream.
static label nProcs(const label communicator=worldComm)
defineTypeNameAndDebug(collatedFileOperation, 0)