40 namespace fileOperations
46 collatedFileOperation,
56 "maxThreadFileBufferSize",
64 fileOperationInitialise,
65 collatedFileOperationInitialise,
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_),
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" 306 if (!ioRanks[proci].empty())
308 Info<<
" " << ioRanks[proci] <<
endl;
321 <<
"Resetting fileModificationChecking to inotify" <<
endl;
331 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
341 const word& typeName,
347 writer_(maxThreadFileBufferSize, comm),
353 Info<<
"I/O : " << typeName
354 <<
" (maxThreadFileBufferSize " << maxThreadFileBufferSize
357 if (maxThreadFileBufferSize == 0)
359 Info<<
" Threading not activated " 360 "since maxThreadFileBufferSize = 0." <<
nl 361 <<
" Writing may run slowly for large file sizes." 366 Info<<
" Threading activated " 367 "since maxThreadFileBufferSize > 0." <<
nl 368 <<
" Requires large enough buffer to collect all data" 369 " or thread support " <<
nl 370 <<
" enabled in MPI. If thread support cannot be " 371 "enabled, deactivate" <<
nl 372 <<
" threading by setting maxThreadFileBufferSize " 374 <<
" $FOAM_ETC/controlDict" 385 <<
"Resetting fileModificationChecking to inotify" <<
endl;
395 <<
"Resetting fileModificationChecking to timeStamp" <<
endl;
463 Pout<<
"collatedFileOperation::writeObject :" 464 <<
" For object : " << io.
name()
465 <<
" falling back to master-only output to " << io.
path()
500 fileName path(processorsPath(io, inst, processorsDir(io)));
509 Pout<<
"collatedFileOperation::writeObject :" 510 <<
" For global object : " << io.
name()
511 <<
" falling back to master-only output to " << pathName
550 Pout<<
"collatedFileOperation::writeObject :" 551 <<
" For object : " << io.
name()
552 <<
" appending to " << pathName <<
endl;
555 return appendObject(io, pathName, fmt, ver, cmp);
561 bool useThread = (maxThreadFileBufferSize > 0);
565 Pout<<
"collatedFileOperation::writeObject :" 566 <<
" For object : " << io.
name()
567 <<
" starting collating output to " << pathName
568 <<
" useThread:" << useThread <<
endl;
615 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 652 label proci = detectProcessorPath(fName);
658 label maxProc = nProcs_-1;
661 if (ioRanks_[i] >= nProcs_)
665 else if (ioRanks_[i] <= proci)
667 minProc = ioRanks_[i];
671 maxProc = ioRanks_[i]-1;
703 Pout<<
"collatedFileOperation::setNProcs :" 704 <<
" 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.
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.
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).
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
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 bool global() const
Is object global.
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")
string str() const
Return the string.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
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.