KASKADE 7 development version
Loading...
Searching...
No Matches
mg
bddcMpi.hh
Go to the documentation of this file.
1
/* Optional MPI ownership contract for BDDC. */
2
#ifndef KASKADE_BDDC_MPI_HH
3
#define KASKADE_BDDC_MPI_HH
4
5
#include <stdexcept>
6
7
#ifdef KASKADE_HAVE_MPI
8
#include <mpi.h>
9
#endif
10
11
namespace
Kaskade::BDDC
12
{
13
class
MpiDomainLayout
14
{
15
public
:
16
void
configure
(
bool
enable,
int
numberOfSubdomains,
bool
master_worker=
false
)
17
{
18
enabled_ = enable;
19
masterWorker_ = master_worker && enable;
20
rank_ = 0;
21
size_ = 1;
22
if
(!enable)
23
return
;
24
25
#ifdef KASKADE_HAVE_MPI
26
int
initialized = 0;
27
MPI_Initialized(&initialized);
28
if
(!initialized)
29
throw
std::runtime_error(
"BDDC MPI requested before MPI_Init"
);
30
MPI_Comm_rank(MPI_COMM_WORLD, &rank_);
31
MPI_Comm_size(MPI_COMM_WORLD, &size_);
32
#else
33
throw
std::runtime_error(
34
"BDDC MPI requested, but this executable was built without MPI support"
);
35
#endif
36
37
if
(numberOfSubdomains <= 0)
38
throw
std::runtime_error(
"BDDC MPI requires at least one subdomain"
);
39
int
workerCount = masterWorker_ ? size_ - 1 : size_;
40
if
(workerCount <= 0 || workerCount > numberOfSubdomains)
41
throw
std::runtime_error(
42
"BDDC MPI requires at least one worker and no more workers than subdomains"
);
43
}
44
45
bool
enabled
()
const
{
return
enabled_; }
46
int
rank
()
const
{
return
rank_; }
47
int
size
()
const
{
return
size_; }
48
bool
masterWorker
()
const
{
return
masterWorker_; }
49
bool
isMaster
()
const
{
return
masterWorker_ && rank_ == 0; }
50
51
// Deterministic initial mapping. A graph/weight-aware partitioner can
52
// replace this later without changing the communication interface.
53
int
owner
(
int
subdomain)
const
54
{
55
if
(subdomain < 0)
56
throw
std::invalid_argument(
"negative BDDC subdomain id"
);
57
if
(!enabled_)
58
return
0;
59
if
(!masterWorker_)
60
return
subdomain % size_;
61
return
1 + subdomain % (size_ - 1);
62
}
63
64
bool
owns
(
int
subdomain)
const
{
return
owner
(subdomain) == rank_; }
65
66
private
:
67
bool
enabled_ =
false
;
68
int
rank_ = 0;
69
int
size_ = 1;
70
bool
masterWorker_ =
false
;
71
};
72
}
73
74
#endif
Kaskade::BDDC::MpiDomainLayout
Definition
bddcMpi.hh:14
Kaskade::BDDC::MpiDomainLayout::owns
bool owns(int subdomain) const
Definition
bddcMpi.hh:64
Kaskade::BDDC::MpiDomainLayout::owner
int owner(int subdomain) const
Definition
bddcMpi.hh:53
Kaskade::BDDC::MpiDomainLayout::isMaster
bool isMaster() const
Definition
bddcMpi.hh:49
Kaskade::BDDC::MpiDomainLayout::size
int size() const
Definition
bddcMpi.hh:47
Kaskade::BDDC::MpiDomainLayout::masterWorker
bool masterWorker() const
Definition
bddcMpi.hh:48
Kaskade::BDDC::MpiDomainLayout::enabled
bool enabled() const
Definition
bddcMpi.hh:45
Kaskade::BDDC::MpiDomainLayout::rank
int rank() const
Definition
bddcMpi.hh:46
Kaskade::BDDC::MpiDomainLayout::configure
void configure(bool enable, int numberOfSubdomains, bool master_worker=false)
Definition
bddcMpi.hh:16
Kaskade::BDDC
Definition
add.hh:29
Generated on
for KASKADE 7 development version by
1.14.0