processorTopology.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) 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 
28 #include "processorTopology.H"
29 #include "Pstream.H" // For allGatherList()
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  comm_(UPstream::worldComm)
36 {}
37 
38 
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 
42 {
43  if (procNeighbours_.empty() && !procPatchMap_.empty())
44  {
45  // My neighbouring procs in ascending sorted order
46  procNeighbours_ = procPatchMap_.sortedToc();
47  }
48 
49  return procNeighbours_;
50 }
51 
52 
53 // May be useful in the future...
54 // ------------------------------
55 //
56 // const Foam::labelUList Foam::processorTopology::below() const
57 // {
58 // const auto& all = procNeighbours();
59 //
60 // const auto* pivot = std::upper_bound
61 // (
62 // all.begin(),
63 // all.end(),
64 // UPstream::myProcNo(comm_)
65 // );
66 //
67 // if (pivot != all.end())
68 // {
69 // return UList<label>
70 // (
71 // const_cast<label*>(all.begin()),
72 // (pivot - all.begin())
73 // );
74 // }
75 // return UList<label>();
76 // }
77 //
78 //
79 // const Foam::labelUList Foam::processorTopology::above() const
80 // {
81 // const auto& all = procNeighbours();
82 //
83 // const auto* pivot = std::upper_bound
84 // (
85 // all.begin(),
86 // all.end(),
87 // UPstream::myProcNo(comm_)
88 // );
89 // if (pivot != all.end())
90 // {
91 // return UList<label>
92 // (
93 // const_cast<label*>(pivot),
94 // (all.end() - pivot)
95 // );
96 // }
97 // return UList<label>();
98 // }
99 
100 
102 {
103  if (UPstream::parRun() && procAdjacencyTable_.empty())
104  {
105  procAdjacencyTable_.resize(UPstream::nProcs(comm_));
106 
107  // My neighbouring procs in ascending sorted order
108  procAdjacencyTable_[UPstream::myProcNo(comm_)]
109  = procPatchMap_.sortedToc();
110 
111  // Synchronize on all processors
112  Pstream::allGatherList(procAdjacencyTable_, UPstream::msgType(), comm_);
113  }
114 
115  return procAdjacencyTable_;
116 }
117 
118 
119 // ************************************************************************* //
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:675
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1061
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1252
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
Definition: UPstream.H:1086
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Definition: UPstream.H:1077
const labelListList & procAdjacency() const
The complete processor to processor connection adjacency table. Globally synchronized information...
const direction noexcept
Definition: Scalar.H:258
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTable.H:353
processorTopology() noexcept
Default construct (empty)
static void allGatherList(UList< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses MPI_Allgather or manual linear/tree communicat...
const labelList & procNeighbours() const
The neighbour processor connections (ascending order) associated with the local rank.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:163
Inter-processor communications stream.
Definition: UPstream.H:65