9.2
general documentation
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-2026 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/*============================================================================
31 * Autoconf-defined macros
32 *============================================================================*/
33
34#if defined(HAVE_CONFIG_H)
35# include "base/cs_config.h"
36#endif
37
38#include <type_traits>
39#include <utility>
40
41/*============================================================================
42 * Internationalization
43 *============================================================================*/
44
45extern "C" {
46
47#if defined(ENABLE_NLS) && defined(HAVE_GETTEXT)
48
49# include <libintl.h>
50# define _(String) dgettext(PACKAGE, String)
51# ifdef gettext_noop
52# define N_(String) gettext_noop(String)
53# else
54# define N_(String) String
55# endif /* gettext_noop */
56
57#else
58
59# define _LIBINTL_H /* Prevent inclusion of <libintl.h> by other files
60 with incorrect or missing checks;
61 TODO locate files causing issues to avoid
62 requiring this workaround */
64# define _(String) (String)
65# define N_(String) String
66# define textdomain(String) (String)
67# define gettext(String) (String)
68# define dgettext(Domain,String) (String)
69# define dcgettext(Domain,String,Type) (String)
70# define bindtextdomain(Domain, Directory) (Domain)
71
72#endif /* ENABLE_NLS && HAVE_GETTEXT */
73
74}
75
76/*============================================================================
77 * Parallelism
78 *============================================================================*/
79
80#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
81
82# include <mpi.h>
83
84# if !defined(MPI_VERSION) /* Defined in up-to-date MPI versions */
85# define MPI_VERSION 1
86# endif
88# if MPI_VERSION == 1
89# define MPI_Info int
90# define MPI_INFO_NULL 0
91# endif
92
93#endif
94
95#if defined(HAVE_OPENMP)
96
97# include <omp.h>
98
99#if _OPENMP >= 201307 /* simd construct available from OpenMP 4.0 */
100#undef HAVE_OPENMP_SIMD
101#define HAVE_OPENMP_SIMD 1
102#endif
103
104#else
105
106// The compiler may sometimes use OpenMP in adapters to external libraries
107// even when OpenMP is disabled for code_saturne due to propagation of
108// compiler flags for external libraries. Filtering those flags would
109// be complex with the current build system, so here the macro
110// defined directly by the compiler is disabled. Note that this could affect
111// external including calls to code_saturne, so a filtering of compiler
112// flags would be preferrable.
113#undef _OPENMP
114
115#endif
116
117/* Do we have accelerator support ? */
118
119#if defined(HAVE_CUDA)
120#define HAVE_ACCEL 1
121#elif defined(HAVE_HIP)
122#define HAVE_ACCEL 1
123#elif defined(HAVE_SYCL)
124#define HAVE_ACCEL 1
125#elif defined(HAVE_OPENMP_TARGET)
126#define HAVE_ACCEL 1
127#endif
128
129/*----------------------------------------------------------------------------
130 * Accelerator stream definitions
131 *----------------------------------------------------------------------------*/
132
133#if defined(HAVE_CUDA) && defined(__CUDACC__)
134using cs_stream_t = cudaStream_t;
135#elif defined(HAVE_HIP) && defined(__HIPCC__)
136using cs_stream_t = hipStream_t;
137#else
138using cs_stream_t = void *;
139#endif
140
141/*============================================================================
142 * Qualifiers and macros
143 *============================================================================*/
144
145# if defined(__GNUC__) || defined(__clang__) || defined (__NVCC__)
146# define restrict __restrict__
147# elif defined(_MSC_VER)
148# define restrict __restrict
149# else
150# ifndef HAVE_RESTRICT /* Must be provided by caller */
151# define restrict
152# endif
153# endif
154
155/* Macros for locally suppressing warnings from external libraries */
156#if (defined(__GNUC__) || defined(__clang__)) \
157 && !defined(CS_DONT_SUPPRESS_EXTERNAL_WARNINGS)
158# define DO_PRAGMA(x) _Pragma (#x)
159# define DISABLE_WARNING_PUSH _Pragma("GCC diagnostic push")
160# define DISABLE_WARNING(warningName) \
161 DO_PRAGMA(GCC diagnostic ignored #warningName)
162# define DISABLE_WARNING_POP _Pragma("GCC diagnostic pop")
163// Define LLVM only warnings suppression (needed for clang/oneapi compilers
164# if defined(__llvm__)
165# define DISABLE_WARNING_LLVM(warningName) \
166 DISABLE_WARNING(warningName)
167# else
168# define DISABLE_WARNING_LLVM(warningName)
169# endif
170#else
171# define DISABLE_WARNING_PUSH
172# define DISABLE_WARNING(warningName)
173# define DISABLE_WARNING_POP
174# define DISABLE_WARNING_LLVM(warningName)
175#endif
176
177/*============================================================================
178 * Definitions that may not always be provided directly by the system
179 *============================================================================*/
180
181/*
182 * Obtain definitions such as that of size_t through stddef.h (C99 standard)
183 * if available (preferred method), or through stdlib.h (which defines
184 * malloc() and family and so must define size_t some way) otherwise.
185 */
186
187#if HAVE_STDDEF_H
188# include <stddef.h>
189#else
190# include <stdlib.h>
191#endif
192
193/*
194 * Usually stdint.h is included by inttypes.h, but only inttypes.h exists
195 * on certain systems, such as Tru64Unix.
196 */
197
198#if HAVE_STDINT_H
199# include <stdint.h>
200#elif HAVE_INTTYPES_H
201# include <inttypes.h>
202#endif
203
204/*
205 * Obtain the definition of off_t.
206 */
207
208#if defined(HAVE_SYS_TYPES_H)
209#include <sys/types.h>
210#endif
211
212/* C++ assert necessary for template */
213#include <typeinfo>
214#include "assert.h"
215
216/* int32_t type */
217
218#if !defined(HAVE_INT32_T)
219# if (SIZEOF_INT == 4)
220typedef int int32_t;
221# elif (SIZEOF_SHORT == 4)
222typedef short int32_t;
223# else
224# error
225# endif
226#endif
227
228/* int64_t type */
229
230#if !defined(HAVE_INT64_T)
231# if (SIZEOF_INT == 8)
232typedef int int64_t;
233# elif (SIZEOF_LONG == 8)
234typedef long int64_t;
235# elif (HAVE_LONG_LONG == 8) /* SIZEOF_LONG_LONG not generally available */
236typedef long long int64_t;
237# else
238# error
239# endif
240#endif
241
242/* uint32_t type */
243
244#if !defined(HAVE_UINT32_T)
245# if (SIZEOF_INT == 4)
246typedef unsigned uint32_t;
247# elif (SIZEOF_SHORT == 4)
248typedef unsigned short uint32_t;
249# else
250# error
251# endif
252#endif
253
254/* uint64_t type */
255
256#if !defined(HAVE_UINT64_T)
257# if (SIZEOF_INT == 8)
258typedef unsigned uint64_t;
259# elif (SIZEOF_LONG == 8)
260typedef unsigned long uint64_t;
261# elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
262typedef unsigned long long uint64_t;
263# else
264# error
265# endif
266#endif
267
268/* __has_builtin is missing in some cases (e.g. nvcc) */
269
270#ifndef __has_builtin
271 #define __has_builtin(x) 0
272#endif
273
274/* Legacy Intel compiler (retired) reports having
275 * __builtin_FILE() and __builtin_LINE() but generates code calling
276 * nonexisting functions with those names, leading to link errors. */
277#if defined(__INTEL_COMPILER)
278# if __INTEL_COMPILER <= 2000
279# define __has_builtin(x) 0
280# endif
281#endif
282
283/*============================================================================
284 * General types and macros used throughout code_saturne
285 *============================================================================*/
286
287extern "C" {
288
289/*----------------------------------------------------------------------------
290 * Variable value type.
291 *----------------------------------------------------------------------------*/
293typedef enum {
295 CS_DATATYPE_NULL, /* empty datatype */
296 CS_CHAR, /* character values */
297 CS_FLOAT, /* 4-byte floating point values */
298 CS_DOUBLE, /* 8-byte floating point values */
299 CS_UINT16, /* 2-byte unsigned integer values */
300 CS_INT32, /* 4-byte signed integer values */
301 CS_INT64, /* 8-byte signed integer values */
302 CS_UINT32, /* 4-byte unsigned integer values */
303 CS_UINT64 /* 8-byte unsigned integer values */
304
306
307/*----------------------------------------------------------------------------
308 * Basic types used by code_saturne
309 * They may be modified here to better map to a given library, with the
310 * following constraints:
311 * - cs_lnum_t must be signed
312 * - cs_gnum_t may be signed or unsigned
313 *----------------------------------------------------------------------------*/
314
315/* Global integer index or number */
316
317#if defined(HAVE_LONG_GNUM)
318 typedef uint64_t cs_gnum_t;
319#else
320 typedef unsigned cs_gnum_t;
321#endif
322
323/* Local integer index or number */
324
325#if defined(HAVE_LONG_LNUM)
326 typedef int64_t cs_lnum_t;
327#else
328 typedef int cs_lnum_t;
329#endif
331/* Other types */
333typedef double cs_coord_t; /* Real number (coordinate value) */
335typedef double cs_real_t; /* Fortran double precision */
336typedef char cs_byte_t; /* Byte (untyped memory unit) */
337typedef unsigned short int cs_flag_t; /* Flag storing metadata */
339typedef double cs_nreal_t; /* Real number (normalized value) */
340typedef double cs_dreal_t; /* Local distance */
341typedef double cs_rreal_t; /* Reconstruction distance */
343/* Vector or array block types */
344
345typedef cs_lnum_t cs_lnum_2_t[2]; /* Vector of 2 local numbers */
346typedef cs_lnum_t cs_lnum_3_t[3]; /* Vector of 3 local numbers */
347
348typedef cs_coord_t cs_coord_3_t[3]; /* Vector of 3 real (coordinate)
349 values */
351typedef cs_real_t cs_real_2_t[2]; /* Vector of 2 real values */
352typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
353typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
354typedef cs_real_t cs_real_6_t[6]; /* Vector of 6 real values
355 (for symmetric tensor) */
356typedef cs_real_t cs_real_9_t[9]; /* Vector of 9 real values */
357typedef cs_real_t cs_real_10_t[10]; /* Vector of 10 real values */
359typedef cs_real_t cs_real_23_t[2][3]; /* Matrix of 2x3 real values */
361typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
362typedef cs_real_t cs_real_66_t[6][6]; /* Matrix of 6x6 real values */
363typedef cs_real_t cs_real_99_t[9][9]; /* Matrix of 9x9 real values */
365typedef cs_real_t cs_real_333_t[3][3][3]; /* tensor of 3x3x3 real values */
367typedef cs_real_t cs_real_34_t[3][4]; /* Matrix of 3x4 real values */
369typedef cs_real_t cs_real_63_t[6][3]; /* Matrix of 6x3 real values */
371typedef cs_real_t cs_real_69_t[6][9]; /* Matrix of 6x9 real values */
373typedef cs_real_33_t cs_real_332_t[2]; /* vector of 2 3x3 matrices
374 of real values */
375typedef cs_real_66_t cs_real_662_t[2]; /* vector of 2 6x6 matrices
376 of real values */
378typedef cs_nreal_t cs_nreal_3_t[3]; /* Vector of normalized real values
379 (i.e. unit vector) */
380typedef cs_dreal_t cs_dreal_3_t[3]; /* Vector joining 2 local coordinates */
381typedef cs_rreal_t cs_rreal_3_t[3]; /* Reconstruction distance Vector */
383typedef struct {
384
385 double val; /* Value */
386 int id; /* Id related to value */
387
389
390/* Vector-valued quantity stored using its measure (i.e. length) and
391 its direction given by a unitary vector */
393typedef struct {
394
395 double meas;
396 double unitv[3];
397
398} cs_nvec3_t;
399
400/* Mappings to MPI datatypes */
401/*---------------------------*/
403#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
404
405# define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
406
407/* MPI type for cs_gnum_t integer type (depends on configuration) */
408
409# if defined(HAVE_LONG_GNUM)
410# if (SIZEOF_LONG == 8)
411# define CS_MPI_GNUM MPI_UNSIGNED_LONG
412# elif (SIZEOF_LONG_LONG == 8)
413# if defined(MPI_UNSIGNED_LONG_LONG)
414# define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
415# elif defined(MPI_LONG_LONG)
416# define CS_MPI_GNUM MPI_LONG_LONG
417# endif
418# endif
419# if !defined(CS_MPI_GNUM)
420# error
421# endif
422# else
423# define CS_MPI_GNUM MPI_UNSIGNED
424# endif
425
426/* MPI type for cs_lnum_t type */
427
428# if defined(HAVE_LONG_LNUM)
429# define CS_MPI_LNUM MPI_LONG
430# else
431# define CS_MPI_LNUM MPI_INT
432# endif
434# define CS_MPI_EFLAG MPI_UNSIGNED /* MPI type for cs_mflag_t type */
435# define CS_MPI_FLAG MPI_UNSIGNED_SHORT /* MPI type for cs_flag_t type */
436# define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
437
438#endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
439
440/* Mappings to code_saturne datatypes */
441/*------------------------------------*/
442
443#if defined(HAVE_LONG_GNUM)
444# define CS_GNUM_TYPE CS_UINT64
445#elif (SIZEOF_INT == 8)
446# define CS_GNUM_TYPE CS_UINT64
447#else
448# define CS_GNUM_TYPE CS_UINT32
449#endif
450
451#if defined(HAVE_LONG_LNUM)
452# if (SIZEOF_LONG == 8)
453# define CS_LNUM_TYPE CS_INT64
454# else
455# define CS_LNUM_TYPE CS_INT32
456# endif
457#else
458# if (SIZEOF_INT == 8)
459# define CS_LNUM_TYPE CS_INT64
460# else
461# define CS_LNUM_TYPE CS_INT32
462# endif
463#endif
464
465#if (SIZEOF_INT == 8)
466# define CS_INT_TYPE CS_INT64
467#else
468# define CS_INT_TYPE CS_INT32
469#endif
470
471#if (SIZEOF_INT == 8)
472# define CS_UINT_TYPE CS_UINT64
473#else
474# define CS_UINT_TYPE CS_UINT32
475#endif
477#define CS_FLAG_TYPE CS_UINT16
478#define CS_EFLAG_TYPE CS_UINT_TYPE
479#define CS_REAL_TYPE CS_DOUBLE
480#define CS_COORD_TYPE CS_DOUBLE
481
482/* Minimum size for OpenMP loops
483 * (will need benchmarking and tuning for various systems)
484 *---------------------------------------------------------*/
485
486#define CS_THR_MIN 128
487
488/* Cache line size, or multiple thereof */
489/*--------------------------------------*/
490
491#define CS_CL_SIZE 64
492
493/*----------------------------------------------------------------------------
494 * Type independent min an max (caution: the argument is evaluated)
495 *----------------------------------------------------------------------------*/
497#define CS_ABS(a) ((a) < 0 ? -(a) : (a))
498#define CS_MIN(a,b) ((a) < (b) ? (a) : (b))
499#define CS_MAX(a,b) ((a) > (b) ? (a) : (b))
501/*----------------------------------------------------------------------------
502 * Variable interlace type:
503 * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
504 * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
505 *----------------------------------------------------------------------------*/
507typedef enum {
508
509 CS_INTERLACE, /* Variable is interlaced */
510 CS_NO_INTERLACE /* Variable is not interlaced */
511
513
514/*----------------------------------------------------------------------------
515 * Macro used to silence "unused argument" warnings.
516 *
517 * This is useful when a function must match a given function pointer
518 * type, but does not use all possible arguments.
519 *----------------------------------------------------------------------------*/
520
521#define CS_UNUSED(x) (void)(x)
522#define CS_NO_WARN_IF_UNUSED(x) (void)(x)
523
524/*----------------------------------------------------------------------------
525 * Macros for compilation with a C++ compiler
526 *----------------------------------------------------------------------------*/
527
528#undef BEGIN_C_DECLS
529#undef END_C_DECLS
530
531#define BEGIN_C_DECLS extern "C" {
532#define END_C_DECLS }
533
534/*----------------------------------------------------------------------------
535 * Macro to check if we are compiling for device
536 *----------------------------------------------------------------------------*/
537
538#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) \
539 || defined(__SYCL_DEVICE_ONLY__)
540#define CS_DEVICE_COMPILE
541#endif
542
543/*----------------------------------------------------------------------------
544 * Macros for function type qualifiers
545 *----------------------------------------------------------------------------*/
546
547#if defined(__CUDACC__) || defined (__HIP_DEVICE_COMPILE__)
548
549#define CS_F_HOST __host__
550#define CS_F_DEVICE __device__
551#define CS_F_HOST_DEVICE __host__ __device__
552#define CS_V_CONSTANT __constant__
554#else
556#define CS_F_HOST
557#define CS_F_DEVICE
558#define CS_F_HOST_DEVICE
559#define CS_V_CONSTANT static const
560
561#endif
562
563/*----------------------------------------------------------------------------
564 * Macros for lambda specifiers
565 *----------------------------------------------------------------------------*/
567#define CS_LAMBDA [=] CS_F_HOST_DEVICE
568#define CS_HOST_LAMBDA [=] CS_F_HOST
569#define CS_CLASS_LAMBDA [=, *this] CS_F_HOST_DEVICE
570
571/*=============================================================================
572 * Global variables
573 *============================================================================*/
574
575/* Empty but non-null string */
576
577extern const char cs_empty_string[];
578
579/* Sizes and names associated with datatypes */
580
581extern const size_t cs_datatype_size[];
582extern const char *cs_datatype_name[];
583
584/* MPI Datatypes associated with code_saturne datatypes */
585
586#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
587
588extern MPI_Datatype cs_datatype_to_mpi[];
589
590#endif
591
592/* Global variables indicating task state */
593
594extern int cs_glob_n_threads; /* Number of threads */
595
596extern int cs_glob_rank_id; /* Rank in main MPI communicator */
597extern int cs_glob_n_ranks; /* Size of main MPI communicator */
598
599extern int cs_glob_node_rank_id; /* Rank on node in main MPI communicator */
600extern int cs_glob_node_n_ranks; /* Number of ranks on node of main
601 MPI communicator */
602
603#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
604
605extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
606
607#endif
608
609/*----------------------------------------------------------------------------
610 * Function pointer types
611 *----------------------------------------------------------------------------*/
612
613/*----------------------------------------------------------------------------*/
621/*----------------------------------------------------------------------------*/
622
623typedef void *
624(cs_destructor_t)(void *s);
625
626/*=============================================================================
627 * Public functions
628 *============================================================================*/
629
630/*----------------------------------------------------------------------------*/
631/*
632 * \brief Given a base index i, return the next index aligned with a size m.
633 *
634 * \param[in] i base index
635 * \param[in] m block size to align with
636 *
637 * \return aligned index
638 */
639/*----------------------------------------------------------------------------*/
640
641inline static cs_lnum_t
643 cs_lnum_t m)
644{
645 return ((i > 0) ? ((i-1)/m+1)*m : 0);
646}
647
648/*----------------------------------------------------------------------------*/
655/*----------------------------------------------------------------------------*/
656
657inline static int
659{
660#if defined(HAVE_OPENMP)
661 return omp_get_thread_num();
662#else
663 return 0;
664#endif
665}
666
667/*----------------------------------------------------------------------------*/
668
669} // extern "C"
670
671/*=============================================================================
672 * Public C++ templates
673 *============================================================================*/
674
675namespace cs {
676
677/*----------------------------------------------------------------------------*/
678/*
679 * \brief Return absolute value of a number.
680 *
681 * This function is overloaded in cs_math.h for floating-point values.
682 *
683 * \tparam T value type
684 *
685 * \param[in] a value
686 *
687 * \return absolute value of a
688 */
689/*----------------------------------------------------------------------------*/
691template <typename T>
692CS_F_HOST_DEVICE inline T
693abs(const T a)
694{
695 return ((a) < 0 ? -(a) : (a));
696}
697
698/*----------------------------------------------------------------------------*/
699/*
700 * \brief Return minimum of two values.
701 *
702 * This function is overloaded in cs_math.h for floating-point values.
703 *
704 * \tparam T value type
705 *
706 * \param[in] a first value
707 * \param[in] b second value
708 *
709 * \return minimum of a and b
710 */
711/*----------------------------------------------------------------------------*/
713template <typename T>
714CS_F_HOST_DEVICE inline T
715min(const T a,
716 const T b)
717{
718 return ((a) < (b) ? (a) : (b));
719}
720
721/*----------------------------------------------------------------------------*/
722/*
723 * \brief Return maximum of two values.
724 *
725 * This function is overloaded in cs_math.h for floating-point values.
726 *
727 * \tparam T value type
728 *
729 * \param[in] a first value
730 * \param[in] b second value
731 *
732 * \return maximum of a and b
733 */
734/*----------------------------------------------------------------------------*/
736template <typename T>
737CS_F_HOST_DEVICE inline T
738max(const T a,
739 const T b)
740{
741 return ((a) > (b) ? (a) : (b));
742}
743
744/*----------------------------------------------------------------------------*/
745/*
746 * \brief Clamp function for a given scalar value.
747 *
748 * This function is overloaded in cs_math.h for floating-point values.
749 *
750 * \tparam T value type
751 *
752 * \param[in] x initial value
753 * \param[in] xmin min value for clamping
754 * \param[in] xmax max value for clamping
755 *
756 * \return clamped value which is 'x' if xmin < x < xmax or lower/upper bound
757 * otherwise
758 */
759/*----------------------------------------------------------------------------*/
761template <typename T>
762CS_F_HOST_DEVICE inline T
763clamp(const T x,
764 const T xmin,
765 const T xmax)
766{
767 T x_tmp = ((xmin) > (x) ? (xmin) : (x));
768 return ((xmax) < (x_tmp) ? (xmax) : (x_tmp));
769}
770
771/*----------------------------------------------------------------------------*/
775/*----------------------------------------------------------------------------*/
777template <class... Args>
778struct are_integral {
779 enum : bool { value = true};
780};
781
782/*----------------------------------------------------------------------------*/
783
784template <typename T, class... Args>
785struct are_integral<T, Args...> {
786 enum {
787 value = (std::is_integral<T>::value || std::is_enum<T>::value)
789 };
790};
791
792/*----------------------------------------------------------------------------*/
798/*----------------------------------------------------------------------------*/
799
800template <typename... Args>
801struct always_true : std::true_type {};
802
803/*--------------------------------------------------------------------------*/
809/*--------------------------------------------------------------------------*/
810
811template <class T>
813constexpr
814std::enable_if_t<std::is_move_constructible<T>::value &&
815 std::is_move_assignable<T>::value>
817(
818 T& obj1,
819 T& obj2
820)
821{
822 T tmp(std::move(obj1));
823 obj1 = std::move(obj2);
824 obj2 = std::move(tmp);
825}
826
827/*--------------------------------------------------------------------------*/
834/*--------------------------------------------------------------------------*/
835
836template <class T, std::size_t N>
838constexpr
839void
841(
842 T (&obj1)[N],
843 T (&obj2)[N]
844)
845{
846 for (std::size_t i = 0; i < N; ++i)
847 swap_objects(obj1[i], obj2[i]);
848}
849
850/*--------------------------------------------------------------------------*/
856/*--------------------------------------------------------------------------*/
857
858template<typename Id1>
860inline
861unsigned int
863(
864 Id1 val
865)
866{
867 static_assert(std::is_integral<Id1>::value, "Non integral input arguments.");
868
869 unsigned int retval = 1;
870 while (val >= 10) {
871 val /= 10;
872 retval += 1;
873 }
874
875 return retval;
876}
877
878/*--------------------------------------------------------------------------*/
882/*--------------------------------------------------------------------------*/
883
884template<typename Id1>
886inline
887void
889(
890 char *dest,
891 Id1 val
892)
893{
894 static_assert(std::is_integral<Id1>::value, "Non integral input arguments.");
895 assert(val >= 0);
896
897 unsigned int n_digits = number_of_digits(val);
898 int pos = n_digits - 1;
899
900 if (val == 0) {
901 dest[0] = '0';
902 dest[1] = '\0';
903 }
904 else {
905 Id1 v = val;
906 while (v > 0) {
907 auto const num = v % 10;
908 v /= 10;
909 dest[pos] = '0' + num;
910 --pos;
911 }
912 }
913}
914
915/*--------------------------------------------------------------------------*/
919/*--------------------------------------------------------------------------*/
920
922inline
923void
925(
926 char *dest,
927 const char *src
928)
929{
930 int dst_pos = 0;
931 while (dest[dst_pos] != 0) {
932 dst_pos += 1;
933 }
934
935 int i = 0;
936 while (src[i] != 0) {
937 dest[i + dst_pos] = src[i];
938 i += 1;
939 }
940}
941
942/*----------------------------------------------------------------------------*/
943
944} // namespace cs
945
946/*----------------------------------------------------------------------------*/
952/*----------------------------------------------------------------------------*/
953
954template <typename T>
955struct dependent_false : std::false_type {};
957template <typename T>
958static inline cs_datatype_t
960{
961 static_assert(dependent_false<T>::value, "Unknown datatype");
962 return CS_DATATYPE_NULL;
963}
964
965/*----------------------------------------------------------------------------*/
966/* Specialized versions of the templated function */
967/*----------------------------------------------------------------------------*/
968
969template <>
970constexpr inline cs_datatype_t
972{
973 return CS_CHAR;
974}
975
976/*----------------------------------------------------------------------------*/
977
978template <>
979constexpr inline cs_datatype_t
981{
982 return CS_FLOAT;
983}
984
985/*----------------------------------------------------------------------------*/
986
987template <>
988constexpr inline cs_datatype_t
990{
991 return CS_DOUBLE;
992}
993
994/*----------------------------------------------------------------------------*/
995
996template <>
997constexpr inline cs_datatype_t
999{
1000 return CS_UINT16;
1001}
1002
1003/*----------------------------------------------------------------------------*/
1004
1005template <>
1006constexpr inline cs_datatype_t
1008{
1009 return CS_UINT32;
1010}
1011
1012/*----------------------------------------------------------------------------*/
1013
1014template <>
1015constexpr inline cs_datatype_t
1017{
1018 return CS_UINT64;
1019}
1020
1021/*----------------------------------------------------------------------------*/
1022
1023template <>
1024constexpr inline cs_datatype_t
1026{
1027 return CS_INT32;
1028}
1029
1030/*----------------------------------------------------------------------------*/
1031
1032template <>
1033constexpr inline cs_datatype_t
1035{
1036 return CS_INT64;
1037}
1038
1039/*----------------------------------------------------------------------------*/
1040
1041#endif /* CS_DEFS_H */
int cs_glob_n_ranks
Definition: cs_defs.cpp:171
cs_datatype_t
Definition: cs_defs.h:290
@ CS_FLOAT
Definition: cs_defs.h:294
@ CS_CHAR
Definition: cs_defs.h:293
@ CS_UINT16
Definition: cs_defs.h:296
@ CS_INT64
Definition: cs_defs.h:298
@ CS_UINT64
Definition: cs_defs.h:300
@ CS_DOUBLE
Definition: cs_defs.h:295
@ CS_UINT32
Definition: cs_defs.h:299
@ CS_INT32
Definition: cs_defs.h:297
@ CS_DATATYPE_NULL
Definition: cs_defs.h:292
cs_lnum_t cs_lnum_3_t[3]
Definition: cs_defs.h:343
const char * cs_datatype_name[]
Definition: cs_defs.cpp:139
void * cs_stream_t
Definition: cs_defs.h:135
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:555
constexpr cs_datatype_t cs_datatype_from_type< int32_t >()
Definition: cs_defs.h:1022
constexpr cs_datatype_t cs_datatype_from_type< uint16_t >()
Definition: cs_defs.h:995
char cs_byte_t
Definition: cs_defs.h:333
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
void *() cs_destructor_t(void *s)
Destroy a given structure.
Definition: cs_defs.h:621
cs_rreal_t cs_rreal_3_t[3]
Definition: cs_defs.h:378
constexpr cs_datatype_t cs_datatype_from_type< char >()
Definition: cs_defs.h:968
const size_t cs_datatype_size[]
Definition: cs_defs.cpp:129
static cs_datatype_t cs_datatype_from_type()
Definition: cs_defs.h:956
cs_real_33_t cs_real_332_t[2]
vector of 2 3x3 matrices of floating-point values
Definition: cs_defs.h:370
int cs_glob_node_rank_id
Definition: cs_defs.cpp:173
cs_real_t cs_real_69_t[6][9]
Definition: cs_defs.h:368
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:375
const char cs_empty_string[]
Definition: cs_defs.cpp:125
int cs_glob_n_threads
Definition: cs_defs.cpp:168
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:342
static int cs_get_thread_id(void)
Retrieve the associated thread id (0 if no OpenMP or if outside an OpenMP region)
Definition: cs_defs.h:655
int cs_glob_node_n_ranks
Definition: cs_defs.cpp:174
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition: cs_defs.h:350
MPI_Datatype cs_datatype_to_mpi[]
Definition: cs_defs.cpp:153
double cs_dreal_t
Definition: cs_defs.h:337
cs_real_t cs_real_10_t[10]
Definition: cs_defs.h:354
cs_real_t cs_real_99_t[9][9]
Definition: cs_defs.h:360
double cs_coord_t
Definition: cs_defs.h:330
cs_real_t cs_real_34_t[3][4]
Definition: cs_defs.h:364
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:359
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
cs_coord_t cs_coord_3_t[3]
Definition: cs_defs.h:345
cs_real_66_t cs_real_662_t[2]
Definition: cs_defs.h:372
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:348
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
constexpr cs_datatype_t cs_datatype_from_type< int64_t >()
Definition: cs_defs.h:1031
constexpr cs_datatype_t cs_datatype_from_type< float >()
Definition: cs_defs.h:977
cs_interlace_t
Definition: cs_defs.h:504
@ CS_INTERLACE
Definition: cs_defs.h:506
@ CS_NO_INTERLACE
Definition: cs_defs.h:507
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:351
static cs_lnum_t cs_align(cs_lnum_t i, cs_lnum_t m)
Given a base index i, return the next index aligned with a size m.
Definition: cs_defs.h:639
cs_dreal_t cs_dreal_3_t[3]
Definition: cs_defs.h:377
constexpr cs_datatype_t cs_datatype_from_type< double >()
Definition: cs_defs.h:986
cs_real_t cs_real_333_t[3][3][3]
Definition: cs_defs.h:362
double cs_rreal_t
Definition: cs_defs.h:338
constexpr cs_datatype_t cs_datatype_from_type< uint32_t >()
Definition: cs_defs.h:1004
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:358
MPI_Comm cs_glob_mpi_comm
Definition: cs_defs.cpp:179
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:366
double cs_nreal_t
Definition: cs_defs.h:336
constexpr cs_datatype_t cs_datatype_from_type< uint64_t >()
Definition: cs_defs.h:1013
cs_real_t cs_real_9_t[9]
Definition: cs_defs.h:353
cs_real_t cs_real_23_t[2][3]
Definition: cs_defs.h:356
unsigned short int cs_flag_t
Definition: cs_defs.h:334
int cs_glob_rank_id
Definition: cs_defs.cpp:170
Definition: cs_algorithm.h:51
CS_F_HOST_DEVICE T max(const T a, const T b)
Definition: cs_defs.h:735
CS_F_HOST_DEVICE unsigned int number_of_digits(Id1 val)
Count number of digits in an integer.
Definition: cs_defs.h:860
CS_F_HOST_DEVICE T clamp(const T x, const T xmin, const T xmax)
Definition: cs_defs.h:760
CS_F_HOST_DEVICE void concatenate_char(char *dest, const char *src)
Concatenate two strings (char *)
Definition: cs_defs.h:922
CS_F_HOST_DEVICE T min(const T a, const T b)
Definition: cs_defs.h:712
CS_F_HOST_DEVICE void uint_to_char(char *dest, Id1 val)
Convert an unsigned integer to an array of char.
Definition: cs_defs.h:886
CS_F_HOST_DEVICE constexpr std::enable_if_t< std::is_move_constructible< T >::value &&std::is_move_assignable< T >::value > swap_objects(T &obj1, T &obj2)
A swap method which is callable from GPU and not only CPU.
Definition: cs_defs.h:814
CS_F_HOST_DEVICE T abs(const T a)
Definition: cs_defs.h:690
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:798
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:775
@ value
Definition: cs_defs.h:776
Definition: cs_defs.h:380
Definition: cs_defs.h:390
Get the cs_datatype_t from a typename.
Definition: cs_defs.h:952