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 -------------------------------------------------------------------------------
11 License
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 
31 
32 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
33 
34 namespace Foam
35 {
36 namespace fileOperations
37 {
38  defineTypeNameAndDebug(hostCollatedFileOperation, 0);
40  (
41  fileOperation,
42  hostCollatedFileOperation,
43  word
44  );
46  (
47  fileOperation,
48  hostCollatedFileOperation,
49  comm
50  );
51 
52  // Threaded MPI: depending on buffering
54  (
55  fileOperationInitialise,
56  fileOperationInitialise_collated,
57  word,
58  hostCollated
59  );
60 }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65 
66 namespace 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
81  commAndIORanks.second() = fileOperation::getGlobalHostIORanks();
82  }
83 
84  if (UPstream::parRun() && commAndIORanks.second().size() > 1)
85  {
86  // Multiple masters: ranks for my IO range
87  commAndIORanks.first() = UPstream::allocateCommunicator
88  (
90  fileOperation::subRanks(commAndIORanks.second())
91  );
92  }
93 
94  return commAndIORanks;
95 }
96 
97 } // End namespace Foam
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
102 void 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  (
120  getCommPattern(),
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
hostCollatedFileOperation(bool verbose=false)
Default construct.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
static labelList getGlobalHostIORanks()
Get list of global IO master ranks based on the hostname. It is assumed that each host range is conti...
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
Definition: UPstream.C:565
int infoDetailLevel
Global for selective suppression of Info output.
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:409
Macros for easy insertion into run-time selection tables.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
void printBanner(const bool withRanks=false) const
Print banner information, optionally with io ranks.
addNamedToRunTimeSelectionTable(fileOperationInitialise, fileOperationInitialise_collated, word, collated)
static Tuple2< label, labelList > getCommPattern()
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
const T2 & second() const noexcept
Access the second element.
Definition: Tuple2.H:142
const labelList ioRanks_
The list of IO ranks (global ranks)
static labelList getGlobalIORanks()
Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master...
defineTypeNameAndDebug(collatedFileOperation, 0)
const T1 & first() const noexcept
Access the first element.
Definition: Tuple2.H:132
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
Definition: UPstream.C:258
Namespace for OpenFOAM.
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.