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"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  procPatchMap_(0),
36  comm_(UPstream::worldComm)
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
43 {
44  if (procNeighbours_.empty() && !procPatchMap_.empty())
45  {
46  // My neighbouring procs in ascending sorted order
47  procNeighbours_ = procPatchMap_.sortedToc();
48  }
49 
50  return procNeighbours_;
51 }
52 
53 
54 // May be useful in the future...
55 // ------------------------------
56 //
57 // const Foam::labelUList Foam::processorTopology::below() const
58 // {
59 // const auto& all = procNeighbours();
60 //
61 // const auto* pivot = std::upper_bound
62 // (
63 // all.begin(),
64 // all.end(),
65 // UPstream::myProcNo(comm_)
66 // );
67 //
68 // if (pivot != all.end())
69 // {
70 // return UList<label>
71 // (
72 // const_cast<label*>(all.begin()),
73 // (pivot - all.begin())
74 // );
75 // }
76 // return UList<label>();
77 // }
78 //
79 //
80 // const Foam::labelUList Foam::processorTopology::above() const
81 // {
82 // const auto& all = procNeighbours();
83 //
84 // const auto* pivot = std::upper_bound
85 // (
86 // all.begin(),
87 // all.end(),
88 // UPstream::myProcNo(comm_)
89 // );
90 // if (pivot != all.end())
91 // {
92 // return UList<label>
93 // (
94 // const_cast<label*>(pivot),
95 // (all.end() - pivot)
96 // );
97 // }
98 // return UList<label>();
99 // }
100 
101 
103 {
104  if (UPstream::parRun() && procAdjacencyTable_.empty())
105  {
106  procAdjacencyTable_.resize(UPstream::nProcs(comm_));
107 
108  // My neighbouring procs in ascending sorted order
109  procAdjacencyTable_[UPstream::myProcNo(comm_)]
110  = procPatchMap_.sortedToc();
111 
112  // Synchronize on all processors
113  Pstream::allGatherList(procAdjacencyTable_, UPstream::msgType(), comm_);
114  }
115 
116  return procAdjacencyTable_;
117 }
118 
119 
120 // ************************************************************************* //
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
processorTopology()
Default construct (empty)
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
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:1074
static void allGatherList(List< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses linear/tree communication. ...
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:1065
const labelListList & procAdjacency() const
The complete processor to processor connection adjacency table. Globally synchronized information...
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTable.H:337
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:139
Inter-processor communications stream.
Definition: UPstream.H:60