DIY 3.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

All Classes Namespaces Functions Typedefs Groups Pages
point-to-point.hpp
1 #include <vector>
2
3 namespace diy
4 {
5 namespace mpi
6 {
7 namespace detail
8 {
9 // send
10 template< class T, class is_mpi_datatype_ = typename is_mpi_datatype<T>::type >
11 struct send;
12
13 template<class T>
14 struct send<T, true_type>
15 {
16 void operator()(MPI_Comm comm, int dest, int tag, const T& x) const
17 {
18 typedef mpi_datatype<T> Datatype;
19 MPI_Send((void*) Datatype::address(x),
20 Datatype::count(x),
21 Datatype::datatype(),
22 dest, tag, comm);
23 }
24 };
25
26 // recv
27 template< class T, class is_mpi_datatype_ = typename is_mpi_datatype<T>::type >
28 struct recv;
29
30 template<class T>
31 struct recv<T, true_type>
32 {
33 status operator()(MPI_Comm comm, int source, int tag, T& x) const
34 {
35 typedef mpi_datatype<T> Datatype;
36 status s;
37 MPI_Recv((void*) Datatype::address(x),
38 Datatype::count(x),
39 Datatype::datatype(),
40 source, tag, comm, &s.s);
41 return s;
42 }
43 };
44
45 template<class U>
46 struct recv<std::vector<U>, true_type>
47 {
48 status operator()(MPI_Comm comm, int source, int tag, std::vector<U>& x) const
49 {
50 status s;
51
52 MPI_Probe(source, tag, comm, &s.s);
53 x.resize(s.count<U>());
54 MPI_Recv(&x[0], x.size(), get_mpi_datatype<U>(), source, tag, comm, &s.s);
55 return s;
56 }
57 };
58
59 // isend
60 template< class T, class is_mpi_datatype_ = typename is_mpi_datatype<T>::type >
61 struct isend;
62
63 template<class T>
64 struct isend<T, true_type>
65 {
66 request operator()(MPI_Comm comm, int dest, int tag, const T& x) const
67 {
68 request r;
69 typedef mpi_datatype<T> Datatype;
70 MPI_Isend((void*) Datatype::address(x),
71 Datatype::count(x),
72 Datatype::datatype(),
73 dest, tag, comm, &r.r);
74 return r;
75 }
76 };
77
78 // irecv
79 template< class T, class is_mpi_datatype_ = typename is_mpi_datatype<T>::type >
80 struct irecv;
81
82 template<class T>
83 struct irecv<T, true_type>
84 {
85 request operator()(MPI_Comm comm, int source, int tag, T& x) const
86 {
87 request r;
88 typedef mpi_datatype<T> Datatype;
89 MPI_Irecv(Datatype::address(x),
90 Datatype::count(x),
91 Datatype::datatype(),
92 source, tag, comm, &r.r);
93 return r;
94 }
95 };
96 }
97 }
98 }