44 namespace fileOperations
50 collatedFileOperation,
60 "maxThreadFileBufferSize",
68 fileOperationInitialise,
69 collatedFileOperationInitialise,
85 <<
"I/O : " << this->
type();
90 <<
" [unthreaded] (maxThreadFileBufferSize = 0)." <<
nl 91 <<
" Writing may be slow for large file sizes." 97 <<
" [threaded] (maxThreadFileBufferSize = " 99 <<
" Requires buffer large enough to collect all data" 100 " or thread support" <<
nl 101 <<
" enabled in MPI. If MPI thread support cannot be" 102 " enabled, deactivate" <<
nl 103 <<
" threading by setting maxThreadFileBufferSize" 105 <<
" OpenFOAM etc/controlDict" <<
endl;
122 if (!hosts[ranki].empty())
124 offsetMaster.append(ranki);
128 if (offsetMaster.size() > 1)
131 <<
"IO nodes:" <<
nl <<
'(' <<
nl;
137 const label beg = offsetMaster[
group-1];
138 const label
end = offsetMaster[
group];
141 <<
" (" << hosts[beg].c_str() <<
' ' 142 << (
end-beg) <<
')' <<
nl;
172 else if (ioRanks_.size())
175 return ioRanks_.found(proci);
194 const label proci = detectProcessorPath(
io.objectPath());
198 Pout<<
"collatedFileOperation::writeObject :" 199 <<
" For local object : " <<
io.name()
200 <<
" appending processor " << proci
201 <<
" data to " << pathName <<
endl;
206 <<
"Invalid processor path: " << pathName
210 const bool isMaster = isMasterRank(proci);
215 const_cast<regIOobject&
>(
io).updateMetaData();
236 <<
"Cannot open for appending" 255 return (blockOffset >= 0) &&
os.good();
261 void Foam::fileOperations::collatedFileOperation::init(
bool verbose)
267 this->printBanner(ioRanks_.size());
277 masterUncollatedFileOperation
291 writer_(
mag(maxThreadFileBufferSize), comm_),
303 const word& typeName,
309 writer_(
mag(maxThreadFileBufferSize), comm),
340 if (
io.time().processorCase())
370 const Time& tm =
io.time();
383 Pout<<
"collatedFileOperation::writeObject :" 384 <<
" For object : " <<
io.name()
385 <<
" falling back to master-only output to " <<
io.path()
404 &&
io.writeHeader(
os)
418 fileName
path(processorsPath(
io, inst, processorsDir(
io)));
421 fileName pathName(
path/
io.name());
427 Pout<<
"collatedFileOperation::writeObject :" 428 <<
" For global object : " <<
io.name()
429 <<
" falling back to master-only output to " << pathName
448 &&
io.writeHeader(
os)
465 Pout<<
"collatedFileOperation::writeObject :" 466 <<
" For object : " <<
io.name()
467 <<
" appending to " << pathName <<
endl;
470 return appendObject(
io, pathName, streamOpt);
476 const bool useThread = (maxThreadFileBufferSize != 0);
480 Pout<<
"collatedFileOperation::writeObject :" 481 <<
" For object : " <<
io.name()
482 <<
" starting collating output to " << pathName
483 <<
" useThread:" << useThread <<
endl;
492 threadedCollatedOFstream
os 507 ok = ok &&
io.writeHeader(
os);
519 os.setHeaderEntries(
dict);
522 ok = ok &&
io.writeData(
os);
534 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread" 566 word procDir(processorsBaseDir+
Foam::name(nProcs_));
571 label proci = detectProcessorPath(fName);
577 label maxProc = nProcs_-1;
578 for (
const label ranki : ioRanks_)
580 if (ranki >= nProcs_)
584 else if (ranki <= proci)
612 return processorsDir(
io.objectPath());
622 Pout<<
"collatedFileOperation::setNProcs :" 623 <<
" Setting number of processors to " << nProcs_ <<
endl;
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
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.
int infoDetailLevel
Global for selective suppression of Info output.
constexpr char nl
The newline '\n' character (0x0a)
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
collatedFileOperation(bool verbose)
Default construct.
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 int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
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
Return true if this is a processor case.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
#define forAll(list, i)
Loop across all elements in list.
constexpr const char *const group
Group name for atomic constants.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
Gather data, but keep individual values separate. Uses the specified communication schedule...
static void writeExtraHeaderContent(dictionary &dict, IOstreamOption streamOptData, const IOobject &io)
Helper: generate additional entries for FoamFile header.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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 INVALID.
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.
Inter-processor communications stream.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Helper: write block of (binary) character data.
static const word null
An empty word.
objectPath exists in 'processorsNN_first-last'
bool isMasterRank(const label proci) const
Is proci master of communicator (in parallel) or master of the io ranks (non-parallel) ...
string hostName()
Return the system's host name, as per hostname(1)
static bool isUserComm(label communicator) noexcept
True if communicator appears to be user-allocated.
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
int debug
Static debugging option.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
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 bool bannerEnabled() noexcept
Status of output file banner.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
virtual ~collatedFileOperation()
Destructor.
List< string > stringList
A List of strings.
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.
virtual void setNProcs(const label nProcs)
Set number of processor directories/results. Only used in decomposePar.
static List< int > & procID(const label communicator)
Process IDs within a given communicator.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static bool master(const label communicator=worldComm)
Am I the master rank.
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...
const label comm_
Communicator to use.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
defineTypeNameAndDebug(collatedFileOperation, 0)
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.
Inter-processor communications stream.
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 void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...