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