Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_Ialltofewv.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #pragma once
11 
12 #include <memory>
13 
14 #include <mpi.h>
15 
16 namespace Tpetra::Details {
17 
18 struct Ialltofewv {
19  struct Req {
20  const void *sendbuf;
21  const int *sendcounts;
22  const int *sdispls;
23  MPI_Datatype sendtype;
24  void *recvbuf;
25  const int *recvcounts;
26  const int *rdispls;
27  const int *roots;
28  int nroots;
29  MPI_Datatype recvtype;
30  int tag;
31  MPI_Comm comm;
32 
33  bool devAccess;
34  bool completed;
35  };
36 
37  template <bool DevAccess>
38  int post(const void *sendbuf,
39  const int *sendcounts, // how much to each root (length nroots)
40  const int *sdispls, // where data for each root starts (length nroots)
41  MPI_Datatype sendtype,
42  void *recvbuf, // address of recv buffer (significant only at root)
43  const int *recvcounts, // the number of elements recvd from each process
44  // (signficant only at roots)
45  const int *rdispls, // where in `recvbuf` to place incoming data from
46  // process i (signficant only at roots)
47  const int *roots, // list of root ranks (must be same on all procs)
48  int nroots, // size of list of root ranks
49  MPI_Datatype recvtype,
50  int tag,
51  MPI_Comm comm,
52  Req *req) {
53  req->sendbuf = sendbuf;
54  req->sendcounts = sendcounts;
55  req->sdispls = sdispls;
56  req->sendtype = sendtype;
57  req->recvbuf = recvbuf;
58  req->recvcounts = recvcounts;
59  req->rdispls = rdispls;
60  req->roots = roots;
61  req->nroots = nroots;
62  req->recvtype = recvtype;
63  req->tag = tag;
64  req->comm = comm;
65 
66  req->devAccess = DevAccess;
67  req->completed = false;
68 #ifndef NDEBUG
69  // {
70  // std::stringstream ss;
71  // ss << __FILE__ << ":" << __LINE__ << "\n";
72  // std::cerr << ss.str();
73  // }
74 #endif
75  return MPI_SUCCESS;
76  }
77 
78  int wait(Req &req);
79 
80  int get_status(const Req &req, int *flag, MPI_Status *status) const;
81 
82  struct Cache {
83  struct impl;
84  std::shared_ptr<impl> pimpl;
85 
86  Cache();
87  ~Cache();
88  };
89 
90  private:
91  Cache cache_;
92 
93 }; // struct Ialltofewv
94 } // namespace Tpetra::Details