OpenLB 1.7
Loading...
Searching...
No Matches
superCommunicationTagCoordinator.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef SUPER_COMMUNICATION_TAG_COORDINATOR_HH
25#define SUPER_COMMUNICATION_TAG_COORDINATOR_HH
26
28
29#include <vector>
30#include <algorithm>
31
32namespace olb {
33
34#ifdef PARALLEL_MODE_MPI
35
36template <typename T>
38private:
39 const int _iC;
40 const int _jC;
41
42public:
43 ChannelId(int iC, int jC):
44 _iC(util::min(iC,jC)),
45 _jC(util::max(iC,jC)) { }
46
47 bool operator==(const ChannelId& rhs) const
48 {
49 return _iC == rhs._iC
50 && _jC == rhs._jC;
51 }
52
53 bool operator<(const ChannelId& rhs) const
54 {
55 return _iC < rhs._iC
56 || (_iC == rhs._iC && _jC < rhs._jC);
57 }
58
59};
61template <typename T>
64
65template <typename T>
66template <unsigned D>
68 std::vector<std::unique_ptr<BlockCommunicationNeighborhood<T,D>>>& neighborhood)
69{
70 for (int iC = 0; iC < _loadBalancer.size(); ++iC) {
71 neighborhood[iC]->forNeighbors([&](int jC) {
72 if (!_loadBalancer.isLocal(jC)) {
73 _tags[_loadBalancer.rank(jC)][{_loadBalancer.glob(iC),jC}] = -1;
74 }
75 });
76 }
77
78 for (auto& [rank, tags] : _tags) {
79 int i=0;
80 for (auto tag=tags.begin(); tag != tags.end(); ++tag, ++i) {
81 (*tag).second = i;
82 }
83 }
84}
85
86template <typename T>
87int SuperCommunicationTagCoordinator<T>::get(int iC, int jC, int iGroup)
88{
89 if (_loadBalancer.isLocal(iC) && _loadBalancer.isLocal(jC)) {
90 return iGroup*_loadBalancer.size()*_loadBalancer.size()
91 + _loadBalancer.loc(iC)*_loadBalancer.size() + _loadBalancer.loc(jC);
92 } else {
93 int kC = _loadBalancer.isLocal(iC) ? jC : iC;
94 auto& tags = _tags[_loadBalancer.rank(kC)];
95 return iGroup*tags.size() + tags[{iC,jC}];
96 }
97}
98
99#endif // PARALLEL_MODE_MPI
100
101}
102
103#endif
Configurable overlap communication neighborhood of a block.
Base class for all LoadBalancer.
Communication-free negotation of unique tags for inter-cuboid communication.
void coordinate(std::vector< std::unique_ptr< BlockCommunicationNeighborhood< T, D > > > &neighborhood)
Generate unique tags for given block neighborhood system.
SuperCommunicationTagCoordinator(LoadBalancer< T > &loadBalancer)
Top level namespace for all of OpenLB.