38 namespace fileOperations
71 string ioRanksString(
getEnv(
"FOAM_IORANKS"));
72 if (!ioRanksString.empty())
124 Pout<<
"collatedFileOperation::writeObject :" 125 <<
" For local object : " << io.
name()
126 <<
" appending processor " << proci
127 <<
" data to " << filePath <<
endl;
133 <<
"Not a valid processor path " << filePath
137 const bool isMaster = isMasterRank(proci);
140 label localProci = proci;
143 label groupStart, groupSize, nProcs;
154 if (groupSize > 0 && groupStart != -1)
156 localProci = proci-groupStart;
203 <<
"Cannot open for appending" 213 os <<
" version " << os.
version() <<
";\n";
216 os <<
" format " << os.
format() <<
";\n" 217 <<
" class " << decomposedBlockData::typeName
219 <<
" location " << filePath <<
";\n" 220 <<
" object " << filePath.
name() <<
";\n" 229 const_cast<char*>(buf.data()),
232 os <<
nl <<
"// Processor" << localProci <<
nl << slice <<
nl;
259 writer_(maxThreadFileBufferSize, comm_),
266 <<
"I/O : " << typeName
267 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
270 if (maxThreadFileBufferSize == 0)
273 <<
" Threading not activated " 274 "since maxThreadFileBufferSize = 0." <<
nl 275 <<
" Writing may run slowly for large file sizes." 281 <<
" 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" 306 if (!ioRanks[proci].empty())
321 <<
"Resetting fileModificationChecking to inotify" <<
endl;
331 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
341 const word& typeName,
347 writer_(maxThreadFileBufferSize, comm),
354 <<
"I/O : " << typeName
355 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
358 if (maxThreadFileBufferSize == 0)
361 <<
" Threading not activated " 362 "since maxThreadFileBufferSize = 0." <<
nl 363 <<
" Writing may run slowly for large file sizes." 369 <<
" Threading activated " 370 "since maxThreadFileBufferSize > 0." <<
nl 371 <<
" Requires large enough buffer to collect all data" 372 " or thread support " <<
nl 373 <<
" enabled in MPI. If thread support cannot be " 374 "enabled, deactivate" <<
nl 375 <<
" threading by setting maxThreadFileBufferSize " 377 <<
" $FOAM_ETC/controlDict" 388 <<
"Resetting fileModificationChecking to inotify" <<
endl;
398 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
466 Pout<<
"collatedFileOperation::writeObject :" 467 <<
" For object : " << io.
name()
468 <<
" falling back to master-only output to " << io.
path()
503 fileName path(processorsPath(io, inst, processorsDir(io)));
512 Pout<<
"collatedFileOperation::writeObject :" 513 <<
" For global object : " << io.
name()
514 <<
" falling back to master-only output to " << filePath
553 Pout<<
"collatedFileOperation::writeObject :" 554 <<
" For object : " << io.
name()
555 <<
" appending to " << filePath <<
endl;
558 return appendObject(io, filePath, fmt, ver, cmp);
564 bool useThread = (maxThreadFileBufferSize > 0);
568 Pout<<
"collatedFileOperation::writeObject :" 569 <<
" For object : " << io.
name()
570 <<
" starting collating output to " << filePath
571 <<
" useThread:" << useThread <<
endl;
618 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 655 label proci = detectProcessorPath(fName);
661 label maxProc = nProcs_-1;
664 if (ioRanks_[i] >= nProcs_)
668 else if (ioRanks_[i] <= proci)
670 minProc = ioRanks_[i];
674 maxProc = ioRanks_[i]-1;
706 Pout<<
"collatedFileOperation::setNProcs :" 707 <<
" 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.
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.
static const versionNumber currentVersion
Current version number.
#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.
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.
bool appendObject(const regIOobject &io, const fileName &filePath, IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Append to processors/ file.
fileName path(UMean.rootPath()/UMean.caseName()/functionObjects::writeFile::outputPrefix/"graphs"/UMean.instance())