Go to the documentation of this file.
42 namespace fileOperations
48 collatedFileOperation,
58 "maxThreadFileBufferSize",
67 collatedFileOperationInitialise,
81 string ioRanksString(
getEnv(
"FOAM_IORANKS"));
82 if (!ioRanksString.empty())
102 else if (ioRanks_.size())
105 return ioRanks_.found(proci);
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;
209 <<
"Cannot open for appending"
217 <<
" version " << os.
version() <<
";\n"
218 <<
" format " << os.
format() <<
";\n"
219 <<
" class " << decomposedBlockData::typeName
221 <<
" location " << pathName <<
";\n"
222 <<
" object " << pathName.
name() <<
";\n"
230 const_cast<char*
>(buf.data()),
233 os <<
nl <<
"// Processor" << localProci <<
nl << slice <<
nl;
260 writer_(maxThreadFileBufferSize, comm_),
268 Info<<
"I/O : " << typeName
269 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
272 if (maxThreadFileBufferSize == 0)
274 Info<<
" Threading not activated "
275 "since maxThreadFileBufferSize = 0." <<
nl
276 <<
" Writing may run slowly for large file sizes."
281 Info<<
" Threading activated "
282 "since maxThreadFileBufferSize > 0." <<
nl
283 <<
" Requires large enough buffer to collect all data"
284 " or thread support " <<
nl
285 <<
" enabled in MPI. If thread support cannot be "
286 "enabled, deactivate" <<
nl
287 <<
" threading by setting maxThreadFileBufferSize "
289 <<
" $FOAM_ETC/controlDict"
303 Info<<
" IO nodes:" <<
nl;
304 for (
const string& ranks : ioRanks)
308 Info<<
" " << ranks <<
nl;
321 <<
"Resetting fileModificationChecking to inotify" <<
endl;
331 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
341 const word& typeName,
347 writer_(maxThreadFileBufferSize, comm),
355 Info<<
"I/O : " << typeName
356 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
359 if (maxThreadFileBufferSize == 0)
361 Info<<
" Threading not activated "
362 "since maxThreadFileBufferSize = 0." <<
nl
363 <<
" Writing may run slowly for large file sizes."
368 Info<<
" Threading activated "
369 "since maxThreadFileBufferSize > 0." <<
nl
370 <<
" Requires large enough buffer to collect all data"
371 " or thread support " <<
nl
372 <<
" enabled in MPI. If thread support cannot be "
373 "enabled, deactivate" <<
nl
374 <<
" threading by setting maxThreadFileBufferSize "
375 "to 0 in the OpenFOAM etc/controlDict" <<
nl
386 <<
"Resetting fileModificationChecking to inotify" <<
endl;
396 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
464 Pout<<
"collatedFileOperation::writeObject :"
465 <<
" For object : " << io.
name()
466 <<
" falling back to master-only output to " << io.
path()
501 fileName path(processorsPath(io, inst, processorsDir(io)));
510 Pout<<
"collatedFileOperation::writeObject :"
511 <<
" For global object : " << io.
name()
512 <<
" falling back to master-only output to " << pathName
551 Pout<<
"collatedFileOperation::writeObject :"
552 <<
" For object : " << io.
name()
553 <<
" appending to " << pathName <<
endl;
556 return appendObject(io, pathName, fmt, ver, cmp);
562 bool useThread = (maxThreadFileBufferSize > 0);
566 Pout<<
"collatedFileOperation::writeObject :"
567 <<
" For object : " << io.
name()
568 <<
" starting collating output to " << pathName
569 <<
" 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()
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.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Representation of a major/minor version number.
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
pid_t pid()
Return the PID of this process.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Append to processors/ file.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
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.
versionNumber version() const noexcept
Get the stream version.
streamFormat
Data format (ascii | binary)
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.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
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.
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.
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
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)