Alsvinn  0.5.3
The fast FVM simulator with UQ support
Request.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
17 #include <mpi.h>
18 #include "alsutils/config.hpp"
20 #include "alsfvm/types.hpp"
21 #include <memory>
22 #ifdef ALSVINN_HAVE_CUDA
23  #include <thrust/host_vector.h>
24 #endif
25 
26 namespace alsfvm {
27 namespace mpi {
28 
32 class Request {
33 public:
35  Request();
36 public:
37  typedef alsfvm::shared_ptr<Request> RequestPtr;
38 
40  template<class Data>
41  static RequestPtr isend(const Data& data, int count, MPI_Datatype datatype,
42  int destination, int tag, Configuration& configuration);
43 
45  template<class Data>
46  static RequestPtr ireceive(Data& receiveBuffer, int count,
47  MPI_Datatype datatype,
48  int source, int tag, Configuration configuration);
49 
50 
52  void wait();
53 
54  friend class std::unique_ptr<Request>;
55 
56  ~Request();
57 private:
58 
59  MPI_Request request{NULL};
60 };
61 
63 
64 template<class Data>
65 inline RequestPtr Request::isend(const Data& data, int count,
66  MPI_Datatype datatype,
67  int destination, int tag, Configuration& configuration) {
68  std::shared_ptr<Request> requestPointer(new Request());
69 
70 
71  MPI_Isend((void*)data.getPointer(), count, datatype, destination, tag,
72  configuration.getCommunicator(),
73  &requestPointer->request);
74 
75  return requestPointer;
76 }
77 
78 template<class Data>
79 inline RequestPtr Request::ireceive(Data& receiveBuffer, int count,
80  MPI_Datatype datatype,
81  int source, int tag, Configuration configuration) {
82  std::shared_ptr<Request> requestPointer(new Request());
83 
84 
85  MPI_Irecv((void*)receiveBuffer.getPointer(), count, datatype, source, tag,
86  configuration.getCommunicator(),
87  &requestPointer->request);
88 
89  return requestPointer;
90 }
91 
92 
93 #ifdef ALSVINN_HAVE_CUDA
94 template<>
95 inline RequestPtr Request::isend(const thrust::host_vector<real>& data,
96  int count, MPI_Datatype datatype,
97  int destination, int tag, Configuration& configuration) {
98  std::shared_ptr<Request> requestPointer(new Request());
99 
100 
101  MPI_Isend((void*)data.data(), count, datatype, destination, tag,
102  configuration.getCommunicator(),
103  &requestPointer->request);
104 
105  return requestPointer;
106 }
107 
108 template<>
109 inline RequestPtr Request::ireceive(thrust::host_vector<real>& receiveBuffer,
110  int count, MPI_Datatype datatype,
111  int source, int tag, Configuration configuration) {
112  std::shared_ptr<Request> requestPointer(new Request());
113 
114 
115  MPI_Irecv((void*)receiveBuffer.data(), count, datatype, source, tag,
116  configuration.getCommunicator(),
117  &requestPointer->request);
118 
119  return requestPointer;
120 }
121 #endif
122 }
123 } // namespace alsfvm
static RequestPtr ireceive(Data &receiveBuffer, int count, MPI_Datatype datatype, int source, int tag, Configuration configuration)
Maps to MPI_Irecv. See http://www.mpich.org/static/docs/v3.1/www3/MPI_Irecv.html. ...
Definition: Request.hpp:79
~Request()
Definition: Request.cpp:32
alsfvm::shared_ptr< Request > RequestPtr
Definition: Request.hpp:37
Request()
Singleton.
Definition: Request.cpp:24
Definition: Configuration.hpp:50
static RequestPtr isend(const Data &data, int count, MPI_Datatype datatype, int destination, int tag, Configuration &configuration)
Maps to MPI_Isend. See http://www.mpich.org/static/docs/v3.1/www3/MPI_Isend.html. ...
Definition: Request.hpp:65
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
Definition: Request.hpp:32
void wait()
Wait for the request to finish, maps to MPI_Wait.
Definition: Request.cpp:28