preCICE
Toggle main menu visibility
Loading...
Searching...
No Matches
src
acceleration
impl
ParallelMatrixOperations.cpp
Go to the documentation of this file.
1
#include "
com/Communication.hpp
"
2
#ifndef PRECICE_NO_MPI
3
4
#include "
acceleration/impl/ParallelMatrixOperations.hpp
"
5
#include "
utils/IntraComm.hpp
"
6
7
namespace
precice::acceleration::impl
{
8
9
void
ParallelMatrixOperations::initialize
(
const
bool
needCyclicComm)
10
{
11
PRECICE_TRACE
();
12
13
if
(needCyclicComm &&
utils::IntraComm::isParallel
()) {
14
_needCyclicComm
=
true
;
15
establishCircularCommunication
();
16
}
else
{
17
_needCyclicComm
=
false
;
18
}
19
}
20
21
ParallelMatrixOperations::~ParallelMatrixOperations
()
22
{
23
PRECICE_TRACE
();
24
25
if
(
_needCyclicComm
) {
26
closeCircularCommunication
();
27
}
28
}
29
30
void
ParallelMatrixOperations::establishCircularCommunication
()
31
{
32
PRECICE_ASSERT
(
_needCyclicComm
);
33
PRECICE_ASSERT
(
_cyclicCommRight
==
nullptr
);
34
PRECICE_ASSERT
(
_cyclicCommLeft
==
nullptr
);
35
36
com::PtrCommunication
cyclicCommLeft =
com::PtrCommunication
(
new
com::MPIPortsCommunication
(
"."
));
37
com::PtrCommunication
cyclicCommRight =
com::PtrCommunication
(
new
com::MPIPortsCommunication
(
"."
));
38
39
const
auto
size =
utils::IntraComm::getSize
();
40
const
auto
rank =
utils::IntraComm::getRank
();
41
com::connectCircularComm
(
"IQNIMVJCyclicComm"
,
""
, rank, size, *cyclicCommLeft, *cyclicCommRight);
42
43
_cyclicCommLeft
= std::move(cyclicCommLeft);
44
_cyclicCommRight
= std::move(cyclicCommRight);
45
}
46
47
void
ParallelMatrixOperations::closeCircularCommunication
()
48
{
49
// Enforce consistency
50
PRECICE_ASSERT
(
static_cast<
bool
>
(
_cyclicCommLeft
) ==
static_cast<
bool
>
(
_cyclicCommRight
));
51
PRECICE_ASSERT
(
_needCyclicComm
);
52
53
if
((
utils::IntraComm::getRank
() % 2) == 0) {
54
_cyclicCommLeft
->closeConnection();
55
_cyclicCommRight
->closeConnection();
56
}
else
{
57
_cyclicCommRight
->closeConnection();
58
_cyclicCommLeft
->closeConnection();
59
}
60
61
_cyclicCommRight
=
nullptr
;
62
_cyclicCommLeft
=
nullptr
;
63
}
64
65
}
// namespace precice::acceleration::impl
66
67
#endif
Communication.hpp
IntraComm.hpp
PRECICE_TRACE
#define PRECICE_TRACE(...)
Definition
LogMacros.hpp:92
ParallelMatrixOperations.hpp
PRECICE_ASSERT
#define PRECICE_ASSERT(...)
Definition
assertion.hpp:85
precice::acceleration::impl::ParallelMatrixOperations::closeCircularCommunication
void closeCircularCommunication()
Definition
ParallelMatrixOperations.cpp:47
precice::acceleration::impl::ParallelMatrixOperations::initialize
void initialize(const bool needCyclicComm)
Initializes the acceleration.
Definition
ParallelMatrixOperations.cpp:9
precice::acceleration::impl::ParallelMatrixOperations::_cyclicCommLeft
com::PtrCommunication _cyclicCommLeft
Communication between neighboring ranks, backwards.
Definition
ParallelMatrixOperations.hpp:308
precice::acceleration::impl::ParallelMatrixOperations::_needCyclicComm
bool _needCyclicComm
Definition
ParallelMatrixOperations.hpp:313
precice::acceleration::impl::ParallelMatrixOperations::_cyclicCommRight
com::PtrCommunication _cyclicCommRight
Communication between neighboring ranks, forward.
Definition
ParallelMatrixOperations.hpp:311
precice::acceleration::impl::ParallelMatrixOperations::~ParallelMatrixOperations
~ParallelMatrixOperations()
Definition
ParallelMatrixOperations.cpp:21
precice::acceleration::impl::ParallelMatrixOperations::establishCircularCommunication
void establishCircularCommunication()
Definition
ParallelMatrixOperations.cpp:30
precice::com::MPIPortsCommunication
Provides connection methods based on MPI ports (part of MPI 2.0).
Definition
MPIPortsCommunication.hpp:21
precice::utils::IntraComm::getSize
static int getSize()
Number of ranks. This includes ranks from both participants, e.g. minimal size is 2.
Definition
IntraComm.cpp:47
precice::utils::IntraComm::getRank
static Rank getRank()
Current rank.
Definition
IntraComm.cpp:42
precice::utils::IntraComm::isParallel
static bool isParallel()
True if this process is running in parallel.
Definition
IntraComm.cpp:62
precice::acceleration::impl
Definition
ConstantPreconditioner.cpp:8
precice::com::PtrCommunication
std::shared_ptr< Communication > PtrCommunication
Definition
SharedPointer.hpp:11
precice::com::connectCircularComm
void connectCircularComm(std::string const &participantName, std::string const &tag, int rank, int size, com::Communication &left, com::Communication &right)
Definition
Communication.cpp:359