Fenix @develop
 
Loading...
Searching...
No Matches
reduce_log.h
1#ifndef FENIX_LOGGING_OPS_REDUCE_LOG_H
2#define FENIX_LOGGING_OPS_REDUCE_LOG_H
3#include <cstring>
4#include <istream>
5#include <ostream>
6#include "fenix/mpi_util.hpp"
7#include "fenix/logging/op_log.h"
8
9namespace fenix::logging {
10
11class ReduceLog : public CollectiveLog {
12 public:
14 const void* send, void* recv, int count, MPI_Datatype type, MPI_Op o,
15 int root_rank, MPI_Comm c, int idx
16 )
17 : CollectiveLog(idx), root(root_rank), op(o),
18 sbuf(MPIBuffer::copy(send == MPI_IN_PLACE ? recv : send, count, type)) {
19 if (root == util::comm_rank(c)) {
20 rbuf = MPIBuffer::wrap(recv, count, type);
21 }
22 }
23
24 ReduceLog(ReduceLog&& o) { *this = std::move(o); }
25 ReduceLog& operator=(ReduceLog&& o) {
26 CollectiveLog::operator=(std::move(o));
27 root = o.root;
28 op = o.op;
29 sbuf = std::move(o.sbuf);
30 rbuf = std::move(o.rbuf);
31 return *this;
32 }
33
34 ~ReduceLog() = default;
35
36 ReduceLog(std::istream& i) : CollectiveLog(i) {
37 serialize::read(i, root);
38 serialize::read(i, op);
39 serialize::read(i, sbuf);
40 rbuf = MPIBuffer::create(sbuf, sbuf);
41 }
42 void serialize_impl(std::ostream& s) const override {
43 serialize::write(s, root);
44 serialize::write(s, op);
45 serialize::write(s, sbuf);
46 }
47
48 std::string str() const override {
49 return "Reduce " + std::to_string(m_idx) +
50 " (root = " + std::to_string(root) + ")";
51 }
52
53 int begin(MPI_Comm c) const override {
54 req_free();
55 void* recv = root == util::comm_rank(c) ? rbuf.buf() : nullptr;
56 int ret = PMPI_Ireduce(sbuf, recv, sbuf, sbuf, op, root, c, req());
57 if (ret == MPI_SUCCESS) ret = PMPI_Wait(req(), MPI_STATUS_IGNORE);
58 // Release references to any user buffers if we get this far
59 rbuf.release_user_buf();
60 return ret;
61 }
62
63 void replay(MPI_Comm c) const override {
64 req_free();
65 void* recv = root == util::comm_rank(c) ? rbuf.buf() : nullptr;
66 int ret = PMPI_Ireduce(sbuf, recv, sbuf, sbuf, op, root, c, req());
67 fenix_assert(
68 ret == MPI_SUCCESS, "Non-process MPI error during collective replay\n"
69 );
70 }
71
72 int root;
73 MPI_Op op;
74 MPIBuffer sbuf;
75 MPIBuffer rbuf;
76};
77
78template <>
79struct mpi_log<MPI_Reduce> {
80 using type = ReduceLog;
81};
82
83} //namespace fenix::logging
84#endif
Definition op_log.h:76
Definition op_log.h:93
Definition reduce_log.h:11
Definition op_log.h:71