Files
OpenFOAM-12/applications/utilities/postProcessing/graphics/ensightFoamReader/USERD_set_filenames.H
Henry Weller 7c301dbff4 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.
2017-07-07 11:39:56 +01:00

210 lines
4.7 KiB
C

//======================================================================
// Setting filenames
//======================================================================
int USERD_set_filenames
(
char filename_1[],
char filename_2[],
char the_path[],
int swapbytes
)
{
#ifdef ENSIGHTDEBUG
Info<< "Entering: USERD_set_filenames" << endl << flush;
#endif
char tmp[100];
label lRoot = strlen(the_path);
label lCase = strlen(filename_1);
bool cleared = false;
while (!cleared)
{
lRoot = strlen(the_path);
lCase = strlen(filename_1);
// remove the last '/' from rootDir
if (the_path[lRoot-1] == '/')
{
the_path[lRoot-1] = '\0';
}
else
{
cleared = true;
}
}
rootDir = the_path;
// the path is pre-pended to filename_1
// 1 is the 'Geometry' : 2 the 'Result' which is null here
// since two_field is FALSE
for (label i=0; i<lCase-lRoot;i++)
{
tmp[i] = filename_1[i+1+lRoot];
}
caseDir = tmp;
if (!isDir(rootDir/caseDir))
{
Info<< rootDir/caseDir << " is not a valid directory."
<< endl;
return Z_ERR;
}
// construct the global pointers to the database and mesh
delete meshPtr;
delete runTimePtr;
runTimePtr = new Time
(
Time::controlDictName,
rootDir,
caseDir
);
Time& runTime = *runTimePtr;
meshPtr = new fvMesh
(
IOobject
(
fvMesh::defaultRegion,
runTime.timeName(),
runTime
)
);
// set the available number of time-steps
timeDirs = Foam::Time::findTimes(rootDir/caseDir);
Num_time_steps = timeDirs.size() - 1;
nPatches = meshPtr->boundaryMesh().size();
// set the number of fields and store their names
// a valid field must exist for all time-steps
runTime.setTime(timeDirs.last(), timeDirs.size()-1);
IOobjectList objects(*meshPtr, runTime.timeName());
fieldNames = objects.names();
// because of the spray being a 'field' ...
// get the availabe number of variables and
// check for type (scalar/vector/tensor)
label nVar = 0;
wordList scalars = objects.names(scalarName);
forAll(fieldNames, n)
{
bool isitScalar = false;
forAll(scalars,i)
{
if (fieldNames[n] == scalars[i])
{
isitScalar = true;
var2field[nVar++] = n;
}
}
isScalar[n] = isitScalar;
}
wordList vectors = objects.names(vectorName);
forAll(fieldNames, n)
{
bool isitVector = false;
forAll(vectors,i)
{
if (fieldNames[n] == vectors[i])
{
isitVector = true;
var2field[nVar++] = n;
}
}
isVector[n] = isitVector;
}
wordList tensors = objects.names(tensorName);
forAll(fieldNames, n)
{
bool isitTensor = false;
forAll(tensors,i)
{
if (fieldNames[n] == tensors[i])
{
isitTensor = true;
var2field[nVar++] = n;
}
}
isTensor[n] = isitTensor;
}
bool lagrangianNamesFound = false;
label n = 0;
while (!lagrangianNamesFound && n < Num_time_steps)
{
runTime.setTime(timeDirs[n+1], n+1);
Cloud<passiveParticle> lagrangian(*meshPtr, cloud::defaultName);
n++;
if (lagrangian.size())
{
lagrangianNamesFound = true;
}
}
IOobject sprayHeader
(
"positions",
runTime.timeName(),
cloud::prefix,
runTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
if (sprayHeader.typeHeaderOk<Cloud<passiveParticle>>(false))
{
Info<< "[Found lagrangian]" << endl;
delete sprayPtr;
sprayPtr = new Cloud<passiveParticle>(*meshPtr, cloud::defaultName);
IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix);
lagrangianScalarNames =
objects.names(sprayScalarFieldName);
lagrangianVectorNames =
objects.names(sprayVectorFieldName);
isSpray[fieldNames.size()] = true;
nSprayVariables += lagrangianScalarNames.size();
nSprayVariables += lagrangianVectorNames.size();
Num_unstructured_parts++;
}
Current_time_step = Num_time_steps;
runTime.setTime(timeDirs[Current_time_step], Current_time_step);
Num_variables = nVar + nSprayVariables;
Numparts_available =
Num_unstructured_parts + Num_structured_parts + nPatches;
#ifdef ENSIGHTDEBUG
Info<< "Leaving: USERD_set_filenames" << endl << flush;
#endif
return Z_OK;
}