Code_Saturne
CFD tool
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cs_defs.h
Go to the documentation of this file.
1 #ifndef __CS_DEFS_H__
2 #define __CS_DEFS_H__
3 
4 /*============================================================================
5  * Base macro and typedef definitions for system portability
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2012 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #if 0
33 } /* Fake brace to force Emacs auto-indentation back to column 0 */
34 #endif
35 #endif /* __cplusplus */
36 
37 /*============================================================================
38  * Autoconf-defined macros
39  *============================================================================*/
40 
41 #if defined(HAVE_CONFIG_H)
42 # include "cs_config.h"
43 #endif
44 
45 /*============================================================================
46  * Internationalization
47  *============================================================================*/
48 
49 #if defined(ENABLE_NLS) && defined(HAVE_GETTEXT)
50 
51 # include <libintl.h>
52 # define _(String) dgettext(PACKAGE, String)
53 # ifdef gettext_noop
54 # define N_(String) gettext_noop(String)
55 # else
56 # define N_(String) String
57 # endif /* gettext_noop */
58 
59 #else
60 
61 # define _(String) (String)
62 # define N_(String) String
63 # define textdomain(String) (String)
64 # define gettext(String) (String)
65 # define dgettext(Domain,String) (String)
66 # define dcgettext(Domain,String,Type) (String)
67 # define bindtextdomain(Domain, Directory) (Domain)
68 
69 #endif /* ENABLE_NLS && HAVE_GETTEXT */
70 
71 /*============================================================================
72  * Parallelism
73  *============================================================================*/
74 
75 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
76 # include <mpi.h>
77 #endif
78 
79 #if defined(HAVE_OPENMP)
80 # include <omp.h>
81 #endif
82 
83 /*============================================================================
84  * C99 Qualifiers
85  *============================================================================*/
86 
87 /* inline provided by cs_config.h if necessary */
88 
89 #if !defined(__STDC_VERSION__)
90 # define __STDC_VERSION__ 1989
91 #endif
92 
93 /*
94  * Redefinition of "inline" et "restrict" qualifiers incompatible with
95  * some C89 compilers (standard in C99)
96  */
97 
98 #if (__STDC_VERSION__ < 199901L)
99 
100 # if defined(__GNUC__)
101 # define inline __inline__
102 # define restrict __restrict__
103 # else
104 # define inline
105 # define restrict
106 # endif
107 
108 #endif
109 
110 /*============================================================================
111  * Definitions that may not always be provided directly by the system
112  *============================================================================*/
113 
114 /*
115  * Obtain definitions such as that of size_t through stddef.h (C99 standard)
116  * if available (preferred method), or through stdlib.h (which defines
117  * malloc() and family and so must define size_t some way) otherwise.
118  */
119 
120 #if HAVE_STDDEF_H
121 # include <stddef.h>
122 #else
123 # include <stdlib.h>
124 #endif
125 
126 /*
127  * Usually stdint.h is included by inttypes.h, but only inttypes.h exists
128  * on certain systems, such as Tru64Unix.
129  */
130 
131 #if HAVE_STDINT_H
132 # include <stdint.h>
133 #elif HAVE_INTTYPES_H
134 # include <inttypes.h>
135 #endif
136 
137 /*
138  * Obtain the definition of off_t.
139  */
140 
141 #if defined(HAVE_SYS_TYPES_H)
142 #include <sys/types.h>
143 #endif
144 
145 /* C99 _Bool type */
146 
147 #if HAVE_STDBOOL_H
148 # include <stdbool.h>
149 #else
150 # ifndef HAVE__BOOL
151 # ifdef __cplusplus
152 typedef bool _Bool;
153 # else
154 # define _Bool signed char;
155 # endif
156 # endif
157 # define bool _Bool
158 # define false 0
159 # define true 1
160 # define __bool_true_false_are_defined 1
161 #endif
162 
163 /* int32_t type */
164 
165 #if !defined(HAVE_INT32_T)
166 # if (SIZEOF_INT == 4)
167 typedef int int32_t;
168 # elif (SIZEOF_SHORT == 4)
169 typedef short int32_t;
170 # else
171 # error
172 # endif
173 #endif
174 
175 /* int64_t type */
176 
177 #if !defined(HAVE_INT64_T)
178 # if (SIZEOF_INT == 8)
179 typedef int int64_t;
180 # elif (SIZEOF_LONG == 8)
181 typedef long int64_t;
182 # elif (HAVE_LONG_LONG == 8) /* SIZEOF_LONG_LONG not generally available */
183 typedef long long int64_t;
184 # else
185 # error
186 # endif
187 #endif
188 
189 /* uint32_t type */
190 
191 #if !defined(HAVE_UINT32_T)
192 # if (SIZEOF_INT == 4)
193 typedef unsigned uint32_t;
194 # elif (SIZEOF_SHORT == 4)
195 typedef unsigned short uint32_t;
196 # else
197 # error
198 # endif
199 #endif
200 
201 /* uint64_t type */
202 
203 #if !defined(HAVE_UINT64_T)
204 # if (SIZEOF_INT == 8)
205 typedef unsigned uint64_t;
206 # elif (SIZEOF_LONG == 8)
207 typedef unsigned long uint64_t;
208 # elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
209 typedef unsigned long long uint64_t;
210 # else
211 # error
212 # endif
213 #endif
214 
215 /*============================================================================
216  * General types and macros used throughout Code_Saturne
217  *============================================================================*/
218 
219 /*----------------------------------------------------------------------------
220  * Variable value type.
221  *----------------------------------------------------------------------------*/
222 
223 typedef enum {
224 
225  CS_DATATYPE_NULL, /* empty datatype */
226  CS_CHAR, /* character values */
227  CS_FLOAT, /* 4-byte floating point values */
228  CS_DOUBLE, /* 8-byte floating point values */
229  CS_INT32, /* 4-byte signed integer values */
230  CS_INT64, /* 8-byte signed integer values */
231  CS_UINT32, /* 4-byte unsigned integer values */
232  CS_UINT64 /* 8-byte unsigned integer values */
233 
234 } cs_datatype_t;
235 
236 /*----------------------------------------------------------------------------
237  * Basic types used by Code_Saturne
238  * They may be modified here to better map to a given library, with the
239  * following constraints:
240  * - cs_lnum_t must be signed
241  * - cs_gnum_t may be signed or unsigned
242  *----------------------------------------------------------------------------*/
243 
244 /* Global integer index or number */
245 
246 #if defined(HAVE_LONG_GNUM)
247  #if (SIZEOF_LONG == 8)
248  typedef unsigned long cs_gnum_t;
249  #elif (SIZEOF_LONG_LONG == 8)
250  typedef unsigned long long cs_gnum_t;
251  #else
252  #error
253  #endif
254 #else
255  typedef unsigned cs_gnum_t;
256 #endif
257 
258 /* Other types */
259 
260 typedef int cs_lnum_t; /* Local integer index or number */
261 typedef double cs_coord_t; /* Real number (coordinate value) */
262 
263 typedef int cs_int_t; /* Fortran integer */
264 typedef double cs_real_t; /* Fortran double precision */
265 typedef char cs_byte_t; /* Byte (untyped memory unit) */
266 
267 /* Vector or array block types */
268 
269 typedef cs_lnum_t cs_lnum_2_t[2]; /* Vector of 2 local numbers */
270 
271 typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
272 typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
273 typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
274 
275 /* Mappings to MPI datatypes */
276 /*---------------------------*/
277 
278 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
279 
280 # define CS_MPI_INT MPI_INT /* If cs_int_t is an int */
281 # define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
282 
283 /* MPI type for cs_gnum_t integer type (depends on configuration) */
284 
285 # if defined(HAVE_LONG_GNUM)
286 # if (SIZEOF_LONG == 8)
287 # define CS_MPI_GNUM MPI_UNSIGNED_LONG
288 # elif (SIZEOF_LONG_LONG == 8)
289 # if defined(MPI_UNSIGNED_LONG_LONG)
290 # define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
291 # elif defined(MPI_LONG_LONG)
292 # define CS_MPI_GNUM MPI_LONG_LONG
293 # endif
294 # endif
295 # if !defined(CS_MPI_GNUM)
296 # error
297 # endif
298 # else
299 # define CS_MPI_GNUM MPI_UNSIGNED
300 # endif
301 
302 # define CS_MPI_LNUM MPI_INT /* MPI type for cs_lnum_t type */
303 # define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
304 
305 #endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
306 
307 /* Mappings to Code_Saturne datatypes */
308 /*------------------------------------*/
309 
310 #if defined(HAVE_LONG_GNUM)
311 # define CS_GNUM_TYPE CS_UINT64
312 #elif (SIZEOF_INT == 8)
313 # define CS_GNUM_TYPE CS_UINT64
314 #else
315 # define CS_GNUM_TYPE CS_UINT32
316 #endif
317 
318 #if (SIZEOF_INT == 8)
319 # define CS_LNUM_TYPE CS_INT64
320 #else
321 # define CS_LNUM_TYPE CS_INT32
322 #endif
323 
324 #if (SIZEOF_INT == 8)
325 # define CS_INT_TYPE CS_INT64
326 #else
327 # define CS_INT_TYPE CS_INT32
328 #endif
329 
330 #define CS_REAL_TYPE CS_DOUBLE
331 #define CS_COORD_TYPE CS_DOUBLE
332 
333 /*----------------------------------------------------------------------------
334  * Type independent min an max (caution: the argument is evaluated)
335  *----------------------------------------------------------------------------*/
336 
337 #define CS_ABS(a) ((a) < 0 ? -(a) : (a)) /* Absolute value of a */
338 #define CS_MIN(a,b) ((a) < (b) ? (a) : (b)) /* Minimum of a et b */
339 #define CS_MAX(a,b) ((a) > (b) ? (a) : (b)) /* Maximum of a et b */
340 
341 /*----------------------------------------------------------------------------
342  * Variable interlace type:
343  * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
344  * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
345  *----------------------------------------------------------------------------*/
346 
347 typedef enum {
348 
349  CS_INTERLACE, /* Variable is interlaced */
350  CS_NO_INTERLACE /* Variable is not interlaced */
351 
353 
354 /*----------------------------------------------------------------------------
355  * Macros for compilation with a C++ compiler
356  *----------------------------------------------------------------------------*/
357 
358 #undef BEGIN_C_DECLS
359 #undef END_C_DECLS
360 
361 #if defined(__cplusplus)
362 # define BEGIN_C_DECLS extern "C" {
363 # define END_C_DECLS }
364 #else
365 # define BEGIN_C_DECLS
366 # define END_C_DECLS
367 #endif
368 
369 /*----------------------------------------------------------------------------
370  * Macros for Fortran interoperability
371  *----------------------------------------------------------------------------*/
372 
373 /*
374  * Macro for handling of different symbol names (underscored or not,
375  * lowercase or uppercase) between C and Fortran, for link resolution.
376  */
377 
378 #if !defined (__hpux)
379 #define CS_PROCF(x, y) x##_
380 #else
381 #define CS_PROCF(x, y) x
382 #endif
383 
384 /*
385  * Macro used to handle automatic "Fortran string length" arguments
386  * (not used by Code_Saturne calls, but set by many compilers).
387  * Some compilers, like the Fujitsu VPP 5000 compiler, may not
388  * support the variable length lists in mixed C/Fortran calls.
389  */
390 
391 #if defined (__uxpv__) /* Fujitsu VPP 5000 case */
392 #define CS_ARGF_SUPP_CHAINE
393 #else
394 #define CS_ARGF_SUPP_CHAINE , ...
395 #endif
396 
397 /*=============================================================================
398  * Global variables
399  *============================================================================*/
400 
401 /* Sizes and names associated with datatypes */
402 
403 extern const size_t cs_datatype_size[];
404 extern const char *cs_datatype_name[];
405 
406 /* MPI Datatypes associated with Code_Saturne datatypes */
407 
408 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
409 
410 extern MPI_Datatype cs_datatype_to_mpi[];
411 
412 #endif
413 
414 /* Global variables indicationg task state */
415 
416 extern int cs_glob_n_threads; /* Number of threads */
417 
418 extern int cs_glob_rank_id; /* Rank in main MPI communicator */
419 extern int cs_glob_n_ranks; /* Size of main MPI communicator */
420 
421 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
422 
423 extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
424 
425 #endif
426 
427 /*----------------------------------------------------------------------------*/
428 
429 #ifdef __cplusplus
430 }
431 #endif /* __cplusplus */
432 
433 #endif /* __CS_DEFS_H__ */
cs_datatype_t
Definition: cs_defs.h:223
Definition: cs_defs.h:230
Definition: cs_defs.h:229
Definition: cs_defs.h:349
cs_real_t cs_real_4_t[4]
Definition: cs_defs.h:272
char cs_byte_t
Definition: cs_defs.h:265
cs_interlace_t
Definition: cs_defs.h:347
Definition: cs_defs.h:225
int cs_glob_n_ranks
Definition: cs_defs.c:82
Definition: cs_defs.h:232
int cs_int_t
Definition: cs_defs.h:263
double cs_coord_t
Definition: cs_defs.h:261
Definition: cs_defs.h:350
int cs_lnum_t
Definition: cs_defs.h:260
Definition: cs_defs.h:227
int cs_glob_n_threads
Definition: cs_defs.c:79
unsigned cs_gnum_t
Definition: cs_defs.h:255
Definition: cs_defs.h:231
const size_t cs_datatype_size[]
Definition: cs_defs.c:43
Definition: cs_defs.h:226
double cs_real_t
Definition: cs_defs.h:264
const char * cs_datatype_name[]
Definition: cs_defs.c:52
cs_real_t cs_real_3_t[3]
Definition: cs_defs.h:271
Definition: cs_defs.h:228
int cs_glob_rank_id
Definition: cs_defs.c:81
#define _Bool
Definition: cs_defs.h:154
cs_real_t cs_real_33_t[3][3]
Definition: cs_defs.h:273
cs_lnum_t cs_lnum_2_t[2]
Definition: cs_defs.h:269