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