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 
20  struct Req {
21  const void *sendbuf;
22  const int *sendcounts;
23  const int *sdispls;
24  MPI_Datatype sendtype;
25  void *recvbuf;
26  const int *recvcounts;
27  const int *rdispls;
28  const int *roots;
29  int nroots;
30  MPI_Datatype recvtype;
31  int tag;
32  MPI_Comm comm;
33 
34  bool devAccess;
35  bool completed;
36  };
37 
38  template <bool DevAccess>
39  int post(const void *sendbuf,
40  const int *sendcounts, // how much to each root (length nroots)
41  const int *sdispls, // where data for each root starts (length nroots)
42  MPI_Datatype sendtype,
43  void *recvbuf, // address of recv buffer (significant only at root)
44  const int *recvcounts, // the number of elements recvd from each process
45  // (signficant only at roots)
46  const int *rdispls, // where in `recvbuf` to place incoming data from
47  // process i (signficant only at roots)
48  const int *roots, // list of root ranks (must be same on all procs)
49  int nroots, // size of list of root ranks
50  MPI_Datatype recvtype,
51  int tag,
52  MPI_Comm comm,
53  Req *req) {
54  req->sendbuf = sendbuf;
55  req->sendcounts = sendcounts;
56  req->sdispls = sdispls;
57  req->sendtype = sendtype;
58  req->recvbuf = recvbuf;
59  req->recvcounts = recvcounts;
60  req->rdispls = rdispls;
61  req->roots = roots;
62  req->nroots = nroots;
63  req->recvtype = recvtype;
64  req->tag = tag;
65  req->comm = comm;
66 
67  req->devAccess = DevAccess;
68  req->completed = false;
69  #ifndef NDEBUG
70  // {
71  // std::stringstream ss;
72  // ss << __FILE__ << ":" << __LINE__ << "\n";
73  // std::cerr << ss.str();
74  // }
75  #endif
76  return MPI_SUCCESS;
77  }
78 
79  int wait(Req &req);
80 
81  int get_status(const Req &req, int *flag, MPI_Status *status) const;
82 
83  struct Cache {
84  struct impl;
85  std::shared_ptr<impl> pimpl;
86 
87  Cache();
88  ~Cache();
89  };
90 
91 private:
92 
93  Cache cache_;
94 
95 }; // struct Ialltofewv
96 } // namespace Tpetra::Details