mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
INT: Integration of Mattijs' collocated parallel IO additions
Original commit message:
------------------------
Parallel IO: New collated file format
When an OpenFOAM simulation runs in parallel, the data for decomposed fields and
mesh(es) has historically been stored in multiple files within separate
directories for each processor. Processor directories are named 'processorN',
where N is the processor number.
This commit introduces an alternative "collated" file format where the data for
each decomposed field (and mesh) is collated into a single file, which is
written and read on the master processor. The files are stored in a single
directory named 'processors'.
The new format produces significantly fewer files - one per field, instead of N
per field. For large parallel cases, this avoids the restriction on the number
of open files imposed by the operating system limits.
The file writing can be threaded allowing the simulation to continue running
while the data is being written to file. NFS (Network File System) is not
needed when using the the collated format and additionally, there is an option
to run without NFS with the original uncollated approach, known as
"masterUncollated".
The controls for the file handling are in the OptimisationSwitches of
etc/controlDict:
OptimisationSwitches
{
...
//- Parallel IO file handler
// uncollated (default), collated or masterUncollated
fileHandler uncollated;
//- collated: thread buffer size for queued file writes.
// If set to 0 or not sufficient for the file size threading is not used.
// Default: 2e9
maxThreadFileBufferSize 2e9;
//- masterUncollated: non-blocking buffer size.
// If the file exceeds this buffer size scheduled transfer is used.
// Default: 2e9
maxMasterFileBufferSize 2e9;
}
When using the collated file handling, memory is allocated for the data in the
thread. maxThreadFileBufferSize sets the maximum size of memory in bytes that
is allocated. If the data exceeds this size, the write does not use threading.
When using the masterUncollated file handling, non-blocking MPI communication
requires a sufficiently large memory buffer on the master node.
maxMasterFileBufferSize sets the maximum size in bytes of the buffer. If the
data exceeds this size, the system uses scheduled communication.
The installation defaults for the fileHandler choice, maxThreadFileBufferSize
and maxMasterFileBufferSize (set in etc/controlDict) can be over-ridden within
the case controlDict file, like other parameters. Additionally the fileHandler
can be set by:
- the "-fileHandler" command line argument;
- a FOAM_FILEHANDLER environment variable.
A foamFormatConvert utility allows users to convert files between the collated
and uncollated formats, e.g.
mpirun -np 2 foamFormatConvert -parallel -fileHandler uncollated
An example case demonstrating the file handling methods is provided in:
$FOAM_TUTORIALS/IO/fileHandling
The work was undertaken by Mattijs Janssens, in collaboration with Henry Weller.
This commit is contained in:
@ -29,6 +29,7 @@ License
|
||||
#include "HashSet.H"
|
||||
#include "profiling.H"
|
||||
#include "demandDrivenData.H"
|
||||
#include "IOdictionary.H"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -177,13 +178,12 @@ void Foam::Time::setControls()
|
||||
|
||||
// Check if time directory exists
|
||||
// If not increase time precision to see if it is formatted differently.
|
||||
if (!exists(timePath(), false))
|
||||
if (!fileHandler().exists(timePath(), false))
|
||||
{
|
||||
int oldPrecision = precision_;
|
||||
int requiredPrecision = -1;
|
||||
bool found = false;
|
||||
word oldTime(timeName());
|
||||
|
||||
for
|
||||
(
|
||||
precision_ = maxPrecision_;
|
||||
@ -194,7 +194,6 @@ void Foam::Time::setControls()
|
||||
// Update the time formatting
|
||||
setTime(startTime_, 0);
|
||||
|
||||
// Check that the time name has changed otherwise exit loop
|
||||
word newTime(timeName());
|
||||
if (newTime == oldTime)
|
||||
{
|
||||
@ -203,7 +202,7 @@ void Foam::Time::setControls()
|
||||
oldTime = newTime;
|
||||
|
||||
// Check the existence of the time directory with the new format
|
||||
found = exists(timePath(), false);
|
||||
found = fileHandler().exists(timePath(), false);
|
||||
|
||||
if (found)
|
||||
{
|
||||
@ -379,17 +378,8 @@ void Foam::Time::setMonitoring(const bool forceProfiling)
|
||||
// Time objects not registered so do like objectRegistry::checkIn ourselves.
|
||||
if (runTimeModifiable_)
|
||||
{
|
||||
monitorPtr_.reset
|
||||
(
|
||||
new fileMonitor
|
||||
(
|
||||
regIOobject::fileModificationChecking == inotify
|
||||
|| regIOobject::fileModificationChecking == inotifyMaster
|
||||
)
|
||||
);
|
||||
|
||||
// Monitor all files that controlDict depends on
|
||||
addWatches(controlDict_, controlDict_.files());
|
||||
fileHandler().addWatches(controlDict_, controlDict_.files());
|
||||
}
|
||||
|
||||
// Clear dependent files - not needed now
|
||||
@ -685,7 +675,7 @@ Foam::Time::~Time()
|
||||
|
||||
forAllReverse(controlDict_.watchIndices(), i)
|
||||
{
|
||||
removeWatch(controlDict_.watchIndices()[i]);
|
||||
fileHandler().removeWatch(controlDict_.watchIndices()[i]);
|
||||
}
|
||||
|
||||
// Destroy function objects first
|
||||
@ -698,86 +688,6 @@ Foam::Time::~Time()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::Time::addWatches(regIOobject& rio, const fileNameList& files) const
|
||||
{
|
||||
const labelList& watchIndices = rio.watchIndices();
|
||||
|
||||
DynamicList<label> newWatchIndices;
|
||||
labelHashSet removedWatches(watchIndices);
|
||||
|
||||
forAll(files, i)
|
||||
{
|
||||
const fileName& f = files[i];
|
||||
label index = findWatch(watchIndices, f);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
newWatchIndices.append(addTimeWatch(f));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Existing watch
|
||||
newWatchIndices.append(watchIndices[index]);
|
||||
removedWatches.erase(index);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any unused watches
|
||||
forAllConstIter(labelHashSet, removedWatches, iter)
|
||||
{
|
||||
removeWatch(watchIndices[iter.key()]);
|
||||
}
|
||||
|
||||
rio.watchIndices() = newWatchIndices;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::Time::findWatch
|
||||
(
|
||||
const labelList& watchIndices,
|
||||
const fileName& fName
|
||||
) const
|
||||
{
|
||||
forAll(watchIndices, i)
|
||||
{
|
||||
if (getFile(watchIndices[i]) == fName)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::Time::addTimeWatch(const fileName& fName) const
|
||||
{
|
||||
return monitorPtr_().addWatch(fName);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Time::removeWatch(const label watchIndex) const
|
||||
{
|
||||
return monitorPtr_().removeWatch(watchIndex);
|
||||
}
|
||||
|
||||
const Foam::fileName& Foam::Time::getFile(const label watchIndex) const
|
||||
{
|
||||
return monitorPtr_().getFile(watchIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::fileMonitor::fileState Foam::Time::getState(const label watchIndex) const
|
||||
{
|
||||
return monitorPtr_().getState(watchIndex);
|
||||
}
|
||||
|
||||
|
||||
void Foam::Time::setUnmodified(const label watchIndex) const
|
||||
{
|
||||
monitorPtr_().setUnmodified(watchIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::Time::timeName(const scalar t, const int precision)
|
||||
{
|
||||
std::ostringstream buf;
|
||||
@ -806,26 +716,22 @@ Foam::word Foam::Time::findInstancePath
|
||||
const instant& t
|
||||
) const
|
||||
{
|
||||
// Read directory entries into a list
|
||||
fileNameList dirEntries(readDir(directory, fileName::DIRECTORY));
|
||||
// Simplified version: use findTimes (readDir + sort). The expensive
|
||||
// bit is the readDir, not the sorting. Tbd: avoid calling findInstancePath
|
||||
// from filePath.
|
||||
|
||||
forAll(dirEntries, i)
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
// Note:
|
||||
// - times will include constant (with value 0) as first element.
|
||||
// For backwards compatibility make sure to find 0 in preference
|
||||
// to constant.
|
||||
// - list is sorted so could use binary search
|
||||
|
||||
forAllReverse(timeDirs, i)
|
||||
{
|
||||
scalar timeValue;
|
||||
if (readScalar(dirEntries[i].c_str(), timeValue) && t.equal(timeValue))
|
||||
if (t.equal(timeDirs[i].value()))
|
||||
{
|
||||
return dirEntries[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (t.equal(0.0))
|
||||
{
|
||||
const word& constantName = constant();
|
||||
|
||||
// Looking for 0 or constant. 0 already checked above.
|
||||
if (isDir(directory/constantName))
|
||||
{
|
||||
return constantName;
|
||||
return timeDirs[i].name();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1030,6 +936,7 @@ void Foam::Time::setTime(const Time& t)
|
||||
value() = t.value();
|
||||
dimensionedScalar::name() = t.dimensionedScalar::name();
|
||||
timeIndex_ = t.timeIndex_;
|
||||
fileHandler().setTime(*this);
|
||||
}
|
||||
|
||||
|
||||
@ -1056,6 +963,7 @@ void Foam::Time::setTime(const instant& inst, const label newIndex)
|
||||
timeDict.readIfPresent("deltaT", deltaT_);
|
||||
timeDict.readIfPresent("deltaT0", deltaT0_);
|
||||
timeDict.readIfPresent("index", timeIndex_);
|
||||
fileHandler().setTime(*this);
|
||||
}
|
||||
|
||||
|
||||
@ -1070,6 +978,7 @@ void Foam::Time::setTime(const scalar newTime, const label newIndex)
|
||||
value() = newTime;
|
||||
dimensionedScalar::name() = timeName(timeToUserTime(newTime));
|
||||
timeIndex_ = newIndex;
|
||||
fileHandler().setTime(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user