44 namespace fileOperations
50 collatedFileOperation,
56 collatedFileOperation,
66 "maxThreadFileBufferSize",
74 fileOperationInitialise,
75 fileOperationInitialise_collated,
91 <<
"I/O : " << this->
type();
96 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl 97 <<
" Writing may be slow for large file sizes." 103 <<
" [threaded] (maxThreadFileBufferSize = " 105 <<
" Requires buffer large enough to collect all data" 106 " or thread support" <<
nl 107 <<
" enabled in MPI. If MPI thread support cannot be" 108 " enabled, deactivate" <<
nl 109 <<
" threading by setting maxThreadFileBufferSize" 111 <<
" OpenFOAM etc/controlDict" <<
endl;
142 const label proci = detectProcessorPath(
io.objectPath());
146 Pout<<
"collatedFileOperation::writeObject :" 147 <<
" For local object : " <<
io.name()
148 <<
" appending processor " << proci
149 <<
" data to " << pathName <<
endl;
154 <<
"Invalid processor path: " << pathName
163 const_cast<regIOobject&
>(
io).updateMetaData();
184 <<
"Cannot open for appending" 202 return (blockOffset >= 0) &&
os.good();
231 return commAndIORanks;
239 void Foam::fileOperations::collatedFileOperation::init(
bool verbose)
245 this->printBanner(ioRanks_.size());
261 managedComm_(getManagedComm(comm_)),
262 writer_(
mag(maxThreadFileBufferSize), comm_)
271 const bool distributedRoots,
282 writer_(
mag(maxThreadFileBufferSize), comm_)
291 managedComm_ = getManagedComm(comm_);
315 if (
io.time().processorCase())
342 const bool writeOnProc
345 const Time& tm =
io.time();
360 Pout<<
"collatedFileOperation::writeObject :" 361 <<
" For object : " <<
io.name()
362 <<
" falling back to master-only output to " <<
io.path()
382 &&
io.writeHeader(
os)
403 if (
io.global() ||
io.globalObject())
407 Pout<<
"collatedFileOperation::writeObject :" 408 <<
" For global object : " <<
io.name()
409 <<
" falling back to master-only output to " << pathName
429 &&
io.writeHeader(
os)
446 Pout<<
"collatedFileOperation::writeObject :" 447 <<
" For object : " <<
io.name()
448 <<
" appending to " << pathName <<
endl;
452 return appendObject(
io, pathName, streamOpt);
458 const bool useThread = (maxThreadFileBufferSize != 0);
462 Pout<<
"collatedFileOperation::writeObject :" 463 <<
" For object : " <<
io.name()
464 <<
" starting collating output to " << pathName
465 <<
" useThread:" << useThread <<
endl;
474 threadedCollatedOFstream
os 489 ok = ok &&
io.writeHeader(
os);
501 os.setHeaderEntries(
dict);
504 ok = ok &&
io.writeData(
os);
516 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 536 if (procs.
size() != nProcs_)
553 label proci = detectProcessorPath(fName);
559 label maxProc = nProcs_-1;
560 for (
const label ranki : ioRanks_)
562 if (ranki >= nProcs_)
566 else if (ranki <= proci)
578 if (maxProc-minProc+1 != nProcs_)
599 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.
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.
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'
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 ...