Go to the documentation of this file.
44 namespace fileOperations
50 collatedFileOperation,
60 "maxThreadFileBufferSize",
69 collatedFileOperationInitialise,
83 string ioRanksString(
getEnv(
"FOAM_IORANKS"));
84 if (!ioRanksString.empty())
104 else if (ioRanks_.size())
107 return ioRanks_.found(proci);
126 label proci = detectProcessorPath(io.
objectPath());
130 Pout<<
"collatedFileOperation::writeObject :"
131 <<
" For local object : " << io.
name()
132 <<
" appending processor " << proci
133 <<
" data to " << pathName <<
endl;
139 <<
"Not a valid processor path " << pathName
143 const bool isMaster = isMasterRank(proci);
146 label localProci = proci;
149 label groupStart, groupSize, nProcs;
160 if (groupSize > 0 && groupStart != -1)
162 localProci = proci-groupStart;
207 <<
"Cannot open for appending"
215 <<
" version " << os.
version() <<
";\n"
216 <<
" format " << os.
format() <<
";\n"
217 <<
" class " << decomposedBlockData::typeName
226 os <<
" location " << pathName <<
";\n"
227 <<
" object " << pathName.
name() <<
";\n"
235 const_cast<char*
>(buf.data()),
238 os <<
nl <<
"// Processor" << localProci <<
nl << slice <<
nl;
265 writer_(maxThreadFileBufferSize, comm_),
274 <<
"I/O : " << typeName
275 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
278 if (maxThreadFileBufferSize == 0)
281 <<
" Threading not activated "
282 "since maxThreadFileBufferSize = 0." <<
nl
283 <<
" Writing may run slowly for large file sizes."
289 <<
" Threading activated "
290 "since maxThreadFileBufferSize > 0." <<
nl
291 <<
" Requires large enough buffer to collect all data"
292 " or thread support " <<
nl
293 <<
" enabled in MPI. If thread support cannot be "
294 "enabled, deactivate" <<
nl
295 <<
" threading by setting maxThreadFileBufferSize "
297 <<
" OpenFOAM etc/controlDict"
312 <<
" IO nodes:" <<
nl;
314 for (
const string& ranks : ioRanks)
319 <<
" " << ranks <<
nl;
332 <<
"Resetting fileModificationChecking to inotify" <<
endl;
342 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
352 const word& typeName,
358 writer_(maxThreadFileBufferSize, comm),
367 <<
"I/O : " << typeName
368 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
371 if (maxThreadFileBufferSize == 0)
374 <<
" Threading not activated "
375 "since maxThreadFileBufferSize = 0." <<
nl
376 <<
" Writing may run slowly for large file sizes."
382 <<
" Threading activated "
383 "since maxThreadFileBufferSize > 0." <<
nl
384 <<
" Requires large enough buffer to collect all data"
385 " or thread support " <<
nl
386 <<
" enabled in MPI. If thread support cannot be "
387 "enabled, deactivate" <<
nl
388 <<
" threading by setting maxThreadFileBufferSize "
389 "to 0 in the OpenFOAM etc/controlDict" <<
nl
400 <<
"Resetting fileModificationChecking to inotify" <<
endl;
410 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
476 Pout<<
"collatedFileOperation::writeObject :"
477 <<
" For object : " << io.
name()
478 <<
" falling back to master-only output to " << io.
path()
511 fileName path(processorsPath(io, inst, processorsDir(io)));
520 Pout<<
"collatedFileOperation::writeObject :"
521 <<
" For global object : " << io.
name()
522 <<
" falling back to master-only output to " << pathName
559 Pout<<
"collatedFileOperation::writeObject :"
560 <<
" For object : " << io.
name()
561 <<
" appending to " << pathName <<
endl;
564 return appendObject(io, pathName, streamOpt);
570 bool useThread = (maxThreadFileBufferSize > 0);
574 Pout<<
"collatedFileOperation::writeObject :"
575 <<
" For object : " << io.
name()
576 <<
" starting collating output to " << pathName
577 <<
" useThread:" << useThread <<
endl;
622 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
659 label proci = detectProcessorPath(fName);
665 label maxProc = nProcs_-1;
668 if (ioRanks_[i] >= nProcs_)
672 else if (ioRanks_[i] <= proci)
674 minProc = ioRanks_[i];
678 maxProc = ioRanks_[i]-1;
710 Pout<<
"collatedFileOperation::setNProcs :"
711 <<
" 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.
const word & name() const
Return name.
A class for handling words, derived from Foam::string.
virtual ~collatedFileOperation()
Destructor.
A class for handling file names.
static labelList ioRanks()
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
static Ostream & writeBanner(Ostream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
static bool & parRun()
Is this a parallel run?
static fileCheckTypes fileModificationChecking
Type of file modification checking.
streamFormat format() const noexcept
Get the current stream format.
virtual bool global() const
Is object global.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
Ostream & endl(Ostream &os)
Add newline and flush stream.
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
const Time & time() const
Return time.
string getEnv(const std::string &envName)
Get environment value for given envName.
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 label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processors/ file.
word name(const complex &c)
Return string representation of complex.
pid_t pid()
Return the PID of this process.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
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
Is proci master of communicator (in parallel) or master of.
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.
Macros for easy insertion into run-time selection tables.
Input from string buffer, using a ISstream.
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.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static bool master(const label communicator=0)
Am I the master process.
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.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
static label worldComm
Default communicator (all processors)
Output to string buffer, using a OSstream.
const std::string buildArch
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static const word null
An empty word.
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
bool writeHeader(Ostream &os) const
Write header.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
collatedFileOperation(bool verbose)
Construct null.
bool good() const
Return true if next operation might succeed.
fileName objectPath() const
The complete path + object name.
bool processorCase() const
Return true if this is a processor case.
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.
#define WarningInFunction
Report a warning using Foam::Warning.
static bool isAbsolute(const std::string &str)
Return true if string starts with a '/'.
Master-only drop-in replacement for OFstream.
defineTypeNameAndDebug(collatedFileOperation, 0)