GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
types.h
Go to the documentation of this file.
1 
6 #ifndef GHOST_TYPES_H
7 #define GHOST_TYPES_H
8 
9 #include "config.h"
10 
11 #define GHOST_ALLREDUCE -1
12 
13 #ifdef GHOST_HAVE_MPI
14 #include <mpi.h>
15 typedef MPI_Comm ghost_mpi_comm;
16 typedef MPI_Op ghost_mpi_op;
17 typedef MPI_Datatype ghost_mpi_datatype;
18 #else
19 typedef int ghost_mpi_comm;
20 typedef int ghost_mpi_op;
21 typedef int ghost_mpi_datatype;
22 #define MPI_COMM_NULL 0
23 #define MPI_COMM_SELF 1
24 #define MPI_OP_NULL 0
25 #define MPI_DATATYPE_NULL 0
26 #define MPI_COMM_WORLD 0
27 #endif
28 
29 #include "error.h"
30 
31 #include <inttypes.h>
32 #include <stdint.h>
33 #include <stdbool.h>
34 #include <sys/types.h>
35 
36 #ifndef __cplusplus
37 #include <complex.h>
38 #endif
39 
40 #define SELECT_TMPL_2DATATYPES(dt1,dt2,complexclass,ret,func,...)\
41  if (dt1 & GHOST_DT_COMPLEX) {\
42  if (dt1 & GHOST_DT_DOUBLE) {\
43  if (dt2 & GHOST_DT_COMPLEX) {\
44  if (dt2 & GHOST_DT_DOUBLE) {\
45  ret = func<complexclass<double>,complexclass<double> >(__VA_ARGS__);\
46  } else {\
47  ret = func<complexclass<double>,complexclass<float> >(__VA_ARGS__);\
48  }\
49  } else {\
50  if (dt2 & GHOST_DT_DOUBLE) {\
51  ret = func<complexclass<double>,double>(__VA_ARGS__);\
52  } else {\
53  GHOST_WARNING_LOG("Incompatible data types!");\
54  }\
55  }\
56  } else {\
57  if (dt2 & GHOST_DT_COMPLEX) {\
58  if (dt2 & GHOST_DT_DOUBLE) {\
59  ret = func<complexclass<float>,complexclass<double> >(__VA_ARGS__);\
60  } else {\
61  ret = func<complexclass<float>,complexclass<float> >(__VA_ARGS__);\
62  }\
63  } else {\
64  if (dt2 & GHOST_DT_DOUBLE) {\
65  GHOST_WARNING_LOG("Incompatible data types!");\
66  } else {\
67  ret = func<complexclass<float>,float>(__VA_ARGS__);\
68  }\
69  }\
70  }\
71  } else {\
72  if (dt1 & GHOST_DT_DOUBLE) {\
73  if (dt2 & GHOST_DT_COMPLEX) {\
74  if (dt2 & GHOST_DT_DOUBLE) {\
75  ret = func<double,complexclass<double> >(__VA_ARGS__);\
76  } else {\
77  GHOST_WARNING_LOG("Incompatible data types!");\
78  }\
79  } else {\
80  if (dt2 & GHOST_DT_DOUBLE) {\
81  ret = func<double,double>(__VA_ARGS__);\
82  } else {\
83  ret = func<double,float>(__VA_ARGS__);\
84  }\
85  }\
86  } else {\
87  if (dt2 & GHOST_DT_COMPLEX) {\
88  if (dt2 & GHOST_DT_DOUBLE) {\
89  GHOST_WARNING_LOG("Incompatible data types!");\
90  } else {\
91  ret = func<float,complexclass<float> >(__VA_ARGS__);\
92  }\
93  } else {\
94  if (dt2 & GHOST_DT_DOUBLE) {\
95  ret = func<float,double>(__VA_ARGS__);\
96  } else {\
97  ret = func<float,float>(__VA_ARGS__);\
98  }\
99  }\
100  }\
101  }\
102 
107 #define SELECT_TMPL_2DATATYPES_base_derived(dt1,dt2,complexclass,ret,func,...)\
108  if (dt1 & GHOST_DT_COMPLEX) {\
109  if (dt1 & GHOST_DT_DOUBLE) {\
110  if (dt2 & GHOST_DT_COMPLEX) {\
111  if (dt2 & GHOST_DT_DOUBLE) {\
112  ret = func<complexclass<double>,complexclass<double> >(__VA_ARGS__);\
113  } else {\
114  /* ret = func<complexclass<double>,complexclass<float> >(__VA_ARGS__);*/\
115  }\
116  } else {\
117  ret = GHOST_ERR_DATATYPE; \
118  }\
119  } else {\
120  if (dt2 & GHOST_DT_COMPLEX) {\
121  if (dt2 & GHOST_DT_DOUBLE) {\
122  /* ret = func<complexclass<float>,complexclass<double> >(__VA_ARGS__);*/\
123  } else {\
124  ret = func<complexclass<float>,complexclass<float> >(__VA_ARGS__);\
125  }\
126  } else {\
127  ret = GHOST_ERR_DATATYPE; \
128  }\
129  }\
130  } else {\
131  if (dt1 & GHOST_DT_DOUBLE) {\
132  if (dt2 & GHOST_DT_COMPLEX) {\
133  if (dt2 & GHOST_DT_DOUBLE) {\
134  ret = func<double,complexclass<double> >(__VA_ARGS__);\
135  } else {\
136  /*ret = func<double,complexclass<float> >(__VA_ARGS__);*/\
137  }\
138  } else {\
139  if (dt2 & GHOST_DT_DOUBLE) {\
140  ret = func<double,double>(__VA_ARGS__);\
141  } else {\
142  /*ret = func<double,float>(__VA_ARGS__);*/\
143  } \
144  }\
145  } else {\
146  if (dt2 & GHOST_DT_COMPLEX) {\
147  if (dt2 & GHOST_DT_DOUBLE) {\
148  /* ret = func<float,complexclass<double> >(__VA_ARGS__);*/\
149  } else {\
150  ret = func<float,complexclass<float> >(__VA_ARGS__);\
151  }\
152  } else {\
153  if (dt2 & GHOST_DT_DOUBLE) {\
154  /*ret = func<float,double>(__VA_ARGS__);*/\
155  } else {\
156  ret = func<float,float>(__VA_ARGS__);\
157  }\
158  }\
159  }\
160  }\
161 
162 
165 #define SELECT_TMPL_4DATATYPES(dt1,dt2,complexclass,ret,func,...)\
166  if (dt1 & GHOST_DT_COMPLEX) {\
167  if (dt1 & GHOST_DT_DOUBLE) {\
168  if (dt2 & GHOST_DT_COMPLEX) {\
169  if (dt2 & GHOST_DT_DOUBLE) {\
170  ret = func<cuDoubleComplex,complexclass<double>,cuDoubleComplex,double>(__VA_ARGS__);\
171  } else {\
172  ret = func<cuDoubleComplex,complexclass<float>,cuFloatComplex,float>(__VA_ARGS__);\
173  }\
174  } else {\
175  if (dt2 & GHOST_DT_DOUBLE) {\
176  ret = func<cuDoubleComplex,double,double,double>(__VA_ARGS__);\
177  } else {\
178  ret = func<cuDoubleComplex,float,float,float>(__VA_ARGS__);\
179  }\
180  }\
181  } else {\
182  if (dt2 & GHOST_DT_COMPLEX) {\
183  if (dt2 & GHOST_DT_DOUBLE) {\
184  ret = func<cuFloatComplex,complexclass<double>,cuDoubleComplex,double>(__VA_ARGS__);\
185  } else {\
186  ret = func<cuFloatComplex,complexclass<float>,cuFloatComplex,float>(__VA_ARGS__);\
187  }\
188  } else {\
189  if (dt2 & GHOST_DT_DOUBLE) {\
190  ret = func<cuFloatComplex,double,double,double>(__VA_ARGS__);\
191  } else {\
192  ret = func<cuFloatComplex,float,float,float>(__VA_ARGS__);\
193  }\
194  }\
195  }\
196  } else {\
197  if (dt1 & GHOST_DT_DOUBLE) {\
198  if (dt2 & GHOST_DT_COMPLEX) {\
199  if (dt2 & GHOST_DT_DOUBLE) {\
200  ret = func<double,complexclass<double>,cuDoubleComplex,double>(__VA_ARGS__);\
201  } else {\
202  ret = func<double,complexclass<float>,cuFloatComplex,float>(__VA_ARGS__);\
203  }\
204  } else {\
205  if (dt2 & GHOST_DT_DOUBLE) {\
206  ret = func<double,double,double,double>(__VA_ARGS__);\
207  } else {\
208  ret = func<double,float,float,float>(__VA_ARGS__);\
209  }\
210  }\
211  } else {\
212  if (dt2 & GHOST_DT_COMPLEX) {\
213  if (dt2 & GHOST_DT_DOUBLE) {\
214  ret = func<float,complexclass<double>,cuDoubleComplex,double>(__VA_ARGS__);\
215  } else {\
216  ret = func<float,complexclass<float>,cuFloatComplex,float>(__VA_ARGS__);\
217  }\
218  } else {\
219  if (dt2 & GHOST_DT_DOUBLE) {\
220  ret = func<float,double,double,double>(__VA_ARGS__);\
221  } else {\
222  ret = func<float,float,float,float>(__VA_ARGS__);\
223  }\
224  }\
225  }\
226  }\
227 
228 #define SELECT_TMPL_1DATATYPE(dt,complexclass,ret,func,...)\
229  if (dt & GHOST_DT_COMPLEX) {\
230  if (dt & GHOST_DT_DOUBLE) {\
231  ret = func<complexclass<double> >(__VA_ARGS__);\
232  } else {\
233  ret = func<complexclass<float> >(__VA_ARGS__);\
234  }\
235  } else {\
236  if (dt & GHOST_DT_DOUBLE) {\
237  ret = func<double>(__VA_ARGS__);\
238  } else {\
239  ret = func<float>(__VA_ARGS__);\
240  }\
241  }\
242 
243 
248 typedef enum {
266 
267 #define GHOST_DT_ANY (ghost_datatype)-1
268 #define GHOST_DT_NONE (ghost_datatype)0
269 
270 typedef enum {
283 }
285 
286 
287 #define GHOST_HOST_IDX 0
288 #define GHOST_DEVICE_IDX 1
289 
290 
291 #ifdef __cplusplus
292 inline ghost_location operator&(const ghost_location &a, const ghost_location &b) {
293  return static_cast<ghost_location>(static_cast<int>(a) & static_cast<int>(b));
294 }
295 inline ghost_location operator|(const ghost_location &a, const ghost_location &b) {
296  return static_cast<ghost_location>(static_cast<int>(a) | static_cast<int>(b));
297 }
298 inline ghost_location& operator&=(ghost_location &a, const ghost_location &b) {
299  a = static_cast<ghost_location>(static_cast<int>(a) & static_cast<int>(b));
300  return a;
301 }
302 inline ghost_location& operator|=(ghost_location &a, const ghost_location &b) {
303  a = static_cast<ghost_location>(static_cast<int>(a) | static_cast<int>(b));
304  return a;
305 }
306 // Melven: somehow this doesn't compile here (with GCC)
307 //inline ghost_datatype operator|(const ghost_datatype &a, const ghost_datatype &b) {
308 // return static_cast<ghost_datatype>(static_cast<int>(a) | static_cast<int>(b));
309 //}
310 #endif
311 
315 typedef enum {
319 
323 typedef enum {
332 
338 typedef enum {
356 
360 #define GHOST_DT_MAX_SIZE 16
361 
371 #define GHOST_REGISTER_DT_D(name) \
372  typedef double name ## _t; \
373 ghost_datatype name = (ghost_datatype)(GHOST_DT_DOUBLE|GHOST_DT_REAL); \
374 
375 
378 #define GHOST_REGISTER_DT_S(name) \
379  typedef float name ## _t; \
380 ghost_datatype name = (ghost_datatype)(GHOST_DT_FLOAT|GHOST_DT_REAL); \
381 
382 #ifdef __cplusplus
383 
386 #define GHOST_REGISTER_DT_C(name) \
387  typedef std::complex<float> name ## _t; \
388 ghost_datatype name = (ghost_datatype)(GHOST_DT_FLOAT|GHOST_DT_COMPLEX);
389 #else
390 
393 #define GHOST_REGISTER_DT_C(name) \
394  typedef complex float name ## _t; \
395 ghost_datatype name = (ghost_datatype)(GHOST_DT_FLOAT|GHOST_DT_COMPLEX);
396 #endif
397 
398 #ifdef __cplusplus
399 
402 #define GHOST_REGISTER_DT_Z(name) \
403  typedef std::complex<double> name ## _t; \
404 ghost_datatype name = (ghost_datatype)(GHOST_DT_DOUBLE|GHOST_DT_COMPLEX);
405 #else
406 
409 #define GHOST_REGISTER_DT_Z(name) \
410  typedef complex double name ## _t; \
411 ghost_datatype name = (ghost_datatype)(GHOST_DT_DOUBLE|GHOST_DT_COMPLEX);
412 #endif
413 
414 #ifdef GHOST_IDX64_GLOBAL
415 
419 typedef int64_t ghost_gidx;
420 #ifdef MPI_INT64_T
421 
424 #define ghost_mpi_dt_gidx MPI_INT64_T
425 #else
426 #ifdef GHOST_HAVE_MPI
427 #warning "Assuming that MPI_LONG_LONG_INT is 64 bits long"
428 #endif
429 #define ghost_mpi_dt_gidx MPI_LONG_LONG_INT
430 #endif
431 
434 #define PRGIDX PRId64
435 
436 #define GHOST_GIDX_MAX INT64_MAX
437 
438 #else
439 
443 typedef int32_t ghost_gidx;
444 #ifdef MPI_INT32_T
445 
448 #define ghost_mpi_dt_gidx MPI_INT32_T
449 #else
450 #ifdef GHOST_HAVE_MPI
451 #warning "Assuming that MPI_INT is 32 bits long"
452 #endif
453 #define ghost_mpi_dt_gidx MPI_INT
454 #endif
455 
458 #define PRGIDX PRId32
459 
460 #define GHOST_GIDX_MAX INT32_MAX
461 
462 #endif
463 
464 #ifdef GHOST_IDX64_LOCAL
465 
469 typedef int64_t ghost_lidx;
470 #ifdef MPI_INT64_T
471 
474 #define ghost_mpi_dt_lidx MPI_INT64_T
475 #else
476 #ifdef GHOST_HAVE_MPI
477 #warning "Assuming that MPI_LONG_LONG_INT is 64 bits long"
478 #endif
479 #define ghost_mpi_dt_gidx MPI_LONG_LONG_INT
480 #endif
481 
484 #define PRLIDX PRId64
485 
486 #ifdef GHOST_HAVE_MKL
487 
490 typedef long long int ghost_blas_idx;
491 #define PRBLASIDX PRId64
492 #else
493 typedef int ghost_blas_idx;
494 #define PRBLASIDX PRId32
495 #endif
496 
497 #define PRLIDX PRId64
498 
499 #define GHOST_LIDX_MAX INT64_MAX
500 
501 #else
502 
503 typedef int32_t ghost_lidx;
504 #ifdef MPI_INT32_T
505 #define ghost_mpi_dt_lidx MPI_INT32_T
506 #else
507 #ifdef GHOST_HAVE_MPI
508 #warning "Assuming that MPI_INT is 32 bits long"
509 #endif
510 #define ghost_mpi_dt_lidx MPI_INT
511 #endif
512 typedef int ghost_blas_idx;
513 #define PRBLASIDX PRId32
514 
515 #define PRLIDX PRId32
516 
517 #define GHOST_LIDX_MAX INT32_MAX
518 
519 #endif
520 
521 #if defined(GHOST_IDX64_LOCAL) && defined(GHOST_IDX64_GLOBAL)
522 #define GHOST_IDX_UNIFORM
523 #endif
524 
525 #if !defined(GHOST_IDX64_LOCAL) && !defined(GHOST_IDX64_GLOBAL)
526 #define GHOST_IDX_UNIFORM
527 #endif
528 
529 
530 #define PRIDX PRGIDX
531 #define ghost_mpi_dt_idx ghost_mpi_dt_gidx
532 
533 
534 
535 typedef struct ghost_mpi_c ghost_mpi_c;
536 typedef struct ghost_mpi_z ghost_mpi_z;
537 
538 
543 {
544  float x;
545  float y;
546 };
547 
552 {
553  double x;
554  double y;
555 };
556 
557 #ifdef __cplusplus
558 extern "C" {
559 #endif
560 
571  bool ghost_datatype_valid(ghost_datatype datatype);
581  const char * ghost_datatype_string(ghost_datatype datatype);
582  const char * ghost_location_string(ghost_location location);
583  const char * ghost_implementation_string(ghost_implementation implementation);
586  ghost_error ghost_datatype_size(size_t *size, ghost_datatype datatype);
590 
592 
593 #ifdef __cplusplus
594 }
595 #endif
596 
597 #endif
ghost_implementation
Possible implementations of a CPU function.
Definition: types.h:323
const char * ghost_location_string(ghost_location location)
Definition: types.c:197
ghost_error ghost_datatype_idx_get(ghost_datatype_idx *idx, ghost_datatype datatype)
Definition: types.c:145
Definition: types.h:325
Data is located on host.
Definition: types.h:278
ghost_error ghost_mpi_datatype_get(ghost_mpi_datatype *dt, ghost_datatype datatype)
Definition: types.c:8
int32_t ghost_gidx
Type for global indices.
Definition: types.h:443
Definition: types.h:324
Definition: types.h:328
int32_t ghost_lidx
Definition: types.h:503
int ghost_blas_idx
Definition: types.h:512
Types, functions and macros for error handling.
int ghost_mpi_comm
Definition: types.h:19
Complex numbers.
Definition: types.h:264
Single precision.
Definition: types.h:252
Definition: types.h:316
Double precision.
Definition: types.h:256
ghost_error
Error return type.
Definition: error.h:23
ghost_error ghost_datatype_size(size_t *size, ghost_datatype datatype)
Definition: types.c:67
ghost_alignment
Possible alignments of data access.
Definition: types.h:315
Real numbers.
Definition: types.h:260
Definition: types.h:326
Definition: types.h:330
Real double.
Definition: types.h:346
Definition: types.h:327
Default location. This is only a placeholder and the actual location has to be specified by GHOST...
Definition: types.h:274
bool ghost_datatype_valid(ghost_datatype datatype)
Check whether a given data type is valid.
Definition: types.c:91
ghost_datatype
Available primitive data types.
Definition: types.h:248
float x
Definition: types.h:544
int ghost_mpi_datatype
Definition: types.h:21
ghost_error ghost_mpi_datatypes_create()
Definition: types.c:37
Definition: types.h:329
Data is located on device (accelerator, GPU).
Definition: types.h:282
int ghost_mpi_op
Definition: types.h:20
double x
Definition: types.h:553
double y
Definition: types.h:554
ghost_error ghost_mpi_datatypes_destroy()
Definition: types.c:55
A float complex number (used for MPI).
Definition: types.h:542
ghost_datatype_idx
Contiguous indices for data types.
Definition: types.h:338
const char * ghost_datatype_string(ghost_datatype datatype)
Stringify a ghost_datatype.
Definition: types.c:118
const char * ghost_implementation_string(ghost_implementation implementation)
Definition: types.c:215
float y
Definition: types.h:545
Real float.
Definition: types.h:342
ghost_location
Definition: types.h:270
Definition: types.h:317
Complex float.
Definition: types.h:350
A double complex number (used for MPI).
Definition: types.h:551
ghost_error ghost_idx2datatype(ghost_datatype *datatype, ghost_datatype_idx idx)
Definition: types.c:171
Complex double.
Definition: types.h:354
int ghost_idx_of_location(ghost_location l)
Definition: types.c:238