67 "maxThreadFileBufferSize",
104 <<
"I/O : " << this->
type();
118 <<
" [threaded] (maxThreadFileBufferSize = "
120 <<
" Requires buffer large enough to collect all data"
121 " or MPI thread support." <<
nl
122 <<
" To avoid MPI threading [slow], set"
123 " (maxThreadFileBufferSize = 0) in" <<
nl
124 <<
" OpenFOAM etc/controlDict" <<
endl;
129 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl;
134 <<
" With scheduled transfer" <<
nl;
139 <<
" With non-blocking transfer,"
145 <<
" With non-blocking transfer,"
146 " minimal buffer size" <<
nl;
182 Pout<<
"collatedFileOperation::writeObject :"
183 <<
" For local object : " <<
io.name()
184 <<
" appending processor " << proci
185 <<
" data to " << pathName <<
endl;
190 <<
"Invalid processor path: " << pathName
199 const_cast<regIOobject&
>(
io).updateMetaData();
220 <<
"Cannot open for appending"
238 return (blockOffset >= 0) &&
os.good();
267 return commAndIORanks;
275void Foam::fileOperations::collatedFileOperation::init(
bool verbose)
281 this->printBanner(ioRanks_.size());
291 masterUncollatedFileOperation
297 managedComm_(getManagedComm(comm_)),
298 writer_(
mag(maxThreadFileBufferSize), comm_)
307 const bool distributedRoots,
318 writer_(
mag(maxThreadFileBufferSize), comm_)
327 managedComm_ = getManagedComm(comm_);
351 if (
io.time().processorCase())
376bool Foam::fileOperations::collatedFileOperation::writeObject_legacy
381 const bool writeOnProc
384 const Time& tm =
io.time();
390 || (
io.global() ||
io.globalObject())
395 <<
"Should not have been called for any of these conditions:"
396 <<
" - isAbsolute" <<
nl
397 <<
" - not processorCase" <<
nl
398 <<
" - global or globalObject" <<
nl
399 <<
" - not parallel" <<
nl
408 const bool useThread = (
Foam::mag(maxThreadFileBufferSize) > 1);
412 Pout<<
"collatedFileOperation::writeObject :"
413 <<
" For object : " <<
io.name()
414 <<
" starting collating output to " << pathName
415 <<
" useThread:" << useThread <<
endl;
424 threadedCollatedOFstream
os
439 ok = ok &&
io.writeHeader(
os);
451 os.setHeaderEntries(
dict);
454 ok = ok &&
io.writeData(
os);
468 const bool writeOnProc
471 const Time& tm =
io.time();
486 Pout<<
"collatedFileOperation::writeObject :"
487 <<
" For object : " <<
io.name()
488 <<
" falling back to master-only output to " <<
io.path()
508 &&
io.writeHeader(
os)
529 if (
io.global() ||
io.globalObject())
533 Pout<<
"collatedFileOperation::writeObject :"
534 <<
" For global object : " <<
io.name()
535 <<
" falling back to master-only output to " << pathName
555 &&
io.writeHeader(
os)
572 Pout<<
"collatedFileOperation::writeObject :"
573 <<
" For object : " <<
io.name()
574 <<
" appending to " << pathName <<
endl;
588 return writeObject_mpiio
598 return writeObject_legacy
615 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
635 if (procs.size() != nProcs_)
658 label maxProc = nProcs_-1;
659 for (
const label ranki : ioRanks_)
661 if (ranki >= nProcs_)
665 else if (ranki <= proci)
677 if (maxProc-minProc+1 != nProcs_)
698 return processorsDir(
io.objectPath());
705#include "collatedFileOperation_mpiio.cxx"
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static bool bannerEnabled() noexcept
Status of output file banner.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
A simple container for options an IOstream can normally have.
versionNumber version() const noexcept
Get the stream version.
@ NO_APPEND
no append (truncates existing)
@ APPEND_APP
append (seek end each write)
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
bool processorCase() const noexcept
True if this is a processor case.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
const T1 & first() const noexcept
Access the first element.
const T2 & second() const noexcept
Access the second element.
static bool supported()
True if MPI/IO appears to be supported.
static List< int > & procID(int communicator)
The list of ranks within a given communicator.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
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 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.
A class for handling file names.
static bool isAbsolute(const std::string &str)
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root.
An encapsulation of filesystem-related operations.
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
static label getManagedComm(const label communicator)
Construction helper: check for locally allocated communicator.
const labelList ioRanks_
The list of IO ranks (global ranks).
fileName processorsPath(const IOobject &io, const word &instance, const word &procDir) const
Generate path (like io.path) with provided instance and any.
label nProcs_
Overall number of processors.
static label detectProcessorPath(const fileName &objPath)
Detect processor number from '/aa/bb/processorDDD/cc'.
@ OBJECT
io.objectPath() exists
@ PROCOBJECT
objectPath exists in 'processorsNN_first-last'
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...
label comm_
Communicator to use.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
void printRanks() const
Helper: output which ranks are IO.
static word processorsBaseDir
Return the processors directory name (usually "processors").
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
static int backend_
The type of backend to be used.
virtual ~collatedFileOperation()
Destructor.
virtual word processorsDir(const IOobject &) const
Actual name of processors dir.
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
collatedFileOperation(bool verbose=false)
Default construct.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
OFstreamCollator writer_
Threaded writer.
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Writes a regIOobject (so header, contents and divider).
void printBanner(const bool withRanks=false) const
Print banner information, optionally with io ranks.
virtual fileName objectPath(const IOobject &io, const word &typeName) const
Generate disk file name for object. Opposite of filePath.
A fileOperation initialiser for collated file handlers. Requires threading for non-zero maxThreadFile...
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
masterUncollatedFileOperation(bool verbose=false)
Default construct.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
Master-only drop-in replacement for OFstream.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
Namespace for handling debugging switches.
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
Namespace for implementations of a fileOperation.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
int infoDetailLevel
Global for selective suppression of Info output.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static Tuple2< label, labelList > getCommPattern()
Ostream & flush(Ostream &os)
Flush stream.
constexpr char nl
The newline '\n' character (0x0a).
#define registerOptSwitch(Name, Type, SwitchVar)