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