9.2
general documentation
cs_numbering.h
Go to the documentation of this file.
1#ifndef CS_NUMBERING_H
2#define CS_NUMBERING_H
3
4/*============================================================================
5 * Numbering information for vectorization or multithreading
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 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35#include "base/cs_base.h"
36#include "base/cs_log.h"
37
38/*============================================================================
39 * Macro definitions
40 *============================================================================*/
41
42/* SIMD unit length */
43/*------------------*/
44
45#if defined(__NEC__) && defined(__ve__) /* For NEC Aurora series */
46
47# define CS_NUMBERING_SIMD_SIZE 256
48
49#elif defined(SX) && defined(_SX) /* For NEC SX series (at least SX-9) */
50
51# define CS_NUMBERING_SIMD_SIZE 256
52
53#elif defined(__AVX512F__) /* For Intel with AVX 512 */
54
55# define CS_NUMBERING_SIMD_SIZE 64
56
57#elif defined(HAVE_CUDA) /* For CUDA devices (warp size) */
58
59# define CS_NUMBERING_SIMD_SIZE 32
60
61#elif defined(HAVE_HIP) /* For HIP devices (use warp size) */
62
63#if defined(__GFX8__) || defined(__GFX9__)
64# define CS_NUMBERING_SIMD_SIZE 64
65#else
66# define CS_NUMBERING_SIMD_SIZE 32
67#endif
68
69#else
70
71# define CS_NUMBERING_SIMD_SIZE 4 /* Most current platforms */
72
73#endif
74
75/*============================================================================
76 * Type definitions
77 *============================================================================*/
78
79/* Renumbering types */
80
81typedef enum {
82
83 CS_NUMBERING_DEFAULT, /* Default numbering */
84 CS_NUMBERING_VECTORIZE, /* Numbered for vectorization */
85 CS_NUMBERING_THREADS /* Numbered for threads */
86
88
89/* Renumbering structure */
90
91typedef struct {
92
93 cs_numbering_type_t type; /* Numbering type */
94
95 int vector_size; /* Vector size if vectorized, 1 otherwise */
96
97 int n_threads; /* Number of threads */
98 int n_groups; /* Number of associated groups */
99
100 int n_no_adj_halo_groups; /* number of groups for which only non-ghost
101 entities are adjacent */
102
103 cs_lnum_t n_no_adj_halo_elts; /* Number of elements not adjacent to
104 halo elements */
105
106 cs_lnum_t *group_index; /* For thread t and group g, the start and
107 past-the-end ids for entities in a given
108 group and thread are respectively:
109 group_index[t*n_groups*2 + g] and
110 group_index[t*n_groups*2 + g + 1].
111 (size: n_groups * n_threads * 2) */
112
114
115/*=============================================================================
116 * Global variable definitions
117 *============================================================================*/
118
119/* Names for numbering types */
120
121extern const char *cs_numbering_type_name[];
122
123/*=============================================================================
124 * Public function prototypes
125 *============================================================================*/
126
127/*----------------------------------------------------------------------------*/
136/*----------------------------------------------------------------------------*/
137
138static inline size_t
140 size_t type_size)
141{
142 size_t simd_bytes = CS_NUMBERING_SIMD_SIZE * 8;
143 size_t elt_bytes = n_elts * type_size;
144 size_t n_ceil = (((elt_bytes-1)/simd_bytes+1)*simd_bytes);
145 return n_ceil / type_size;
146}
147
148/*----------------------------------------------------------------------------*/
156/*----------------------------------------------------------------------------*/
157
160
161/*----------------------------------------------------------------------------*/
171/*----------------------------------------------------------------------------*/
172
175 int vector_size);
176
177/*----------------------------------------------------------------------------*/
192/*----------------------------------------------------------------------------*/
193
195cs_numbering_create_threaded(int n_threads,
196 int n_groups,
197 cs_lnum_t group_index[]);
198
199/*----------------------------------------------------------------------------*/
206/*----------------------------------------------------------------------------*/
207
208void
210
211/*----------------------------------------------------------------------------*/
219/*----------------------------------------------------------------------------*/
220
221void
223 const char *description,
224 const cs_numbering_t *numbering);
225
226/*----------------------------------------------------------------------------*/
232/*----------------------------------------------------------------------------*/
233
234void
235cs_numbering_dump(const cs_numbering_t *numbering);
236
237/*----------------------------------------------------------------------------*/
238
239#endif /* CS_NUMBERING_H */
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_log_t
Definition: cs_log.h:44
cs_numbering_t * cs_numbering_create_threaded(int n_threads, int n_groups, cs_lnum_t group_index[])
Create a default numbering information structure in case of threading.
Definition: cs_numbering.cpp:590
cs_numbering_t * cs_numbering_create_vectorized(cs_lnum_t n_elts, int vector_size)
Create a default numbering information structure in case of vectorization.
Definition: cs_numbering.cpp:548
void cs_numbering_log_info(cs_log_t log, const char *description, const cs_numbering_t *numbering)
Log information relative to a cs_numbering_t structure.
Definition: cs_numbering.cpp:648
cs_numbering_t * cs_numbering_create_default(cs_lnum_t n_elts)
Create a default numbering information structure.
Definition: cs_numbering.cpp:512
void cs_numbering_destroy(cs_numbering_t **numbering)
Destroy a numbering information structure.
Definition: cs_numbering.cpp:627
static size_t cs_numbering_simd_size(cs_lnum_t n_elts, size_t type_size)
Round size of array to ensure SIMD alignment.
Definition: cs_numbering.h:139
const char * cs_numbering_type_name[]
Definition: cs_numbering.cpp:69
cs_numbering_type_t
Definition: cs_numbering.h:81
@ CS_NUMBERING_THREADS
Definition: cs_numbering.h:85
@ CS_NUMBERING_VECTORIZE
Definition: cs_numbering.h:84
@ CS_NUMBERING_DEFAULT
Definition: cs_numbering.h:83
#define CS_NUMBERING_SIMD_SIZE
Definition: cs_numbering.h:71
void cs_numbering_dump(const cs_numbering_t *numbering)
Dump a cs_numbering_t structure.
Definition: cs_numbering.cpp:733
Definition: cs_numbering.h:91
cs_lnum_t * group_index
Definition: cs_numbering.h:106
int n_no_adj_halo_groups
Definition: cs_numbering.h:100
int vector_size
Definition: cs_numbering.h:95
cs_numbering_type_t type
Definition: cs_numbering.h:93
int n_threads
Definition: cs_numbering.h:97
int n_groups
Definition: cs_numbering.h:98
cs_lnum_t n_no_adj_halo_elts
Definition: cs_numbering.h:103