Loading...
Searching...
No Matches
hostCollatedFileOperation.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2018 OpenFOAM Foundation
9 Copyright (C) 2021-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
32/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
33
34namespace Foam
35{
36namespace fileOperations
37{
40 (
43 word
44 );
46 (
49 comm
50 );
51
52 // Threaded MPI: depending on buffering
54 (
57 word,
58 hostCollated
59 );
60}
61}
63
64// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68// Construction helper: self/world/local communicator and IO ranks
70{
71 // Default is COMM_WORLD (single master)
72 Tuple2<label, labelList> commAndIORanks
73 (
76 );
77
78 if (commAndIORanks.second().empty())
79 {
80 // Default: one master per host
82 }
83
84 if (UPstream::parRun() && commAndIORanks.second().size() > 1)
85 {
86 // Multiple masters: ranks for my IO range
87 commAndIORanks.first() = UPstream::newCommunicator
88 (
90 fileOperation::subRanks(commAndIORanks.second())
91 );
92 }
93
94 return commAndIORanks;
95}
96
97} // End namespace Foam
98
99
100// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101
102void Foam::fileOperations::hostCollatedFileOperation::init(bool verbose)
103{
104 verbose = (verbose && Foam::infoDetailLevel > 0);
105
106 if (verbose)
107 {
108 this->printBanner(ioRanks_.size());
109 }
110}
111
112
114(
115 bool verbose
116)
117:
118 collatedFileOperation
119 (
121 false, // distributedRoots
122 false // verbose
123 ),
124 managedComm_(getManagedComm(comm_)) // Possibly locally allocated
125{
126 init(verbose);
127}
128
129
131(
132 const Tuple2<label, labelList>& commAndIORanks,
133 const bool distributedRoots,
134 bool verbose
135)
136:
138 (
139 commAndIORanks,
140 distributedRoots,
141 false // verbose
142 ),
143 managedComm_(-1) // Externally managed
144{
145 init(verbose);
146}
147
148
150{
151 // From externally -> locally managed
152 managedComm_ = getManagedComm(comm_);
153}
154
155
156// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
157
159{
160 UPstream::freeCommunicator(managedComm_);
161}
162
163
164// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
const T1 & first() const noexcept
Access the first element.
Definition Tuple2.H:132
const T2 & second() const noexcept
Access the second element.
Definition Tuple2.H:142
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
Definition UPstream.H:1669
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition UPstream.H:1069
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
Definition UPstream.C:272
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
Definition UPstream.C:622
An encapsulation of filesystem-related operations.
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
static label getManagedComm(const label communicator)
Construction helper: check for locally allocated communicator.
const labelList ioRanks_
The list of IO ranks (global ranks).
label comm_
Communicator to use.
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
static labelList getGlobalHostIORanks()
Get list of global IO master ranks based on the hostname. It is assumed that each host range is conti...
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
collatedFileOperation(bool verbose=false)
Default construct.
void printBanner(const bool withRanks=false) const
Print banner information, optionally with io ranks.
A fileOperation initialiser for collated file handlers. Requires threading for non-zero maxThreadFile...
Version of collatedFileOperation with multiple read/write ranks.
hostCollatedFileOperation(bool verbose=false)
Default construct.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
Namespace for implementations of a fileOperation.
Definition regIOobject.H:60
Namespace for OpenFOAM.
int infoDetailLevel
Global for selective suppression of Info output.
static Tuple2< label, labelList > getCommPattern()