Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SyclMpiTypes.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19#include "shamcomm/mpi.hpp"
20#include <climits>
21
22inline MPI_Datatype mpi_type_i64 = MPI_INT64_T;
23inline MPI_Datatype mpi_type_i32 = MPI_INT32_T;
24inline MPI_Datatype mpi_type_i16 = MPI_INT16_T;
25inline MPI_Datatype mpi_type_i8 = MPI_INT8_T;
26inline MPI_Datatype mpi_type_u64 = MPI_UINT64_T;
27inline MPI_Datatype mpi_type_u32 = MPI_UINT32_T;
28inline MPI_Datatype mpi_type_u16 = MPI_UINT16_T;
29inline MPI_Datatype mpi_type_u8 = MPI_UINT8_T;
30inline MPI_Datatype mpi_type_f16 = MPI_SHORT; // no f16 in mpi std
31inline MPI_Datatype mpi_type_f32 = MPI_FLOAT;
32inline MPI_Datatype mpi_type_f64 = MPI_DOUBLE;
33
34inline MPI_Datatype mpi_type_i64_2;
35inline MPI_Datatype mpi_type_i32_2;
36inline MPI_Datatype mpi_type_i16_2;
37inline MPI_Datatype mpi_type_i8_2;
38inline MPI_Datatype mpi_type_u64_2;
39inline MPI_Datatype mpi_type_u32_2;
40inline MPI_Datatype mpi_type_u16_2;
41inline MPI_Datatype mpi_type_u8_2;
42inline MPI_Datatype mpi_type_f16_2;
43inline MPI_Datatype mpi_type_f32_2;
44inline MPI_Datatype mpi_type_f64_2;
45
46inline MPI_Datatype mpi_type_i64_3;
47inline MPI_Datatype mpi_type_i32_3;
48inline MPI_Datatype mpi_type_i16_3;
49inline MPI_Datatype mpi_type_i8_3;
50inline MPI_Datatype mpi_type_u64_3;
51inline MPI_Datatype mpi_type_u32_3;
52inline MPI_Datatype mpi_type_u16_3;
53inline MPI_Datatype mpi_type_u8_3;
54inline MPI_Datatype mpi_type_f16_3;
55inline MPI_Datatype mpi_type_f32_3;
56inline MPI_Datatype mpi_type_f64_3;
57
58inline MPI_Datatype mpi_type_i64_4;
59inline MPI_Datatype mpi_type_i32_4;
60inline MPI_Datatype mpi_type_i16_4;
61inline MPI_Datatype mpi_type_i8_4;
62inline MPI_Datatype mpi_type_u64_4;
63inline MPI_Datatype mpi_type_u32_4;
64inline MPI_Datatype mpi_type_u16_4;
65inline MPI_Datatype mpi_type_u8_4;
66inline MPI_Datatype mpi_type_f16_4;
67inline MPI_Datatype mpi_type_f32_4;
68inline MPI_Datatype mpi_type_f64_4;
69
70inline MPI_Datatype mpi_type_i64_8;
71inline MPI_Datatype mpi_type_i32_8;
72inline MPI_Datatype mpi_type_i16_8;
73inline MPI_Datatype mpi_type_i8_8;
74inline MPI_Datatype mpi_type_u64_8;
75inline MPI_Datatype mpi_type_u32_8;
76inline MPI_Datatype mpi_type_u16_8;
77inline MPI_Datatype mpi_type_u8_8;
78inline MPI_Datatype mpi_type_f16_8;
79inline MPI_Datatype mpi_type_f32_8;
80inline MPI_Datatype mpi_type_f64_8;
81
82inline MPI_Datatype mpi_type_i64_16;
83inline MPI_Datatype mpi_type_i32_16;
84inline MPI_Datatype mpi_type_i16_16;
85inline MPI_Datatype mpi_type_i8_16;
86inline MPI_Datatype mpi_type_u64_16;
87inline MPI_Datatype mpi_type_u32_16;
88inline MPI_Datatype mpi_type_u16_16;
89inline MPI_Datatype mpi_type_u8_16;
90inline MPI_Datatype mpi_type_f16_16;
91inline MPI_Datatype mpi_type_f32_16;
92inline MPI_Datatype mpi_type_f64_16;
93
94template<class type>
95MPI_Datatype &get_mpi_type();
96
97// coments due to weird implementation of half prec in hipsycl
98
99template<>
100inline MPI_Datatype &get_mpi_type<i64>() {
101 return mpi_type_i64;
102}
103template<>
104inline MPI_Datatype &get_mpi_type<i32>() {
105 return mpi_type_i32;
106}
107template<>
108inline MPI_Datatype &get_mpi_type<i16>() {
109 return mpi_type_i16;
110}
111template<>
112inline MPI_Datatype &get_mpi_type<i8>() {
113 return mpi_type_i8;
114}
115template<>
116inline MPI_Datatype &get_mpi_type<u64>() {
117 return mpi_type_u64;
118}
119template<>
120inline MPI_Datatype &get_mpi_type<u32>() {
121 return mpi_type_u32;
122}
123
124#ifdef __MACH__ // On normal Linux size_t is u64
125 // https://stackoverflow.com/questions/40807833/sending-size-t-type-data-with-mpi
126 #if SIZE_MAX == UCHAR_MAX
127 #define _MPI_TYPE_SIZE_T MPI_UNSIGNED_CHAR;
128 #elif SIZE_MAX == USHRT_MAX
129 #define _MPI_TYPE_SIZE_T MPI_UNSIGNED_SHORT;
130 #elif SIZE_MAX == UINT_MAX
131 #define _MPI_TYPE_SIZE_T MPI_UNSIGNED;
132 #elif SIZE_MAX == ULONG_MAX
133 #define _MPI_TYPE_SIZE_T MPI_UNSIGNED_LONG;
134 #elif SIZE_MAX == ULLONG_MAX
135 #define _MPI_TYPE_SIZE_T MPI_UNSIGNED_LONG_LONG;
136 #else
137 #error "what is happening here?"
138 #endif
139inline MPI_Datatype mpi_type_size_t = _MPI_TYPE_SIZE_T;
140template<>
141inline MPI_Datatype &get_mpi_type<size_t>() {
142 return mpi_type_size_t;
143}
144#endif
145
146template<>
147inline MPI_Datatype &get_mpi_type<u16>() {
148 return mpi_type_u16;
149}
150template<>
151inline MPI_Datatype &get_mpi_type<u8>() {
152 return mpi_type_u8;
153}
154// template<> inline MPI_Datatype & get_mpi_type<f16 >(){return mpi_type_f16 ;}
155template<>
156inline MPI_Datatype &get_mpi_type<f32>() {
157 return mpi_type_f32;
158}
159template<>
160inline MPI_Datatype &get_mpi_type<f64>() {
161 return mpi_type_f64;
162}
163
164template<>
165inline MPI_Datatype &get_mpi_type<i64_2>() {
166 return mpi_type_i64_2;
167}
168template<>
169inline MPI_Datatype &get_mpi_type<i32_2>() {
170 return mpi_type_i32_2;
171}
172template<>
173inline MPI_Datatype &get_mpi_type<i16_2>() {
174 return mpi_type_i16_2;
175}
176template<>
177inline MPI_Datatype &get_mpi_type<i8_2>() {
178 return mpi_type_i8_2;
179}
180template<>
181inline MPI_Datatype &get_mpi_type<u64_2>() {
182 return mpi_type_u64_2;
183}
184template<>
185inline MPI_Datatype &get_mpi_type<u32_2>() {
186 return mpi_type_u32_2;
187}
188template<>
189inline MPI_Datatype &get_mpi_type<u16_2>() {
190 return mpi_type_u16_2;
191}
192template<>
193inline MPI_Datatype &get_mpi_type<u8_2>() {
194 return mpi_type_u8_2;
195}
196// template<> inline MPI_Datatype & get_mpi_type<f16_2 >(){return mpi_type_f16_2 ;}
197template<>
198inline MPI_Datatype &get_mpi_type<f32_2>() {
199 return mpi_type_f32_2;
200}
201template<>
202inline MPI_Datatype &get_mpi_type<f64_2>() {
203 return mpi_type_f64_2;
204}
205
206template<>
207inline MPI_Datatype &get_mpi_type<i64_3>() {
208 return mpi_type_i64_3;
209}
210template<>
211inline MPI_Datatype &get_mpi_type<i32_3>() {
212 return mpi_type_i32_3;
213}
214template<>
215inline MPI_Datatype &get_mpi_type<i16_3>() {
216 return mpi_type_i16_3;
217}
218template<>
219inline MPI_Datatype &get_mpi_type<i8_3>() {
220 return mpi_type_i8_3;
221}
222template<>
223inline MPI_Datatype &get_mpi_type<u64_3>() {
224 return mpi_type_u64_3;
225}
226template<>
227inline MPI_Datatype &get_mpi_type<u32_3>() {
228 return mpi_type_u32_3;
229}
230template<>
231inline MPI_Datatype &get_mpi_type<u16_3>() {
232 return mpi_type_u16_3;
233}
234template<>
235inline MPI_Datatype &get_mpi_type<u8_3>() {
236 return mpi_type_u8_3;
237}
238// template<> inline MPI_Datatype & get_mpi_type<f16_3 >(){return mpi_type_f16_3 ;}
239template<>
240inline MPI_Datatype &get_mpi_type<f32_3>() {
241 return mpi_type_f32_3;
242}
243template<>
244inline MPI_Datatype &get_mpi_type<f64_3>() {
245 return mpi_type_f64_3;
246}
247
248template<>
249inline MPI_Datatype &get_mpi_type<i64_4>() {
250 return mpi_type_i64_4;
251}
252template<>
253inline MPI_Datatype &get_mpi_type<i32_4>() {
254 return mpi_type_i32_4;
255}
256template<>
257inline MPI_Datatype &get_mpi_type<i16_4>() {
258 return mpi_type_i16_4;
259}
260template<>
261inline MPI_Datatype &get_mpi_type<i8_4>() {
262 return mpi_type_i8_4;
263}
264template<>
265inline MPI_Datatype &get_mpi_type<u64_4>() {
266 return mpi_type_u64_4;
267}
268template<>
269inline MPI_Datatype &get_mpi_type<u32_4>() {
270 return mpi_type_u32_4;
271}
272template<>
273inline MPI_Datatype &get_mpi_type<u16_4>() {
274 return mpi_type_u16_4;
275}
276template<>
277inline MPI_Datatype &get_mpi_type<u8_4>() {
278 return mpi_type_u8_4;
279}
280// template<> inline MPI_Datatype & get_mpi_type<f16_4 >(){return mpi_type_f16_4 ;}
281template<>
282inline MPI_Datatype &get_mpi_type<f32_4>() {
283 return mpi_type_f32_4;
284}
285template<>
286inline MPI_Datatype &get_mpi_type<f64_4>() {
287 return mpi_type_f64_4;
288}
289
290template<>
291inline MPI_Datatype &get_mpi_type<i64_8>() {
292 return mpi_type_i64_8;
293}
294template<>
295inline MPI_Datatype &get_mpi_type<i32_8>() {
296 return mpi_type_i32_8;
297}
298template<>
299inline MPI_Datatype &get_mpi_type<i16_8>() {
300 return mpi_type_i16_8;
301}
302template<>
303inline MPI_Datatype &get_mpi_type<i8_8>() {
304 return mpi_type_i8_8;
305}
306template<>
307inline MPI_Datatype &get_mpi_type<u64_8>() {
308 return mpi_type_u64_8;
309}
310template<>
311inline MPI_Datatype &get_mpi_type<u32_8>() {
312 return mpi_type_u32_8;
313}
314template<>
315inline MPI_Datatype &get_mpi_type<u16_8>() {
316 return mpi_type_u16_8;
317}
318template<>
319inline MPI_Datatype &get_mpi_type<u8_8>() {
320 return mpi_type_u8_8;
321}
322// template<> inline MPI_Datatype & get_mpi_type<f16_8 >(){return mpi_type_f16_8 ;}
323template<>
324inline MPI_Datatype &get_mpi_type<f32_8>() {
325 return mpi_type_f32_8;
326}
327template<>
328inline MPI_Datatype &get_mpi_type<f64_8>() {
329 return mpi_type_f64_8;
330}
331
332template<>
333inline MPI_Datatype &get_mpi_type<i64_16>() {
334 return mpi_type_i64_16;
335}
336template<>
337inline MPI_Datatype &get_mpi_type<i32_16>() {
338 return mpi_type_i32_16;
339}
340template<>
341inline MPI_Datatype &get_mpi_type<i16_16>() {
342 return mpi_type_i16_16;
343}
344template<>
345inline MPI_Datatype &get_mpi_type<i8_16>() {
346 return mpi_type_i8_16;
347}
348template<>
349inline MPI_Datatype &get_mpi_type<u64_16>() {
350 return mpi_type_u64_16;
351}
352template<>
353inline MPI_Datatype &get_mpi_type<u32_16>() {
354 return mpi_type_u32_16;
355}
356template<>
357inline MPI_Datatype &get_mpi_type<u16_16>() {
358 return mpi_type_u16_16;
359}
360template<>
361inline MPI_Datatype &get_mpi_type<u8_16>() {
362 return mpi_type_u8_16;
363}
364// template<> inline MPI_Datatype & get_mpi_type<f16_16 >(){return mpi_type_f16_16 ;}
365template<>
366inline MPI_Datatype &get_mpi_type<f32_16>() {
367 return mpi_type_f32_16;
368}
369template<>
370inline MPI_Datatype &get_mpi_type<f64_16>() {
371 return mpi_type_f64_16;
372}
373
374void create_sycl_mpi_types();
375void free_sycl_mpi_types();
376bool is_mpi_sycl_interop_active();
Use this header to include MPI properly.