openfoam/src/OpenFOAM/global/fileOperations/collatedFileOperation/hostCollatedFileOperation.H
Mark Olesen 9711b7f1b9 ENH: more consistent single-ownership when swapping fileHandlers
- make fileHandler deletion mechanism more
  transparent by providing a nullptr signature. A nullptr parameter
  is already being used in the argList destructor for shutdown, but that
  relied on an implicit conversion to autoPtr to trigger things.

- improved handling of file handler replacement.

  Previously had a very basic check on old vs new handlers using their
  type() values (string comparison!!), which would unfortunately
  prevent proper swapping of the contents.
  Check the actual pointers instead.

  As part of the change, treat any empty autoPtr as no-op instead of as
  deletion (which is handled explicitly as nullptr instead).

  In addition to making the internal logic simpler, it means that the
  current file handler always changes to a valid state without
  inadvertently removing everything and falling back to creating a new
  default handler (again).

  This handling of no-ops also simplifies call code. For example,

  <code>
      autoPtr<fileHandler> oldHandler;
      autoPtr<fileHandler> writeHandler;
      word handlerName;

      if (arg.readIfPresent("writeHandler", handlerName))
      {
          writeHandler = fileOperation::New(handlerName);
      }

      oldHandler = fileHandler(std::move(writeHandler));

      ... do something

      writeHandler = fileHandler(std::move(oldHandler));
  </code>

  If the "writeHandler" is not specified, each call is a no-op.
  If it is specified, the handlers are swapped out each time.

- the management of the fileHandler communicators is now encapsulated
  privately (managedComm_) with the final layer being responsible for
  cleaning up after itself. This makes delegation/inheritance clearer
  and avoids the risk of freeing an MPI communicator twice.

STYLE: uniformFile static check relocated to fileOperation layer
2022-12-01 12:18:38 +00:00

145 lines
4.3 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenFOAM Foundation
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fileOperations::hostCollatedFileOperation
Description
Version of collatedFileOperation with multiple read/write ranks.
In parallel it will assume ranks are sorted according to hostname
and the lowest rank per hostname will be the IO rank. The output directories
will get a unique name processors\<N\>_\<low\>-\<high\> where N is the
overall number of processors and low and high is the range of ranks
contained in the files. Each of these subsets uses its own communicator.
Instead of using the hostnames the IO ranks can be assigned using the
FOAM_IORANKS environment variable (also when running non-parallel), e.g.
when decomposing into 4:
FOAM_IORANKS='(0 2)' decomposePar -fileHandler hostCollated
will generate
processors4_0-1/
containing data for processors 0 to 1
processors4_2-3/
containing data for processors 2 to 3
See also
collatedFileOperation
SourceFiles
hostCollatedFileOperation.C
\*---------------------------------------------------------------------------*/
#ifndef fileOperations_hostCollatedFileOperation_H
#define fileOperations_hostCollatedFileOperation_H
#include "collatedFileOperation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileOperations
{
/*---------------------------------------------------------------------------*\
Class hostCollatedFileOperation Declaration
\*---------------------------------------------------------------------------*/
class hostCollatedFileOperation
:
public collatedFileOperation
{
// Private Data
//- Communicator allocated/managed by us
label managedComm_;
// Private Member Functions
//- Any initialisation steps after constructing
void init(bool verbose);
//- Get the list of processors part of this set
static labelList subRanks(const label n);
public:
//- Runtime type information
TypeName("hostCollated");
// Constructors
//- Default construct
explicit hostCollatedFileOperation(const bool verbose);
//- Destructor
virtual ~hostCollatedFileOperation();
};
/*---------------------------------------------------------------------------*\
Class hostCollatedFileOperationInitialise Declaration
\*---------------------------------------------------------------------------*/
class hostCollatedFileOperationInitialise
:
public collatedFileOperationInitialise
{
public:
// Constructors
//- Construct from components
hostCollatedFileOperationInitialise(int& argc, char**& argv)
:
collatedFileOperationInitialise(argc, argv)
{}
//- Destructor
virtual ~hostCollatedFileOperationInitialise() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileOperations
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //