44 namespace fileOperations
50 collatedFileOperation,
56 collatedFileOperation,
66 "maxThreadFileBufferSize",
74 fileOperationInitialise,
75 fileOperationInitialise_collated,
91 <<
"I/O : " << this->
type();
97 <<
" [threaded] (maxThreadFileBufferSize = " 99 <<
" Requires buffer large enough to collect all data" 100 " or MPI thread support." <<
nl 101 <<
" To avoid MPI threading [slow], set" 102 " (maxThreadFileBufferSize = 0) in" <<
nl 103 <<
" OpenFOAM etc/controlDict" <<
endl;
108 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl;
113 <<
" With scheduled transfer" <<
nl;
118 <<
" With non-blocking transfer," 124 <<
" With non-blocking transfer," 125 " minimal buffer size" <<
nl;
157 const label proci = detectProcessorPath(
io.objectPath());
161 Pout<<
"collatedFileOperation::writeObject :" 162 <<
" For local object : " <<
io.name()
163 <<
" appending processor " << proci
164 <<
" data to " << pathName <<
endl;
169 <<
"Invalid processor path: " << pathName
178 const_cast<regIOobject&
>(
io).updateMetaData();
199 <<
"Cannot open for appending" 217 return (blockOffset >= 0) &&
os.good();
246 return commAndIORanks;
254 void Foam::fileOperations::collatedFileOperation::init(
bool verbose)
260 this->printBanner(ioRanks_.size());
276 managedComm_(getManagedComm(comm_)),
277 writer_(
mag(maxThreadFileBufferSize), comm_)
286 const bool distributedRoots,
297 writer_(
mag(maxThreadFileBufferSize), comm_)
306 managedComm_ = getManagedComm(comm_);
330 if (
io.time().processorCase())
357 const bool writeOnProc
360 const Time& tm =
io.time();
375 Pout<<
"collatedFileOperation::writeObject :" 376 <<
" For object : " <<
io.name()
377 <<
" falling back to master-only output to " <<
io.path()
397 &&
io.writeHeader(
os)
418 if (
io.global() ||
io.globalObject())
422 Pout<<
"collatedFileOperation::writeObject :" 423 <<
" For global object : " <<
io.name()
424 <<
" falling back to master-only output to " << pathName
444 &&
io.writeHeader(
os)
461 Pout<<
"collatedFileOperation::writeObject :" 462 <<
" For object : " <<
io.name()
463 <<
" appending to " << pathName <<
endl;
467 return appendObject(
io, pathName, streamOpt);
473 const bool useThread = (
mag(maxThreadFileBufferSize) > 1);
477 Pout<<
"collatedFileOperation::writeObject :" 478 <<
" For object : " <<
io.name()
479 <<
" starting collating output to " << pathName
480 <<
" useThread:" << useThread <<
endl;
489 threadedCollatedOFstream
os 504 ok = ok &&
io.writeHeader(
os);
516 os.setHeaderEntries(
dict);
519 ok = ok &&
io.writeData(
os);
531 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 551 if (procs.
size() != nProcs_)
568 label proci = detectProcessorPath(fName);
574 label maxProc = nProcs_-1;
575 for (
const label ranki : ioRanks_)
577 if (ranki >= nProcs_)
581 else if (ranki <= proci)
593 if (maxProc-minProc+1 != nProcs_)
614 return processorsDir(
io.objectPath());
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
int infoDetailLevel
Global for selective suppression of Info output.
constexpr char nl
The newline '\n' character (0x0a)
T & first()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
append (seek end each write)
A simple container for options an IOstream can normally have.
static bool isAbsolute(const std::string &str)
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool processorCase() const noexcept
True if this is a processor case.
Macros for easy insertion into run-time selection tables.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const char *str, const size_t len)
Helper: write block of (binary) character data.
static void writeExtraHeaderContent(dictionary &dict, IOstreamOption streamOptData, const IOobject &io)
Helper: generate additional entries for FoamFile header.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
collatedFileOperation(bool verbose=false)
Default construct.
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 Foam::string.
Master-only drop-in replacement for OFstream.
static const word null
An empty word.
void printBanner(const bool withRanks=false) const
Print banner information, optionally with io ranks.
addNamedToRunTimeSelectionTable(fileOperationInitialise, fileOperationInitialise_collated, word, collated)
objectPath exists in 'processorsNN_first-last'
no append (truncates existing)
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static Tuple2< label, labelList > getCommPattern()
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
static bool bannerEnabled() noexcept
Status of output file banner.
T & last()
Access last element of the list, position [size()-1].
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
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.
Ostream & flush(Ostream &os)
Flush stream.
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
void printRanks() const
Helper: output which ranks are IO.
static List< int > & procID(const label communicator)
The list of ranks within a given communicator.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const T2 & second() const noexcept
Access the second element.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
versionNumber version() const noexcept
Get the stream version.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
bool isIOrank(const label proci) const
Is proci a master rank in the communicator (in parallel) or a master rank in the IO ranks (non-parall...
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
defineTypeNameAndDebug(collatedFileOperation, 0)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
const T1 & first() const noexcept
Access the first element.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Defines the attributes of an object for which implicit objectRegistry management is supported...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
static void writeHeader(Ostream &os, IOstreamOption streamOptContainer, const word &objectType, const string ¬e, const fileName &location, const word &objectName, const dictionary &extraEntries)
Helper: write FoamFile IOobject header.
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...