SpM Handbook 1.2.4
Loading...
Searching...
No Matches
datatypes.h
Go to the documentation of this file.
1/**
2 *
3 * @file spm/datatypes.h
4 *
5 * @copyright 2013-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6 * Univ. Bordeaux. All rights reserved.
7 *
8 * Definitions of the datatypes used in SPM
9 *
10 * @version 1.2.4
11 * @author Mathieu Faverge
12 * @author Pierre Ramet
13 * @author Tony Delarue
14 * @author Alycia Lisito
15 * @date 2024-05-29
16 *
17 */
18#ifndef _spm_datatypes_h_
19#define _spm_datatypes_h_
20
21#include <inttypes.h>
22#include "spm/config.h"
23
24BEGIN_C_DECLS
25
26/**
27 * @addtogroup spm
28 * @{
29 * @def SPM_MPI_INT
30 * @brief The MPI type associated to spm_int_t
31 *
32 * @def SPM_INT_MAX
33 * @brief The maximum spm_int_t value
34 *
35 * @typedef spm_int_t
36 * @brief The main integer datatype used in spm arrays
37 *
38 * @typedef spm_uint_t
39 * @brief The main unsigned integer datatype used in spm arrays
40 *
41 * @typedef spm_complex64_t
42 * @brief The double complex arithmetic datatype
43 *
44 * @typedef spm_complex32_t
45 * @brief The real complex arithmetic datatype
46 */
47#if defined(SPM_INT64)
48
49typedef int64_t spm_int_t;
50typedef uint64_t spm_uint_t;
51#define SPM_MPI_INT MPI_INTEGER8
52#define SPM_INT_MAX INT64_MAX
53
54#elif defined(SPM_INT32)
55
56typedef int32_t spm_int_t;
57typedef uint32_t spm_uint_t;
58#define SPM_MPI_INT MPI_INTEGER4
59#define SPM_INT_MAX INT32_MAX
60
61#elif defined(SPM_LONG)
62
63typedef long spm_int_t;
64typedef unsigned long spm_uint_t;
65#define SPM_MPI_INT MPI_LONG
66#define SPM_INT_MAX LONG_MAX
67
68#else
69
70typedef int spm_int_t;
71typedef unsigned int spm_uint_t;
72#define SPM_MPI_INT MPI_INT
73#define SPM_INT_MAX INT_MAX
74
75#endif
76/**
77 *@}
78 */
79
80/**
81 *******************************************************************************
82 *
83 * @ingroup spm_dev
84 * @brief Internal function to compute min(a,b)
85 *
86 *******************************************************************************
87 *
88 * @param[in] a
89 * @param[in] b
90 *
91 *******************************************************************************
92 *
93 * @return min( a, b )
94 *
95 ********************************************************************************/
96static inline spm_int_t
98{
99 return ( a < b ) ? a : b;
100}
101
102/**
103 *******************************************************************************
104 *
105 * @ingroup spm_dev
106 * @brief Internal function to compute max(a,b)
107 *
108 *******************************************************************************
109 *
110 * @param[in] a
111 * @param[in] b
112 *
113 *******************************************************************************
114 *
115 * @return max( a, b )
116 *
117 ********************************************************************************/
118static inline spm_int_t
120{
121 return ( a > b ) ? a : b;
122}
123
124/**
125 *******************************************************************************
126 *
127 * @ingroup spm_dev
128 * @brief Internal function to compute ceil(a,b)
129 *
130 *******************************************************************************
131 *
132 * @param[in] a
133 * @param[in] b
134 *
135 *******************************************************************************
136 *
137 * @return ceil( a, b )
138 *
139 ********************************************************************************/
140static inline spm_int_t
142{
143 return ( a + b - 1 ) / b;
144}
145
146/**
147 * @ingroup spm_dev
148 * @brief Double datatype that is not converted through precision generator functions
149 */
150typedef double spm_fixdbl_t;
151
152/**
153 * Complex numbers (Extracted from PaRSEC project)
154 **/
155#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
156/* Windows and non-Intel compiler */
157#include <complex>
158typedef std::complex<float> spm_complex32_t;
159typedef std::complex<double> spm_complex64_t;
160#else
161typedef float _Complex spm_complex32_t;
162typedef double _Complex spm_complex64_t;
163#endif
164
165#if !defined(__cplusplus) && defined(HAVE_COMPLEX_H)
166#include <complex.h>
167#else
168
169/**
170 * These declarations will not clash with what C++ provides because
171 * the names in C++ are name-mangled.
172 */
173#ifndef DOXYGEN_SHOULD_SKIP_THIS
174extern double cabs ( spm_complex64_t z );
175extern double creal( spm_complex64_t z );
176extern double cimag( spm_complex64_t z );
177
178extern float cabsf ( spm_complex32_t z );
179extern float crealf( spm_complex32_t z );
180extern float cimagf( spm_complex32_t z );
181
182extern spm_complex64_t conj ( spm_complex64_t z );
183extern spm_complex64_t csqrt( spm_complex64_t z );
184
185extern spm_complex32_t conjf ( spm_complex32_t z );
186extern spm_complex32_t csqrtf( spm_complex32_t z );
187#endif /* DOXYGEN_SHOULD_SKIP_THIS */
188
189#endif /* HAVE_COMPLEX_H */
190
191/**
192 *******************************************************************************
193 *
194 * @ingroup spm_dev
195 * @brief Double datatype that is not converted through precision generator
196 * functions
197 *
198 *******************************************************************************
199 *
200 * @param[in] type
201 * TODO
202 *
203 *******************************************************************************
204 *
205 * @retval TODO
206 *
207 ********************************************************************************/
208static inline size_t
210{
211 switch ( type ) {
212 case SpmPattern:
213 return 0;
214 case SpmFloat:
215 return sizeof( float );
216 case SpmDouble:
217 return sizeof( double );
218 case SpmComplex32:
219 return 2 * sizeof( float );
220 case SpmComplex64:
221 return 2 * sizeof( double );
222 default:
223 fprintf( stderr, "spm_size_of: invalid type parameter\n" );
224 assert( 0 );
225 return sizeof( double );
226 }
227}
228
229struct spmatrix_s;
230
231/**
232 * @brief Type alias to the spmatrix_s structure.
233 */
234typedef struct spmatrix_s spmatrix_t;
235
236END_C_DECLS
237
238#endif /* _spm_datatypes_h_ */
static size_t spm_size_of(spm_coeftype_t type)
Double datatype that is not converted through precision generator functions.
Definition datatypes.h:209
double spm_fixdbl_t
Double datatype that is not converted through precision generator functions.
Definition datatypes.h:150
static spm_int_t spm_iceil(spm_int_t a, spm_int_t b)
Internal function to compute ceil(a,b)
Definition datatypes.h:141
static spm_int_t spm_imin(spm_int_t a, spm_int_t b)
Internal function to compute min(a,b)
Definition datatypes.h:97
float _Complex spm_complex32_t
Definition datatypes.h:161
static spm_int_t spm_imax(spm_int_t a, spm_int_t b)
Internal function to compute max(a,b)
Definition datatypes.h:119
enum spm_coeftype_e spm_coeftype_t
Arithmetic types.
@ SpmComplex64
Definition const.h:66
@ SpmDouble
Definition const.h:64
@ SpmFloat
Definition const.h:63
@ SpmComplex32
Definition const.h:65
@ SpmPattern
Definition const.h:62
unsigned int spm_uint_t
The main unsigned integer datatype used in spm arrays.
Definition datatypes.h:71
int spm_int_t
The main integer datatype used in spm arrays.
Definition datatypes.h:70
The sparse matrix data structure.
Definition spm.h:64