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 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 #include "bitSet.H"
32 
33 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
34 
35 namespace Foam
36 {
37 namespace fileOperations
38 {
39  defineTypeNameAndDebug(hostCollatedFileOperation, 0);
41  (
42  fileOperation,
43  hostCollatedFileOperation,
44  word
45  );
46 
47  // Register initialisation routine. Signals need for threaded mpi and
48  // handles command line arguments
50  (
52  hostCollatedFileOperationInitialise,
53  word,
54  hostCollated
55  );
56 }
57 }
58 
59 
60 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61 
62 Foam::labelList Foam::fileOperations::hostCollatedFileOperation::subRanks
63 (
64  const label n
65 )
66 {
67  DynamicList<label> subRanks(64);
68 
69  labelList mainRanks(fileOperation::ioRanks());
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 
107  stringList hosts(Pstream::nProcs());
108  hosts[Pstream::myProcNo()] = myHostName;
109  Pstream::gatherList(hosts);
110  Pstream::scatterList(hosts);
111 
112  // Collect procs with same hostname
113  forAll(hosts, proci)
114  {
115  if (hosts[proci] == myHostName)
116  {
117  subRanks.append(proci);
118  }
119  }
120  }
121  return subRanks;
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
128 (
129  bool verbose
130 )
131 :
133  (
135  (
137  subRanks(Pstream::nProcs())
138  ),
139  (Pstream::parRun() ? labelList() : ioRanks()), // processor dirs
140  typeName,
141  false // verbose
142  )
143 {
144  if (verbose && Foam::infoDetailLevel > 0)
145  {
146  this->printBanner(ioRanks_.size());
147  }
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 
154 {
155  if (comm_ != -1 && comm_ != UPstream::worldComm)
156  {
158  }
159 }
160 
161 
162 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::fileOperations::hostCollatedFileOperation::hostCollatedFileOperation
hostCollatedFileOperation(const bool verbose)
Default construct.
Definition: hostCollatedFileOperation.C:128
Foam::Pstream::scatterList
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Definition: gatherScatterList.C:215
Foam::fileOperations::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Foam::stringList
List< string > stringList
A List of strings.
Definition: stringList.H:58
hostCollatedFileOperation.H
bitSet.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::UPstream::allocateCommunicator
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
Definition: UPstream.C:108
Foam::fileOperations::hostCollatedFileOperation::~hostCollatedFileOperation
virtual ~hostCollatedFileOperation()
Destructor.
Definition: hostCollatedFileOperation.C:153
Foam::fileOperations::addToRunTimeSelectionTable
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
Foam::UPstream::freeCommunicator
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:174
Foam::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fileOperations::collatedFileOperation
Version of masterUncollatedFileOperation that collates regIOobjects into a container in the processor...
Definition: collatedFileOperation.H:65
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fileOperationInitialise
General fileOperation initialiser. Handles -ioRanks option, using it to set the FOAM_IORANKS environm...
Foam::infoDetailLevel
int infoDetailLevel
Global for selective suppression of Info output.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< label >
Foam::hostName
string hostName(bool full=false)
Return the system's host name, as per hostname(1)
Definition: MSwindows.C:410
Foam::fileOperation::ioRanks
static labelList ioRanks()
Retrieve list of IO ranks from FOAM_IORANKS env variable.
Definition: fileOperation.C:222
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
Foam::fileOperations::defineTypeNameAndDebug
defineTypeNameAndDebug(collatedFileOperation, 0)