/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/mpi.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/mpi.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
mpi.hh
Go to the documentation of this file.
1#pragma once
2
4#include <deal.II/base/mpi.h>
5
6// std
7#include <cstddef>
8#include <cstdint>
9#include <string>
10#include <vector>
11
12// deal.II is the single source of truth for whether MPI is available: it is the library that
13// either includes <mpi.h> (giving us the real types at global scope) or declares dummy types in
14// namespace dealii. DiFfRG's own HAVE_MPI must agree with it, otherwise mpi.cc would compile the
15// serial fallbacks against real MPI types (or the reverse) and the two halves of the program would
16// disagree about what a communicator is.
17#if defined(HAVE_MPI) && !defined(DEAL_II_WITH_MPI)
18#error \
19 "DiFfRG was configured with MPI=ON but the deal.II it links against was built without DEAL_II_WITH_MPI. Rebuild deal.II with MPI, or configure DiFfRG with -DMPI=OFF."
20#endif
21
22#ifdef DEAL_II_WITH_MPI
23#define DIFFRG_WITH_MPI 1
24#endif
25
26namespace DiFfRG
27{
28#ifndef DEAL_II_WITH_MPI
29 // Without MPI, deal.II (>= 9.7) declares the MPI types and constants in
30 // namespace dealii rather than at global scope. Pull them into namespace
31 // DiFfRG so that the API below resolves identically with and without MPI.
32 using dealii::MPI_Comm;
33 using dealii::MPI_Datatype;
34 using dealii::MPI_Op;
35 using dealii::MPI_Request;
36
37 using dealii::MPI_COMM_NULL;
38 using dealii::MPI_COMM_SELF;
39 using dealii::MPI_COMM_WORLD;
40 using dealii::MPI_LOR;
41 using dealii::MPI_MAX;
42 using dealii::MPI_MIN;
43 using dealii::MPI_REQUEST_NULL;
44 using dealii::MPI_SUM;
45#endif
46
47 namespace MPI
48 {
53 bool available();
54
55 uint rank(MPI_Comm comm);
56 uint size(MPI_Comm comm);
57 void barrier(MPI_Comm comm);
58
59 // Element-wise in-place array reductions: on return every rank holds the reduced array.
60 void sum_reduce(MPI_Comm comm, int *data, int size);
61 void max_reduce(MPI_Comm comm, int *data, int size);
62 void min_reduce(MPI_Comm comm, int *data, int size);
63
64 void sum_reduce(MPI_Comm comm, double *data, int size);
65 void max_reduce(MPI_Comm comm, double *data, int size);
66 void min_reduce(MPI_Comm comm, double *data, int size);
67
68 int sum_reduce(MPI_Comm comm, int value);
69 int max_reduce(MPI_Comm comm, int value);
70 int min_reduce(MPI_Comm comm, int value);
71
72 double sum_reduce(MPI_Comm comm, double value);
73 double max_reduce(MPI_Comm comm, double value);
74 double min_reduce(MPI_Comm comm, double value);
75
81 bool any_of(MPI_Comm comm, bool value);
82 bool all_of(MPI_Comm comm, bool value);
83
90 bool agree(MPI_Comm comm, uint64_t token);
91
93 void bcast(MPI_Comm comm, void *data, size_t bytes, uint root = 0);
94
103 void allgatherv_bytes(MPI_Comm comm, const void *send, size_t send_bytes, void *recv,
104 const std::vector<int> &recv_counts, const std::vector<int> &displs);
105
111 MPI_Comm split_shared(MPI_Comm comm);
112 void free_comm(MPI_Comm &comm);
113
120 [[noreturn]] void abort(MPI_Comm comm, const std::string &message, int code = 1);
121 } // namespace MPI
122} // namespace DiFfRG
bool all_of(MPI_Comm comm, bool value)
uint rank(MPI_Comm comm)
void allgatherv_bytes(MPI_Comm comm, const void *send, size_t send_bytes, void *recv, const std::vector< int > &recv_counts, const std::vector< int > &displs)
Concatenating all-gather of byte blocks of differing size.
void barrier(MPI_Comm comm)
void max_reduce(MPI_Comm comm, int *data, int size)
void abort(MPI_Comm comm, const std::string &message, int code=1)
Tear the whole job down with a message on stderr.
bool available()
Whether this build has MPI and MPI_Init has run. Everything below degrades to a single-rank no-op whe...
bool any_of(MPI_Comm comm, bool value)
Collective agreement on a predicate. Used to turn a rank-local decision (an abort,...
bool agree(MPI_Comm comm, uint64_t token)
Whether every rank passed the same token. One collective.
void min_reduce(MPI_Comm comm, int *data, int size)
void sum_reduce(MPI_Comm comm, int *data, int size)
void free_comm(MPI_Comm &comm)
uint size(MPI_Comm comm)
void bcast(MPI_Comm comm, void *data, size_t bytes, uint root=0)
Broadcast raw bytes from root to all ranks.
MPI_Comm split_shared(MPI_Comm comm)
A communicator over the ranks sharing this node's memory, for GPU affinity.
Definition complex_math.hh:10
unsigned int uint
Definition utils.hh:24