12 #include "pcu_defines.h"
14 struct pcu_msg_struct;
15 struct pcu_mpi_struct;
29 explicit PCU(PCU_Comm comm);
33 PCU &operator=(
PCU const &) =
delete;
34 PCU &operator=(
PCU &&) noexcept;
38 [[nodiscard]]
int Self() const noexcept;
42 [[nodiscard]]
int Peers() const noexcept;
44 [[nodiscard]] PCU_t GetCHandle() {PCU_t h; h.ptr=
this;
return h;}
46 void Begin() noexcept;
47 int Pack(
int to_rank, const
void *data,
size_t size) noexcept;
48 template<typename T>
int Pack(
int to_rank, const T& data) noexcept {
49 return Pack(to_rank, &(data),
sizeof(data));
53 bool Receive() noexcept;
54 bool Listen() noexcept;
55 int Sender() noexcept;
56 bool Unpacked() noexcept;
57 int Unpack(
void *data,
size_t size) noexcept;
58 template<typename T>
int Unpack(T& data) noexcept {
59 return Unpack(&(data),
sizeof(data));
62 int Write(
int to_rank,
const void *data,
size_t size) noexcept;
63 bool Read(
int *from_rank,
void **data,
size_t *size) noexcept;
71 template <
typename T>
void Add(T *p,
size_t n) noexcept;
72 template <
typename T> [[nodiscard]] T Add(T p) noexcept;
73 template <
typename T>
void Min(T *p,
size_t n) noexcept;
74 template <
typename T> [[nodiscard]] T Min(T p) noexcept;
75 template <
typename T>
void Max(T *p,
size_t n) noexcept;
76 template <
typename T> [[nodiscard]] T Max(T p) noexcept;
77 template <
typename T>
void Exscan(T *p,
size_t n) noexcept;
78 template <
typename T> [[nodiscard]] T Exscan(T p) noexcept;
80 void Allgather(
const T *send, T *recv,
size_t n) noexcept;
83 [[nodiscard]]
int Or(
int c) noexcept;
84 [[nodiscard]]
int And(
int c) noexcept;
97 std::unique_ptr<PCU>
Split(
int color,
int key) noexcept;
112 int DupComm(PCU_Comm* newcomm)
const noexcept;
115 int Packed(
int to_rank,
size_t *size) noexcept;
116 int From(
int *from_rank) noexcept;
117 int Received(
size_t *size) noexcept;
118 void *Extract(
size_t size) noexcept;
126 void DebugPrint(
const char* format, ...) noexcept PCU_FORMAT_ATTRIBUTE(2, 3)
127 void DebugPrint(const
char* format, va_list args) noexcept;
130 void DebugOpen() noexcept;
133 pcu_msg_struct *msg_;
134 pcu_mpi_struct *mpi_;
137 void Protect() noexcept;
139 [[nodiscard]]
double GetMem() noexcept;
141 [[nodiscard]]
double Time() noexcept;
149 void Init(
int *argc,
char ***argv);
164 #define PCU_EXPL_INST_DECL(T) \
165 extern template void PCU::Add<T>(T * p, size_t n) noexcept; \
166 extern template T PCU::Add<T>(T p) noexcept; \
167 extern template void PCU::Min<T>(T * p, size_t n) noexcept; \
168 extern template T PCU::Min<T>(T p) noexcept; \
169 extern template void PCU::Max<T>(T * p, size_t n) noexcept; \
170 extern template T PCU::Max<T>(T p) noexcept; \
171 extern template void PCU::Exscan<T>(T * p, size_t n) noexcept; \
172 extern template T PCU::Exscan<T>(T p) noexcept; \
174 void PCU::Allgather<T>(const T *send, T *recv, size_t n) noexcept;
175 PCU_EXPL_INST_DECL(
int)
176 PCU_EXPL_INST_DECL(
size_t)
177 PCU_EXPL_INST_DECL(
long)
178 PCU_EXPL_INST_DECL(
double)
179 #undef PCU_EXPL_INST_DECL
The Parallel Contrul Unit class encapsulates parallel communication.
int Self() const noexcept
Returns the rank of the current process.
int DupComm(PCU_Comm *newcomm) const noexcept
Duplicate the underlying communicator.
std::unique_ptr< PCU > Split(int color, int key) noexcept
Split a communicator into distinct subgroups.
int Peers() const noexcept
Returns the number of ranks in the communicator.
void Finalize()
Finalize the underlying parallel library.
void Init(int *argc, char ***argv)
Initialize the underlying parallel library.