Loading...
Searching...
No Matches
hostUncollatedFileOperation.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) 2022-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
32/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
33
34namespace Foam
35{
36namespace fileOperations
37{
40 (
43 word
44 );
46 (
49 comm
50 );
51
52 // Threaded MPI: not required
54 (
57 word,
58 hostUncollated
59 );
60}
61}
62
64// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68
69// Construction helper: self/world/local communicator and IO ranks
71{
72 // Default is COMM_WORLD (single master)
73 Tuple2<label, labelList> commAndIORanks
74 (
77 );
78
79 if (commAndIORanks.second().empty())
80 {
81 // Default: one master per host
83 }
84
85 if (UPstream::parRun() && commAndIORanks.second().size() > 1)
86 {
87 // Multiple masters: ranks for my IO range
88 commAndIORanks.first() = UPstream::newCommunicator
89 (
91 fileOperation::subRanks(commAndIORanks.second())
92 );
93 }
94
95 return commAndIORanks;
96}
97
98} // End namespace Foam
99
100
101// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102
103void Foam::fileOperations::hostUncollatedFileOperation::init(bool verbose)
104{
105 verbose = (verbose && Foam::infoDetailLevel > 0);
106
107 if (verbose)
108 {
110 << "I/O : " << this->type() << nl;
111
112 if (ioRanks_.size())
115 }
116 }
117}
118
119
121(
122 bool verbose
123)
124:
125 masterUncollatedFileOperation
126 (
128 false, // distributedRoots
129 false // verbose
130 ),
131 managedComm_(getManagedComm(comm_)) // Possibly locally allocated
132{
133 init(verbose);
134}
135
136
138(
139 const Tuple2<label, labelList>& commAndIORanks,
140 const bool distributedRoots,
141 bool verbose
142)
143:
145 (
146 commAndIORanks,
147 distributedRoots,
148 false // verbose
149 ),
150 managedComm_(-1) // Externally managed
151{
152 init(verbose);
153}
154
155
157{
158 // From externally -> locally managed
159 managedComm_ = getManagedComm(comm_);
160}
161
162
163// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164
167{
168 // Wait for any outstanding file operations
169 flush();
170
171 UPstream::freeCommunicator(managedComm_);
172}
173
174
175// ************************************************************************* //
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
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
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...
void printRanks() const
Helper: output which ranks are IO.
static labelList getGlobalHostIORanks()
Get list of global IO master ranks based on the hostname. It is assumed that each host range is conti...
A fileOperation initialiser for unthreaded file handlers.
Version of masterUncollated with host-based IO ranks.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
hostUncollatedFileOperation(bool verbose=false)
Default construct.
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
masterUncollatedFileOperation(bool verbose=false)
Default construct.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
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
#define DetailInfo
Definition evalEntry.C:30
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()
Ostream & flush(Ostream &os)
Flush stream.
Definition Ostream.H:509
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50