44namespace fileOperations
60 "maxThreadFileBufferSize",
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;
135 for (label group = 1; group < offsetMaster.
size(); ++group)
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);
231 <<
"Cannot open for appending"
237 decomposedBlockData::writeHeader(
os, streamOpt,
io);
250 return (blockOffset >= 0) &&
os.good();
275 writer_(
mag(maxThreadFileBufferSize), comm_),
290 const word& typeName,
296 writer_(
mag(maxThreadFileBufferSize), comm),
330 if (
io.time().processorCase())
360 const Time& tm =
io.time();
373 Pout<<
"collatedFileOperation::writeObject :"
374 <<
" For object : " <<
io.name()
375 <<
" falling back to master-only output to " <<
io.path()
393 &&
io.writeHeader(
os)
416 Pout<<
"collatedFileOperation::writeObject :"
417 <<
" For global object : " <<
io.name()
418 <<
" falling back to master-only output to " << pathName
436 &&
io.writeHeader(
os)
453 Pout<<
"collatedFileOperation::writeObject :"
454 <<
" For object : " <<
io.name()
455 <<
" appending to " << pathName <<
endl;
458 return appendObject(
io, pathName, streamOpt);
464 const bool useThread = (maxThreadFileBufferSize != 0);
468 Pout<<
"collatedFileOperation::writeObject :"
469 <<
" For object : " <<
io.name()
470 <<
" starting collating output to " << pathName
471 <<
" useThread:" << useThread <<
endl;
494 ok = ok &&
io.writeHeader(
os);
506 os.setHeaderEntries(
dict);
509 ok = ok &&
io.writeData(
os);
521 Pout<<
"collatedFileOperation::flush : clearing and waiting for thread"
537 const List<int>& procs(UPstream::procID(comm_));
558 label proci = detectProcessorPath(fName);
564 label maxProc = nProcs_-1;
565 for (
const label ranki : ioRanks_)
567 if (ranki >= nProcs_)
571 else if (ranki <= proci)
599 return processorsDir(
io.objectPath());
609 Pout<<
"collatedFileOperation::setNProcs :"
610 <<
" Setting number of processors to " << nProcs_ <<
endl;
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.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
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.
fileName objectPath() const
The complete path + object name.
The IOstreamOption is a simple container for options an IOstream can normally have.
versionNumber version() const noexcept
Get the stream version.
Output to file stream, using an OSstream.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
Inter-processor communications stream.
static void gatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
bool processorCase() const noexcept
Return true if this is a processor case.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
T & first()
Return the first element of the list.
void size(const label n)
Older name for setAddressableSize.
T & last()
Return the last element of the list.
Inter-processor communications stream.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
static label worldComm
Default communicator (all processors)
static bool & parRun() noexcept
Test if this a parallel run.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
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 list of keyword definitions, which are a keyword followed by a number of values (eg,...
A class for handling file names.
static bool isAbsolute(const std::string &str)
An encapsulation of filesystem-related operations.
const label comm_
Communicator to use.
@ OBJECT
io.objectPath() exists
@ PROCOBJECT
objectPath exists in 'processorsNN_first-last'
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
bool isMasterRank(const label proci) const
virtual void setNProcs(const label nProcs)
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.
const labelList ioRanks_
Ranks of IO handlers.
static float maxThreadFileBufferSize
Max size of thread buffer size. This is the overall size of.
bool appendObject(const regIOobject &io, const fileName &pathName, IOstreamOption streamOpt) const
Append to processorsNN/ file.
virtual bool writeObject(const regIOobject &, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
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.
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.
int myProcNo() const noexcept
Return processor number.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
splitCell * master() const
Master-only drop-in replacement for OFstream.
A class for handling words, derived from Foam::string.
#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)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Ostream & endl(Ostream &os)
Add newline and flush stream.
string hostName()
Return the system's host name, as per hostname(1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
int infoDetailLevel
Global for selective suppression of Info output.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Ostream & flush(Ostream &os)
Flush stream.
constexpr char nl
The newline '\n' character (0x0a)
#define registerOptSwitch(Name, Type, SwitchVar)
#define forAll(list, i)
Loop across all elements in list.