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:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -62,9 +62,19 @@ Usage
|
||||
#include "cellIOList.H"
|
||||
#include "IOobjectList.H"
|
||||
#include "IOPtrList.H"
|
||||
#include "cloud.H"
|
||||
#include "labelIOField.H"
|
||||
#include "scalarIOField.H"
|
||||
#include "sphericalTensorIOField.H"
|
||||
#include "symmTensorIOField.H"
|
||||
#include "tensorIOField.H"
|
||||
#include "labelFieldIOField.H"
|
||||
#include "vectorFieldIOField.H"
|
||||
#include "Cloud.H"
|
||||
#include "passiveParticle.H"
|
||||
#include "fieldDictionary.H"
|
||||
|
||||
#include "writeMeshObject.H"
|
||||
#include "fieldDictionary.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -143,7 +153,8 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
|
||||
(
|
||||
IOstream::ASCII,
|
||||
IOstream::currentVersion,
|
||||
runTime.writeCompression()
|
||||
runTime.writeCompression(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@ -151,6 +162,75 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
|
||||
}
|
||||
|
||||
|
||||
// Reduction for non-empty strings
|
||||
class uniqueEqOp
|
||||
{
|
||||
public:
|
||||
void operator()(stringList& x, const stringList& y) const
|
||||
{
|
||||
stringList newX(x.size()+y.size());
|
||||
label n = 0;
|
||||
forAll(x, i)
|
||||
{
|
||||
if (!x[i].empty())
|
||||
{
|
||||
newX[n++] = x[i];
|
||||
}
|
||||
}
|
||||
forAll(y, i)
|
||||
{
|
||||
if (!y[i].empty() && findIndex(x, y[i]) == -1)
|
||||
{
|
||||
newX[n++] = y[i];
|
||||
}
|
||||
}
|
||||
newX.setSize(n);
|
||||
x.transfer(newX);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
bool writeOptionalMeshObject
|
||||
(
|
||||
const word& name,
|
||||
const fileName& meshDir,
|
||||
Time& runTime,
|
||||
const bool valid
|
||||
)
|
||||
{
|
||||
IOobject io
|
||||
(
|
||||
name,
|
||||
runTime.timeName(),
|
||||
meshDir,
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
|
||||
bool writeOk = false;
|
||||
|
||||
bool haveFile = io.typeHeaderOk<IOField<label>>(false);
|
||||
|
||||
// Make sure all know if there is a valid class name
|
||||
stringList classNames(1, io.headerClassName());
|
||||
combineReduce(classNames, uniqueEqOp());
|
||||
|
||||
// Check for correct type
|
||||
if (classNames[0] == T::typeName)
|
||||
{
|
||||
Info<< " Reading " << classNames[0]
|
||||
<< " : " << name << endl;
|
||||
T meshObject(io, valid && haveFile);
|
||||
|
||||
Info<< " Writing " << name << endl;
|
||||
writeOk = meshObject.regIOobject::write(valid && haveFile);
|
||||
}
|
||||
|
||||
return writeOk;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -183,6 +263,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
#include "createTime.H"
|
||||
// Optional mesh (used to read Clouds)
|
||||
autoPtr<polyMesh> meshPtr;
|
||||
|
||||
const bool enableEntries = args.optionFound("enableFunctionEntries");
|
||||
if (enableEntries)
|
||||
@ -221,11 +303,24 @@ int main(int argc, char *argv[])
|
||||
Info<< "Time = " << runTime.timeName() << endl;
|
||||
|
||||
// Convert all the standard mesh files
|
||||
writeMeshObject<cellCompactIOList>("cells", meshDir, runTime);
|
||||
writeMeshObject<cellCompactIOList, cellIOList>
|
||||
(
|
||||
"cells",
|
||||
meshDir,
|
||||
runTime
|
||||
);
|
||||
writeMeshObject<labelIOList>("owner", meshDir, runTime);
|
||||
writeMeshObject<labelIOList>("neighbour", meshDir, runTime);
|
||||
writeMeshObject<faceCompactIOList>("faces", meshDir, runTime);
|
||||
writeMeshObject<faceCompactIOList, faceIOList>
|
||||
(
|
||||
"faces",
|
||||
meshDir,
|
||||
runTime
|
||||
);
|
||||
writeMeshObject<pointIOField>("points", meshDir, runTime);
|
||||
// Write boundary in ascii. This is only needed for fileHandler to
|
||||
// kick in. Should not give problems since always writing ascii.
|
||||
writeZones("boundary", meshDir, runTime);
|
||||
writeMeshObject<labelIOList>("pointProcAddressing", meshDir, runTime);
|
||||
writeMeshObject<labelIOList>("faceProcAddressing", meshDir, runTime);
|
||||
writeMeshObject<labelIOList>("cellProcAddressing", meshDir, runTime);
|
||||
@ -279,22 +374,196 @@ int main(int argc, char *argv[])
|
||||
|| headerClassName == pointSphericalTensorField::typeName
|
||||
|| headerClassName == pointSymmTensorField::typeName
|
||||
|| headerClassName == pointTensorField::typeName
|
||||
|
||||
|| headerClassName == volScalarField::Internal::typeName
|
||||
|| headerClassName == volVectorField::Internal::typeName
|
||||
|| headerClassName == volSphericalTensorField::Internal::typeName
|
||||
|| headerClassName == volSymmTensorField::Internal::typeName
|
||||
|| headerClassName == volTensorField::Internal::typeName
|
||||
)
|
||||
{
|
||||
Info<< " Reading " << headerClassName
|
||||
<< " : " << iter()->name() << endl;
|
||||
|
||||
fieldDictionary fDict
|
||||
(
|
||||
*iter(),
|
||||
headerClassName
|
||||
);
|
||||
fieldDictionary fDict(*iter(), headerClassName);
|
||||
|
||||
Info<< " Writing " << iter()->name() << endl;
|
||||
fDict.regIOobject::write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check for lagrangian
|
||||
stringList lagrangianDirs
|
||||
(
|
||||
1,
|
||||
fileHandler().filePath
|
||||
(
|
||||
runTime.timePath()
|
||||
/ regionPrefix
|
||||
/ cloud::prefix
|
||||
)
|
||||
);
|
||||
|
||||
combineReduce(lagrangianDirs, uniqueEqOp());
|
||||
|
||||
if (!lagrangianDirs.empty())
|
||||
{
|
||||
if (meshPtr.valid())
|
||||
{
|
||||
meshPtr().readUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Create polyMesh for time = "
|
||||
<< runTime.timeName() << endl;
|
||||
|
||||
meshPtr.reset
|
||||
(
|
||||
new polyMesh
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
polyMesh::defaultRegion,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
Foam::IOobject::MUST_READ
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
stringList cloudDirs
|
||||
(
|
||||
fileHandler().readDir
|
||||
(
|
||||
lagrangianDirs[0],
|
||||
fileName::DIRECTORY
|
||||
)
|
||||
);
|
||||
|
||||
combineReduce(cloudDirs, uniqueEqOp());
|
||||
|
||||
forAll(cloudDirs, i)
|
||||
{
|
||||
fileName dir(cloud::prefix/cloudDirs[i]);
|
||||
|
||||
Cloud<passiveParticle> parcels(meshPtr(), cloudDirs[i], false);
|
||||
|
||||
parcels.writeObject
|
||||
(
|
||||
runTime.writeFormat(),
|
||||
IOstream::currentVersion,
|
||||
runTime.writeCompression(),
|
||||
parcels.size()
|
||||
);
|
||||
|
||||
|
||||
// Do local scan for valid cloud objects
|
||||
IOobjectList sprayObjs(runTime, runTime.timeName(), dir);
|
||||
|
||||
// Combine with all other cloud objects
|
||||
stringList sprayFields(sprayObjs.sortedToc());
|
||||
combineReduce(sprayFields, uniqueEqOp());
|
||||
|
||||
forAll(sprayFields, fieldi)
|
||||
{
|
||||
const word& name = sprayFields[fieldi];
|
||||
|
||||
// Note: try the various field types. Make sure to
|
||||
// exit once sucessful conversion to avoid re-read
|
||||
// converted file.
|
||||
|
||||
if
|
||||
(
|
||||
name == "positions"
|
||||
|| name == "origProcId"
|
||||
|| name == "origId"
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool writeOk = writeOptionalMeshObject<labelIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<scalarIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<vectorIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<sphericalTensorIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<symmTensorIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<tensorIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<labelFieldIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
if (writeOk) continue;
|
||||
|
||||
writeOk = writeOptionalMeshObject<vectorFieldIOField>
|
||||
(
|
||||
name,
|
||||
dir,
|
||||
runTime,
|
||||
parcels.size() > 0
|
||||
);
|
||||
|
||||
if (!writeOk)
|
||||
{
|
||||
Info<< " Failed converting " << name << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -39,7 +39,7 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
template<class Type, class CheckType = Type>
|
||||
inline bool writeMeshObject
|
||||
(
|
||||
const word& name,
|
||||
@ -61,7 +61,7 @@ inline bool writeMeshObject
|
||||
|
||||
bool writeOk = false;
|
||||
|
||||
if (io.typeHeaderOk<T>(false))
|
||||
if (io.typeHeaderOk<T>(true, true, false))
|
||||
{
|
||||
Info<< " Reading " << io.headerClassName()
|
||||
<< " : " << name << endl;
|
||||
@ -71,15 +71,15 @@ inline bool writeMeshObject
|
||||
word oldTypeName;
|
||||
if (disableHeaderChecking)
|
||||
{
|
||||
oldTypeName = T::typeName;
|
||||
const_cast<word&>(T::typeName) = word::null;
|
||||
oldTypeName = Type::typeName;
|
||||
const_cast<word&>(Type::typeName) = word::null;
|
||||
}
|
||||
|
||||
T meshObject(io);
|
||||
Type meshObject(io);
|
||||
|
||||
if (disableHeaderChecking)
|
||||
{
|
||||
const_cast<word&>(T::typeName) = oldTypeName;
|
||||
const_cast<word&>(Type::typeName) = oldTypeName;
|
||||
// Fake type back to what was in field
|
||||
const_cast<word&>(meshObject.type()) = io.headerClassName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user