preCICE v3.1.2
Loading...
Searching...
No Matches
IntraComm.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4
5#include "boost/range/irange.hpp"
7#include "logging/Logger.hpp"
9#include "precice/span.hpp"
10
11namespace precice {
12namespace logging {
13class Logger;
14} // namespace logging
15
16namespace utils {
17
19class IntraComm {
20public:
22 static void configure(Rank rank, int size);
23
25 static Rank getRank();
26
28 static int getSize();
29
35
37 static auto allSecondaryRanks()
38 {
39 return boost::irange(1, _size);
40 }
41
43 static auto allRanks()
44 {
45 return boost::irange(0, _size);
46 }
47
49 static bool isPrimary();
50
52 static bool isSecondary();
53
55 static bool isParallel();
56
58 static double l2norm(const Eigen::VectorXd &vec);
59
60 // The dot product of 2 vectors is calculated on distributed data.
61 static double dot(const Eigen::VectorXd &vec1, const Eigen::VectorXd &vec2);
62
63 static void reset();
64
65 static void reduceSum(precice::span<const double> sendData, precice::span<double> rcvData);
66
67 static void reduceSum(const int &sendData, int &rcvData);
68
69 static void reduceSum(const double &sendData, double &rcvData);
70
72
73 static void allreduceSum(double &sendData, double &rcvData);
74
75 static void allreduceSum(int &sendData, int &rcvData);
76
77 static void broadcast(bool &value);
78
79 static void broadcast(double &value);
80
81 static void broadcast(int &value);
82
83 static void broadcast(precice::span<double> values);
84
89 static void synchronize();
90
92 static void barrier();
93
94private:
96
98 static Rank _rank;
99
101 static int _size;
102
104 static bool _isPrimaryRank;
105
107 static bool _isSecondaryRank;
108
111};
112
113} // namespace utils
114} // namespace precice
This class provides a lightweight logger.
Definition Logger.hpp:16
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
Utility class for managing intra-participant communication operations.
Definition IntraComm.hpp:19
static bool _isPrimaryRank
True if this process is running the primary rank.
static void barrier()
Synchronizes all ranks.
static void allreduceSum(precice::span< const double > sendData, precice::span< double > rcvData)
static bool _isSecondaryRank
True if this process is running a secondary rank.
static int _size
Number of ranks. This includes ranks from both participants, e.g. minimal size is 2.
static int getSize()
Number of ranks. This includes ranks from both participants, e.g. minimal size is 2.
Definition IntraComm.cpp:47
static double l2norm(const Eigen::VectorXd &vec)
The l2 norm of a vector is calculated on distributed data.
Definition IntraComm.cpp:67
static Rank getRank()
Current rank.
Definition IntraComm.cpp:42
static double dot(const Eigen::VectorXd &vec1, const Eigen::VectorXd &vec2)
static bool isPrimary()
True if this process is running the primary rank.
Definition IntraComm.cpp:52
static void broadcast(bool &value)
static auto allSecondaryRanks()
Returns an iterable range over salve ranks [1, _size)
Definition IntraComm.hpp:37
static com::PtrCommunication _communication
Intra-participant communication.
static Rank _rank
Current rank.
Definition IntraComm.hpp:98
static auto allRanks()
Returns an iterable range over all ranks [0, _size)
Definition IntraComm.hpp:43
static bool isParallel()
True if this process is running in parallel.
Definition IntraComm.cpp:62
static bool isSecondary()
True if this process is running a secondary rank.
Definition IntraComm.cpp:57
static logging::Logger _log
Definition IntraComm.hpp:95
static com::PtrCommunication & getCommunication()
Intra-participant communication.
Definition IntraComm.hpp:31
static void configure(Rank rank, int size)
Configures the intra-participant communication.
Definition IntraComm.cpp:31
static void reduceSum(precice::span< const double > sendData, precice::span< double > rcvData)
Main namespace of the precice library.
int Rank
Definition Types.hpp:37