1818
1919#include " KokkosComm_fwd.hpp"
2020
21+ #include " KokkosComm_mpi_req.hpp"
22+
2123namespace KokkosComm {
2224
2325/*
@@ -35,41 +37,23 @@ class Handle<ExecSpace, Mpi> {
3537 public:
3638 using execution_space = ExecSpace;
3739
38- // a type-erased view. Request uses these to keep temporary views alive for
39- // the lifetime of "Immediate" MPI operations
40- struct ViewHolderBase {
41- virtual ~ViewHolderBase () {}
42- };
43- template <typename V>
44- struct ViewHolder : ViewHolderBase {
45- ViewHolder (const V &v) : v_(v) {}
46- V v_;
47- };
48-
4940 Handle (const execution_space &space, MPI_Comm comm) : space_(space), comm_(comm), preCommFence_(false ) {}
5041
51- // template <KokkosView View>
52- // void impl_track_view(const View &v) {
53- // views_.push_back(std::make_shared<ViewHolder<View>>(v));
54- // }
42+ MPI_Comm &mpi_comm () { return comm_; }
43+ const execution_space &space () const { return space_; }
5544
5645 void impl_add_pre_comm_fence () { preCommFence_ = true ; }
5746
58- void impl_track_mpi_request (MPI_Request req) { reqs_.push_back (req); }
59-
6047 void impl_add_alloc (std::function<void ()> f) { allocs_.push_back (f); }
6148
6249 void impl_add_pre_copy (std::function<void ()> f) { preCopies_.push_back (f); }
6350
6451 void impl_add_comm (std::function<void ()> f) { comms_.push_back (f); }
6552
66- void impl_add_post_wait (std::function<void ()> f) { postWaits_.push_back (f); }
67-
68- MPI_Comm &mpi_comm () { return comm_; }
69-
70- const execution_space &space () const { return space_; }
53+ void impl_track_req (const Req<Mpi> &req) { reqs_.push_back (req); }
7154
7255 void impl_run () {
56+ std::cerr << __FILE__ << " :" << __LINE__ << " impl_run\n " ;
7357 for (const auto &f : allocs_) f ();
7458 for (const auto &f : preCopies_) f ();
7559 if (preCommFence_) {
@@ -82,10 +66,9 @@ class Handle<ExecSpace, Mpi> {
8266 comms_.clear ();
8367 }
8468
85- private:
86- template <KokkosExecutionSpace ES>
87- friend void wait (Handle<ES, Mpi> &handle);
69+ std::vector<Req<Mpi>> &impl_reqs () { return reqs_; }
8870
71+ private:
8972 execution_space space_;
9073 MPI_Comm comm_;
9174
@@ -96,23 +79,8 @@ class Handle<ExecSpace, Mpi> {
9679 std::vector<std::function<void ()>> comms_;
9780
9881 // wait variables
99- std::vector<MPI_Request > reqs_;
82+ std::vector<Req<Mpi> > reqs_;
10083 std::vector<std::function<void ()>> postWaits_;
101- std::vector<std::shared_ptr<ViewHolderBase>> views_;
10284};
10385
104- template <KokkosExecutionSpace ExecSpace>
105- void wait (Handle<ExecSpace, Mpi> &handle) {
106- MPI_Waitall (handle.reqs_ .size (), handle.reqs_ .data (), MPI_STATUSES_IGNORE);
107- handle.reqs_ .clear ();
108- // std::cerr << __FILE__ << ":" << __LINE__ << " MPI_Waitall done\n";
109- for (const auto &f : handle.postWaits_ ) {
110- f ();
111- }
112- // std::cerr << __FILE__ << ":" << __LINE__ << " postWaits_.clear()...\n";
113- handle.postWaits_ .clear ();
114- // views_.clear();
115- // std::cerr << __FILE__ << ":" << __LINE__ << " wait() done\n";
116- }
117-
11886} // namespace KokkosComm
0 commit comments