40 namespace fileOperations
56 "maxThreadFileBufferSize",
58 collatedFileOperation::maxThreadFileBufferSize
79 string ioRanksString(
getEnv(
"FOAM_IORANKS"));
80 if (!ioRanksString.empty())
132 Pout<<
"collatedFileOperation::writeObject :" 133 <<
" For local object : " << io.
name()
134 <<
" appending processor " << proci
135 <<
" data to " << pathName <<
endl;
141 <<
"Not a valid processor path " << pathName
145 const bool isMaster = isMasterRank(proci);
148 label localProci = proci;
151 label groupStart, groupSize, nProcs;
162 if (groupSize > 0 && groupStart != -1)
164 localProci = proci-groupStart;
211 <<
"Cannot open for appending" 219 <<
" version " << os.
version() <<
";\n" 220 <<
" format " << os.
format() <<
";\n" 221 <<
" class " << decomposedBlockData::typeName
223 <<
" location " << pathName <<
";\n" 224 <<
" object " << pathName.
name() <<
";\n" 232 const_cast<char*>(buf.data()),
235 os <<
nl <<
"// Processor" << localProci <<
nl << slice <<
nl;
262 writer_(maxThreadFileBufferSize, comm_),
269 <<
"I/O : " << typeName
270 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
273 if (maxThreadFileBufferSize == 0)
276 <<
" Threading not activated " 277 "since maxThreadFileBufferSize = 0." <<
nl 278 <<
" Writing may run slowly for large file sizes." 284 <<
" Threading activated " 285 "since maxThreadFileBufferSize > 0." <<
nl 286 <<
" Requires large enough buffer to collect all data" 287 " or thread support " <<
nl 288 <<
" enabled in MPI. If thread support cannot be " 289 "enabled, deactivate" <<
nl 290 <<
" threading by setting maxThreadFileBufferSize " 292 <<
" $FOAM_ETC/controlDict" 309 if (!ioRanks[proci].empty())
324 <<
"Resetting fileModificationChecking to inotify" <<
endl;
334 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
344 const word& typeName,
350 writer_(maxThreadFileBufferSize, comm),
357 <<
"I/O : " << typeName
358 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
361 if (maxThreadFileBufferSize == 0)
364 <<
" Threading not activated " 365 "since maxThreadFileBufferSize = 0." <<
nl 366 <<
" Writing may run slowly for large file sizes." 372 <<
" Threading activated " 373 "since maxThreadFileBufferSize > 0." <<
nl 374 <<
" Requires large enough buffer to collect all data" 375 " or thread support " <<
nl 376 <<
" enabled in MPI. If thread support cannot be " 377 "enabled, deactivate" <<
nl 378 <<
" threading by setting maxThreadFileBufferSize " 380 <<
" $FOAM_ETC/controlDict" 391 <<
"Resetting fileModificationChecking to inotify" <<
endl;
401 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
469 Pout<<
"collatedFileOperation::writeObject :" 470 <<
" For object : " << io.
name()
471 <<
" falling back to master-only output to " << io.
path()
506 fileName path(processorsPath(io, inst, processorsDir(io)));
515 Pout<<
"collatedFileOperation::writeObject :" 516 <<
" For global object : " << io.
name()
517 <<
" falling back to master-only output to " << pathName
556 Pout<<
"collatedFileOperation::writeObject :" 557 <<
" For object : " << io.
name()
558 <<
" appending to " << pathName <<
endl;
561 return appendObject(io, pathName, fmt, ver, cmp);
567 bool useThread = (maxThreadFileBufferSize > 0);
571 Pout<<
"collatedFileOperation::writeObject :" 572 <<
" For object : " << io.
name()
573 <<
" starting collating output to " << pathName
574 <<
" useThread:" << useThread <<
endl;
621 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 658 label proci = detectProcessorPath(fName);
664 label maxProc = nProcs_-1;
667 if (ioRanks_[i] >= nProcs_)
671 else if (ioRanks_[i] <= proci)
673 minProc = ioRanks_[i];
677 maxProc = ioRanks_[i]-1;
709 Pout<<
"collatedFileOperation::setNProcs :" 710 <<
" Setting number of processors to " << nProcs_ <<
endl;
string getEnv(const word &)
Return environment variable of given name.
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
static labelList ioRanks()
#define forAll(list, i)
Loop across all elements in list.
bool processorCase() const
Return true if this is a processor case.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
A class for handling file names.
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
float floatOptimisationSwitch(const char *name, const float defaultValue=0)
Lookup optimisation switch or add default value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool write=true) const
Writes a regIOobject (so header, contents and divider).
#define InfoHeader
Report write to Foam::Info if the local log switch is true.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
void size(const label)
Override size to be inconsistent with allocated storage.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
collatedFileOperation(const bool verbose)
Construct null.
Master-only drop-in replacement for OFstream.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
versionNumber version() const
Return the stream version.
static label worldComm
Default communicator (all processors)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool good() const
Return true if next operation might succeed.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
fileName path() const
Return complete path.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
string hostName(const bool full=false)
Return the system's host name, as per hostname(1)
bool isAbsolute() const
Return true if file name is absolute.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
A class for handling words, derived from string.
Master-only drop-in replacement for OFstream.
word name() const
Return file name (part beyond last /)
streamFormat
Enumeration for the format of data in the stream.
static const word null
An empty word.
streamFormat format() const
Return current stream format.
bool isMasterRank(const label proci) const
Is proci master of communicator (in parallel) or master of.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
compressionType
Enumeration for the format of data in the stream.
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.
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
word name(const complex &)
Return a string representation of a complex.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
virtual ~collatedFileOperation()
Destructor.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static bool & parRun()
Is this a parallel run?
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const Time & time() const
Return time.
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
string str() const
Return the string.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
virtual bool global() const
Is object same for all processors.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool writeHeader(Ostream &) const
Write header.
defineTypeNameAndDebug(collatedFileOperation, 0)
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
T & last()
Return the last element of the list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
fileName objectPath() const
Return complete path + object name.
Output to memory buffer stream.
static List< int > & procID(label communicator)
Process ID of given process index.
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
fileName path(UMean.rootPath()/UMean.caseName()/functionObjects::writeFile::outputPrefix/"graphs"/UMean.instance())