ENH: simplify inheritances for fileOperationInitialise

- can be broadly categorised as 'unthreaded'
  or 'collated' (threading requirement depends on buffering)
  without other opaque inheritances.

CONFIG: add hostUncollated to bash completion prompt
This commit is contained in:
Mark Olesen 2023-06-15 09:37:17 +02:00
parent 66a2894da8
commit b2217d5e6b
14 changed files with 84 additions and 209 deletions

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2017-2022 OpenCFD Ltd.
# Copyright (C) 2017-2023 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -146,7 +146,7 @@ _of_complete_()
COMPREPLY=($(compgen -W "$choices" -- ${cur}))
;;
-fileHandler)
choices="collated uncollated hostCollated masterUncollated"
choices="collated uncollated hostCollated hostUncollated masterUncollated"
COMPREPLY=($(compgen -W "$choices" -- ${cur}))
;;
*)

View File

@ -21,7 +21,7 @@ $(fileOps)/fileOperation/fileOperation.C
$(fileOps)/fileOperation/fileOperationBroadcast.C
$(fileOps)/fileOperation/fileOperationNew.C
$(fileOps)/fileOperation/fileOperationRanks.C
$(fileOps)/fileOperationInitialise/fileOperationInitialise.C
$(fileOps)/fileOperation/fileOperationInitialise.C
$(fileOps)/dummyFileOperation/dummyFileOperation.C
$(fileOps)/uncollatedFileOperation/uncollatedFileOperation.C
$(fileOps)/masterUncollatedFileOperation/masterUncollatedFileOperation.C

View File

@ -68,11 +68,11 @@ namespace fileOperations
collatedFileOperation::maxThreadFileBufferSize
);
// Mark as needing threaded mpi
// Threaded MPI: depending on buffering
addNamedToRunTimeSelectionTable
(
fileOperationInitialise,
collatedFileOperationInitialise,
fileOperationInitialise_collated,
word,
collated
);

View File

@ -50,6 +50,7 @@ SourceFiles
#define Foam_fileOperations_collatedFileOperation_H
#include "masterUncollatedFileOperation.H"
#include "fileOperationInitialise.H"
#include "OFstreamCollator.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -173,32 +174,33 @@ public:
/*---------------------------------------------------------------------------*\
Class collatedFileOperationInitialise Declaration
Class fileOperationInitialise_collated Declaration
\*---------------------------------------------------------------------------*/
//! Internal class only
class collatedFileOperationInitialise
//- A fileOperation initialiser for collated file handlers.
//- Requires threading for non-zero maxThreadFileBufferSize.
class fileOperationInitialise_collated
:
public masterUncollatedFileOperationInitialise
public fileOperationInitialise
{
public:
// Constructors
//- Construct from components
collatedFileOperationInitialise(int& argc, char**& argv)
fileOperationInitialise_collated(int& argc, char**& argv)
:
masterUncollatedFileOperationInitialise(argc, argv)
fileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~collatedFileOperationInitialise() = default;
virtual ~fileOperationInitialise_collated() = default;
// Member Functions
//- Requires threading for non-zero maxThreadFileBufferSize
//- The (MPI) threading requirement depends on buffering
virtual bool needsThreading() const
{
return (collatedFileOperation::maxThreadFileBufferSize > 0);

View File

@ -49,12 +49,11 @@ namespace fileOperations
comm
);
// Register initialisation routine. Signals need for threaded mpi and
// handles command line arguments
// Threaded MPI: depending on buffering
addNamedToRunTimeSelectionTable
(
fileOperationInitialise,
hostCollatedFileOperationInitialise,
fileOperationInitialise_collated,
word,
hostCollated
);

View File

@ -129,31 +129,6 @@ public:
};
/*---------------------------------------------------------------------------*\
Class hostCollatedFileOperationInitialise Declaration
\*---------------------------------------------------------------------------*/
//! Internal class only
class hostCollatedFileOperationInitialise
:
public collatedFileOperationInitialise
{
public:
// Constructors
//- Construct from components
hostCollatedFileOperationInitialise(int& argc, char**& argv)
:
collatedFileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~hostCollatedFileOperationInitialise() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations

View File

@ -50,37 +50,44 @@ Foam::fileOperations::fileOperationInitialise::fileOperationInitialise
char**& argv
)
{
// Check for -ioRanks, which requires an argument
// Check for -ioRanks: requires an argument
int index = -1;
for (int argi = 1; argi < argc; ++argi)
{
if (argv[argi][0] == '-')
const char *optName = argv[argi];
if (optName[0] == '-')
{
const char *optName = &argv[argi][1];
++optName; // Looks like an option, skip leading '-'
bool emitErrorMessage = false;
if (strcmp(optName, "ioRanks") == 0)
{
// Requires a parameter
if (argi < argc-1)
{
index = argi;
Foam::setEnv("FOAM_IORANKS", argv[argi+1], true);
++argi;
Foam::setEnv("FOAM_IORANKS", argv[argi], true);
break;
}
else
{
// No argument to -ioRanks.
// Give error message as in argList.
// Slight problem: Pstream not yet initialised so
// - no master-only output
// - no early exit
Info<< nl
<< "Error: option '-ioRanks' requires a list of"
" IO ranks as argument" << nl << nl;
//UPstream::exit(1); // works for serial and parallel
emitErrorMessage = true;
}
}
if (emitErrorMessage)
{
// Missing argument: emit message but not exit or
// FatalError since Pstream etc are not yet initialised
Info<< nl
<< "Error: option '-" << optName
<< "' requires an argument" << nl << nl;
//NO: UPstream::exit(1); // works for serial and parallel
}
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,8 +34,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef fileOperationInitialise_H
#define fileOperationInitialise_H
#ifndef Foam_fileOperations_fileOperationInitialise_H
#define Foam_fileOperations_fileOperationInitialise_H
#include "runTimeSelectionTables.H"
@ -79,7 +80,7 @@ public:
// Selectors
//- Select type
//- Select initialisation type
static autoPtr<fileOperationInitialise> New
(
const word& type, int& argc, char**& argv
@ -92,11 +93,42 @@ public:
// Member Functions
//- Threading required?
//- Requires (MPI) threading?
virtual bool needsThreading() const = 0;
};
/*---------------------------------------------------------------------------*\
Class fileOperationInitialise_unthreaded Declaration
\*---------------------------------------------------------------------------*/
//- A fileOperation initialiser for unthreaded file handlers.
class fileOperationInitialise_unthreaded
:
public fileOperationInitialise
{
public:
// Constructors
//- Construct from components
fileOperationInitialise_unthreaded(int& argc, char**& argv)
:
fileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~fileOperationInitialise_unthreaded() = default;
// Member Functions
//- No (MPI) threading required
virtual bool needsThreading() const { return false; }
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations

View File

@ -1,88 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::unthreadedInitialise
Description
A fileOperation initialiser for unthreaded file handlers
\*---------------------------------------------------------------------------*/
#ifndef unthreadedInitialise_H
#define unthreadedInitialise_H
#include "fileOperationInitialise.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileOperations
{
/*---------------------------------------------------------------------------*\
Class unthreadedInitialise Declaration
\*---------------------------------------------------------------------------*/
class unthreadedInitialise
:
public fileOperationInitialise
{
public:
// Constructors
//- Construct from components
unthreadedInitialise(int& argc, char**& argv)
:
fileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~unthreadedInitialise() = default;
// Member Functions
//- No threading required
virtual bool needsThreading() const
{
return false;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/
#include "masterUncollatedFileOperation.H"
#include "fileOperationInitialise.H"
#include "addToRunTimeSelectionTable.H"
#include "Pstream.H"
#include "Time.H"
@ -38,7 +39,6 @@ License
#include "registerSwitch.H"
#include "dummyISstream.H"
#include "SubList.H"
#include "unthreadedInitialise.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -71,11 +71,11 @@ namespace fileOperations
masterUncollatedFileOperation::maxMasterFileBufferSize
);
// Mark as not needing threaded mpi
// Threaded MPI: not required
addNamedToRunTimeSelectionTable
(
fileOperationInitialise,
masterUncollatedFileOperationInitialise,
fileOperationInitialise_unthreaded,
word,
masterUncollated
);

View File

@ -66,8 +66,6 @@ Description
#include "OSspecific.H"
#include "HashPtrTable.H"
#include "DynamicList.H"
#include "List.H"
#include "unthreadedInitialise.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -787,31 +785,6 @@ public:
};
/*---------------------------------------------------------------------------*\
Class masterUncollatedFileOperationInitialise Declaration
\*---------------------------------------------------------------------------*/
//! Internal class only
class masterUncollatedFileOperationInitialise
:
public unthreadedInitialise
{
public:
// Constructors
//- Construct from components
masterUncollatedFileOperationInitialise(int& argc, char**& argv)
:
unthreadedInitialise(argc, argv)
{}
//- Destructor
virtual ~masterUncollatedFileOperationInitialise() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations

View File

@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "hostUncollatedFileOperation.H"
#include "fileOperationInitialise.H"
#include "addToRunTimeSelectionTable.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -48,12 +49,11 @@ namespace fileOperations
comm
);
// Register initialisation routine. Signals need for threaded mpi and
// handles command line arguments
// Threaded MPI: not required
addNamedToRunTimeSelectionTable
(
fileOperationInitialise,
hostUncollatedFileOperationInitialise,
fileOperationInitialise_unthreaded,
word,
hostUncollated
);

View File

@ -94,31 +94,6 @@ public:
};
/*---------------------------------------------------------------------------*\
Class hostUncollatedFileOperationInitialise Declaration
\*---------------------------------------------------------------------------*/
//! Internal class only
class hostUncollatedFileOperationInitialise
:
public masterUncollatedFileOperationInitialise
{
public:
// Constructors
//- Construct from components
hostUncollatedFileOperationInitialise(int& argc, char**& argv)
:
masterUncollatedFileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~hostUncollatedFileOperationInitialise() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations

View File

@ -27,12 +27,12 @@ License
\*---------------------------------------------------------------------------*/
#include "uncollatedFileOperation.H"
#include "fileOperationInitialise.H"
#include "Time.H"
#include "Fstream.H"
#include "addToRunTimeSelectionTable.H"
#include "decomposedBlockData.H"
#include "dummyISstream.H"
#include "unthreadedInitialise.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -54,11 +54,11 @@ namespace fileOperations
comm
);
// Mark as not needing threaded mpi
// Threaded MPI: not required
addNamedToRunTimeSelectionTable
(
fileOperationInitialise,
unthreadedInitialise,
fileOperationInitialise_unthreaded,
word,
uncollated
);