1 | #ifndef MPI_IALLREDUCEW_HPP |
2 | #define MPI_IALLREDUCEW_HPP |
3 | |
4 | #include <mpi.h> |
5 | |
6 | /*! \brief Set of wrapping classing for MPI_Iallreduce |
7 | * |
8 | * The purpose of these classes is to correctly choose the right call based on the type we want to reduce |
9 | * |
10 | */ |
11 | |
12 | |
13 | /*! \brief General reduction |
14 | * |
15 | * \tparam any type |
16 | * |
17 | */ |
18 | |
19 | template<typename T> class MPI_IallreduceW |
20 | { |
21 | public: |
22 | static inline void reduce(T & buf,MPI_Op op, MPI_Request & req) |
23 | { |
24 | #ifndef DISABLE_ALL_RTTI |
25 | std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " cannot recognize " << typeid(T).name() << "\n" ; |
26 | #endif |
27 | } |
28 | }; |
29 | |
30 | |
31 | /*! \brief specialization for integer |
32 | * |
33 | */ |
34 | template<> class MPI_IallreduceW<int> |
35 | { |
36 | public: |
37 | static inline void reduce(int & buf,MPI_Op op, MPI_Request & req) |
38 | { |
39 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_INT, op, MPI_COMM_WORLD,&req)); |
40 | } |
41 | }; |
42 | |
43 | /*! \brief specialization for unsigned integer |
44 | * |
45 | */ |
46 | template<> class MPI_IallreduceW<unsigned int> |
47 | { |
48 | public: |
49 | static inline void reduce(unsigned int & buf,MPI_Op op, MPI_Request & req) |
50 | { |
51 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED, op, MPI_COMM_WORLD,&req)); |
52 | } |
53 | }; |
54 | |
55 | /*! \brief specialization for short |
56 | * |
57 | */ |
58 | template<> class MPI_IallreduceW<short> |
59 | { |
60 | public: |
61 | static inline void reduce(short & buf,MPI_Op op, MPI_Request & req) |
62 | { |
63 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_SHORT, op, MPI_COMM_WORLD,&req)); |
64 | } |
65 | }; |
66 | |
67 | /*! \brief specialization for short |
68 | * |
69 | */ |
70 | template<> class MPI_IallreduceW<unsigned short> |
71 | { |
72 | public: |
73 | static inline void reduce(unsigned short & buf,MPI_Op op, MPI_Request & req) |
74 | { |
75 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_SHORT, op, MPI_COMM_WORLD,&req)); |
76 | } |
77 | }; |
78 | |
79 | /*! \brief specialization for char |
80 | * |
81 | */ |
82 | template<> class MPI_IallreduceW<char> |
83 | { |
84 | public: |
85 | static inline void reduce(char & buf,MPI_Op op, MPI_Request & req) |
86 | { |
87 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_CHAR, op, MPI_COMM_WORLD,&req)); |
88 | } |
89 | }; |
90 | |
91 | /*! \brief specialization for char |
92 | * |
93 | */ |
94 | template<> class MPI_IallreduceW<unsigned char> |
95 | { |
96 | public: |
97 | static inline void reduce(unsigned char & buf,MPI_Op op, MPI_Request & req) |
98 | { |
99 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_CHAR, op, MPI_COMM_WORLD,&req)); |
100 | } |
101 | }; |
102 | |
103 | /*! \brief specialization for size_t |
104 | * |
105 | */ |
106 | template<> class MPI_IallreduceW<size_t> |
107 | { |
108 | public: |
109 | static inline void reduce(size_t & buf,MPI_Op op, MPI_Request & req) |
110 | { |
111 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_UNSIGNED_LONG, op, MPI_COMM_WORLD,&req)); |
112 | } |
113 | }; |
114 | |
115 | /*! \brief specialization for size_t |
116 | * |
117 | */ |
118 | template<> class MPI_IallreduceW<long int> |
119 | { |
120 | public: |
121 | static inline void reduce(long int & buf,MPI_Op op, MPI_Request & req) |
122 | { |
123 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_LONG, op, MPI_COMM_WORLD,&req)); |
124 | } |
125 | }; |
126 | |
127 | /*! \brief specialization for float |
128 | * |
129 | */ |
130 | template<> class MPI_IallreduceW<float> |
131 | { |
132 | public: |
133 | static inline void reduce(float & buf,MPI_Op op, MPI_Request & req) |
134 | { |
135 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_FLOAT, op, MPI_COMM_WORLD,&req)); |
136 | } |
137 | }; |
138 | |
139 | /*! \brief specialization for double |
140 | * |
141 | */ |
142 | template<> class MPI_IallreduceW<double> |
143 | { |
144 | public: |
145 | static inline void reduce(double & buf,MPI_Op op, MPI_Request & req) |
146 | { |
147 | MPI_SAFE_CALL(MPI_Iallreduce(MPI_IN_PLACE, &buf, 1,MPI_DOUBLE, op, MPI_COMM_WORLD,&req)); |
148 | } |
149 | }; |
150 | |
151 | ////////////////// Specialization for vectors /////////////// |
152 | |
153 | /*! \brief specialization for vector integer |
154 | * |
155 | */ |
156 | /*template<> class MPI_IallreduceW<openfpm::vector<int>> |
157 | { |
158 | public: |
159 | static inline void reduce(openfpm::vector<int> & buf,MPI_Op op, MPI_Request & req) |
160 | { |
161 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_INT, op, MPI_COMM_WORLD,&req); |
162 | } |
163 | };*/ |
164 | |
165 | /*! \brief specialization for vector short |
166 | * |
167 | */ |
168 | /*template<> class MPI_IallreduceW<openfpm::vector<short>> |
169 | { |
170 | public: |
171 | static inline void reduce(openfpm::vector<short> & buf,MPI_Op op, MPI_Request & req) |
172 | { |
173 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_SHORT, op, MPI_COMM_WORLD,&req); |
174 | } |
175 | };*/ |
176 | |
177 | /*! \brief specialization for vector char |
178 | * |
179 | */ |
180 | /*template<> class MPI_IallreduceW<openfpm::vector<char>> |
181 | { |
182 | public: |
183 | static inline void reduce(openfpm::vector<char> & buf,MPI_Op op, MPI_Request & req) |
184 | { |
185 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_CHAR, op, MPI_COMM_WORLD,&req); |
186 | } |
187 | };*/ |
188 | |
189 | /*! \brief specialization for vector size_t |
190 | * |
191 | */ |
192 | /*template<> class MPI_IallreduceW<openfpm::vector<size_t>> |
193 | { |
194 | public: |
195 | static inline void reduce(openfpm::vector<size_t> & buf,MPI_Op op, MPI_Request & req) |
196 | { |
197 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_UNSIGNED_LONG, op, MPI_COMM_WORLD,&req); |
198 | } |
199 | };*/ |
200 | |
201 | /*! \brief specialization for vector float |
202 | * |
203 | */ |
204 | /*template<> class MPI_IallreduceW<openfpm::vector<float>> |
205 | { |
206 | public: |
207 | static inline void reduce(openfpm::vector<float> & buf,MPI_Op op, MPI_Request & req) |
208 | { |
209 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_FLOAT, op, MPI_COMM_WORLD,&req); |
210 | } |
211 | };*/ |
212 | |
213 | /*! \brief specialization for vector double |
214 | * |
215 | */ |
216 | |
217 | /*template<> class MPI_IallreduceW<openfpm::vector<double>> |
218 | { |
219 | public: |
220 | static inline void reduce(openfpm::vector<double> & buf,MPI_Op op, MPI_Request & req) |
221 | { |
222 | MPI_Iallreduce(MPI_IN_PLACE, &buf.get(0), buf.size(),MPI_DOUBLE, op, MPI_COMM_WORLD,&req); |
223 | } |
224 | };*/ |
225 | |
226 | #endif |
227 | |