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-2022 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
31#include "bitSet.H"
32
33/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
34
35namespace Foam
36{
37namespace fileOperations
38{
41 (
44 word
45 );
46
47 // Register initialisation routine. Signals need for threaded mpi and
48 // handles command line arguments
50 (
53 word,
54 hostCollated
55 );
56}
57}
58
59
60// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61
62Foam::labelList Foam::fileOperations::hostCollatedFileOperation::subRanks
63(
64 const label n
65)
66{
67 DynamicList<label> subRanks(64);
68
70 if (!mainRanks.empty())
71 {
72 if (!mainRanks.found(0))
73 {
75 << "Rank 0 (master) should be in the IO ranks. Currently "
76 << mainRanks << nl
77 << exit(FatalError);
78 }
79
80 // The lowest numbered rank is the IO rank
81 const bitSet isIOrank(n, mainRanks);
82
83 for (label proci = Pstream::myProcNo(); proci >= 0; --proci)
84 {
85 if (isIOrank[proci])
86 {
87 // Found my master. Collect all processors with same master
88 subRanks.append(proci);
89 for
90 (
91 label rank = proci+1;
92 rank < n && !isIOrank[rank];
93 ++rank
94 )
95 {
96 subRanks.append(rank);
97 }
98 break;
99 }
100 }
101 }
102 else
103 {
104 // Normal operation: one lowest rank per hostname is the writer
105 const string myHostName(hostName());
106
108 hosts[Pstream::myProcNo()] = myHostName;
110
111 // Collect procs with same hostname
112 forAll(hosts, proci)
113 {
114 if (hosts[proci] == myHostName)
115 {
116 subRanks.append(proci);
117 }
118 }
119 }
120 return subRanks;
121}
122
123
124// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125
127(
128 bool verbose
129)
130:
132 (
133 UPstream::allocateCommunicator
134 (
135 UPstream::worldComm,
136 subRanks(Pstream::nProcs())
137 ),
138 (Pstream::parRun() ? labelList() : ioRanks()), // processor dirs
139 typeName,
140 false // verbose
141 )
142{
143 if (verbose && Foam::infoDetailLevel > 0)
144 {
145 this->printBanner(ioRanks_.size());
146 }
147}
148
149
150// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
151
153{
154 if (comm_ != -1 && comm_ != UPstream::worldComm)
155 {
157 }
158}
159
160
161// ************************************************************************* //
label n
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.
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
Inter-processor communications stream.
Definition: Pstream.H:63
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Inter-processor communications stream.
Definition: UPstream.H:59
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:174
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:69
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
const labelList ioRanks_
Ranks of IO handlers.
void printBanner(const bool printRanks=false) const
Print banner information, optionally with io ranks.
Version of collatedFileOperation with multiple read/write ranks.
int myProcNo() const noexcept
Return processor number.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
string hostName()
Return the system's host name, as per hostname(1)
Definition: MSwindows.C:410
int infoDetailLevel
Global for selective suppression of Info output.
error FatalError
List< string > stringList
A List of strings.
Definition: stringList.H:58
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333