IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
Status.h
Go to the documentation of this file.
1//
2// Class Status
3// A communication status handle for non-blocking communication.
4//
5#ifndef IPPL_MPI_STATUS_H
6#define IPPL_MPI_STATUS_H
7
8#include <mpi.h>
9#include <optional>
10
11namespace ippl {
12 namespace mpi {
13
14 class Status {
15 public:
17 : status_m()
18 , count_m(-1){};
19
20 Status(const Status&) = default;
21
22 Status& operator=(Status& other) = default;
23
24 int source() const noexcept { return status_m.MPI_SOURCE; }
25
26 int tag() const noexcept { return status_m.MPI_TAG; }
27
28 int error() const noexcept { return status_m.MPI_ERROR; }
29
30 template <typename T>
31 std::optional<int> count();
32
33 // https://en.cppreference.com/w/cpp/language/cast_operator
34 operator MPI_Status*() noexcept { return &status_m; }
35
36 operator const MPI_Status*() const noexcept { return &status_m; }
37
38 private:
39 MPI_Status status_m;
41 };
42
43 template <typename T>
44 std::optional<int> Status::count() {
45 if (count_m != -1) {
46 return count_m;
47 }
48
49 int count = MPI_UNDEFINED;
50 MPI_Datatype datatype = get_mpi_datatype<T>(T());
51 MPI_Get_count(&status_m, datatype, &count);
52
53 if (count == MPI_UNDEFINED) {
54 return std::optional<int>();
55 }
56 count_m = count;
57 return count_m;
58 }
59 } // namespace mpi
60} // namespace ippl
61
62#endif
Definition Archive.h:20
MPI_Datatype get_mpi_datatype(const T &)
Definition DataTypes.h:65
std::optional< int > count()
Definition Status.h:44
Status(const Status &)=default
Status & operator=(Status &other)=default
int tag() const noexcept
Definition Status.h:26
int source() const noexcept
Definition Status.h:24
MPI_Status status_m
Definition Status.h:39
int error() const noexcept
Definition Status.h:28