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;
151 splitProcessorPath(pathName,
path, procDir, local,
group, nProcs);
156 localProci = proci -
group.start();
201 <<
"Cannot open for appending"
209 <<
" version " << os.
version() <<
";\n"
210 <<
" format " << os.
format() <<
";\n"
211 <<
" class " << decomposedBlockData::typeName
220 os <<
" location " << pathName <<
";\n"
221 <<
" object " << pathName.
name() <<
";\n"
229 const_cast<char*
>(buf.data()),
232 os <<
nl <<
"// Processor" << localProci <<
nl << slice <<
nl;
259 writer_(maxThreadFileBufferSize, comm_),
268 <<
"I/O : " << typeName
269 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
272 if (maxThreadFileBufferSize == 0)
275 <<
" Threading not activated "
276 "since maxThreadFileBufferSize = 0." <<
nl
277 <<
" Writing may run slowly for large file sizes."
283 <<
" Threading activated "
284 "since maxThreadFileBufferSize > 0." <<
nl
285 <<
" Requires large enough buffer to collect all data"
286 " or thread support " <<
nl
287 <<
" enabled in MPI. If thread support cannot be "
288 "enabled, deactivate" <<
nl
289 <<
" threading by setting maxThreadFileBufferSize "
291 <<
" OpenFOAM etc/controlDict"
306 <<
" IO nodes:" <<
nl;
308 for (
const string& ranks : ioRanks)
313 <<
" " << ranks <<
nl;
326 <<
"Resetting fileModificationChecking to inotify" <<
endl;
336 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
346 const word& typeName,
352 writer_(maxThreadFileBufferSize, comm),
361 <<
"I/O : " << typeName
362 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
365 if (maxThreadFileBufferSize == 0)
368 <<
" Threading not activated "
369 "since maxThreadFileBufferSize = 0." <<
nl
370 <<
" Writing may run slowly for large file sizes."
376 <<
" Threading activated "
377 "since maxThreadFileBufferSize > 0." <<
nl
378 <<
" Requires large enough buffer to collect all data"
379 " or thread support " <<
nl
380 <<
" enabled in MPI. If thread support cannot be "
381 "enabled, deactivate" <<
nl
382 <<
" threading by setting maxThreadFileBufferSize "
383 "to 0 in the OpenFOAM etc/controlDict" <<
nl
394 <<
"Resetting fileModificationChecking to inotify" <<
endl;
404 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
470 Pout<<
"collatedFileOperation::writeObject :"
471 <<
" For object : " << io.
name()
472 <<
" falling back to master-only output to " << io.
path()
505 fileName path(processorsPath(io, inst, processorsDir(io)));
514 Pout<<
"collatedFileOperation::writeObject :"
515 <<
" For global object : " << io.
name()
516 <<
" falling back to master-only output to " << pathName
553 Pout<<
"collatedFileOperation::writeObject :"
554 <<
" For object : " << io.
name()
555 <<
" appending to " << pathName <<
endl;
558 return appendObject(io, pathName, streamOpt);
564 bool useThread = (maxThreadFileBufferSize > 0);
568 Pout<<
"collatedFileOperation::writeObject :"
569 <<
" For object : " << io.
name()
570 <<
" starting collating output to " << pathName
571 <<
" useThread:" << useThread <<
endl;
616 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
653 label proci = detectProcessorPath(fName);
659 label maxProc = nProcs_-1;
662 if (ioRanks_[i] >= nProcs_)
666 else if (ioRanks_[i] <= proci)
668 minProc = ioRanks_[i];
672 maxProc = ioRanks_[i]-1;
704 Pout<<
"collatedFileOperation::setNProcs :"
705 <<
" 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()
constexpr const char *const group
Group name for atomic constants.
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
An interval of (signed) integers defined by a start and a size.
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 std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
static bool & parRun()
Test if this a parallel run, or allow modify access.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
streamFormat format() const noexcept
Get the current stream format.
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.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
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.
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 int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
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.
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
defineTypeNameAndDebug(collatedFileOperation, 0)