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 -------------------------------------------------------------------------------
10 License
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 
31 
32 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
33 
34 namespace Foam
35 {
36 namespace fileOperations
37 {
38  defineTypeNameAndDebug(hostUncollatedFileOperation, 0);
40  (
41  fileOperation,
42  hostUncollatedFileOperation,
43  word
44  );
46  (
47  fileOperation,
48  hostUncollatedFileOperation,
49  comm
50  );
51 
52  // Threaded MPI: not required
54  (
55  fileOperationInitialise,
56  fileOperationInitialise_unthreaded,
57  word,
58  hostUncollated
59  );
60 }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65 
66 namespace 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
82  commAndIORanks.second() = fileOperation::getGlobalHostIORanks();
83  }
84 
85  if (UPstream::parRun() && commAndIORanks.second().size() > 1)
86  {
87  // Multiple masters: ranks for my IO range
88  commAndIORanks.first() = UPstream::allocateCommunicator
89  (
91  fileOperation::subRanks(commAndIORanks.second())
92  );
93  }
94 
95  return commAndIORanks;
96 }
97 
98 } // End namespace Foam
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
103 void Foam::fileOperations::hostUncollatedFileOperation::init(bool verbose)
104 {
105  verbose = (verbose && Foam::infoDetailLevel > 0);
106 
107  if (verbose)
108  {
109  DetailInfo
110  << "I/O : " << this->type() << nl;
111 
112  if (ioRanks_.size())
113  {
115  }
116  }
117 }
118 
119 
121 (
122  bool verbose
123 )
124 :
125  masterUncollatedFileOperation
126  (
127  getCommPattern(),
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
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.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
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.
hostUncollatedFileOperation(bool verbose=false)
Default construct.
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
addNamedToRunTimeSelectionTable(fileOperationInitialise, fileOperationInitialise_collated, word, collated)
#define DetailInfo
Definition: evalEntry.C:30
static Tuple2< label, labelList > getCommPattern()
static labelRange subRanks(const labelUList &mainIOranks)
Get (contiguous) range/bounds of ranks addressed within the given main io-ranks.
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:521
void printRanks() const
Helper: output which ranks are IO.
const T2 & second() const noexcept
Access the second element.
Definition: Tuple2.H:142
const labelList ioRanks_
The list of IO ranks (global ranks)
virtual void storeComm() const
Transfer ownership of communicator to this fileOperation. Use with caution.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
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
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
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.