Code_Saturne
CFD tool
cs_matrix_priv.h
Go to the documentation of this file.
1 #ifndef __CS_MATRIX_PRIV_H__
2 #define __CS_MATRIX_PRIV_H__
3 
4 /*============================================================================
5  * Private types for sparse matrix representation and operations.
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 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_defs.h"
35 
36 #include "cs_matrix.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*=============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 /* Formats currently supported:
51  *
52  * - Native
53  * - Compressed Sparse Row (CSR)
54  * - Symmetric Compressed Sparse Row (CSR_SYM)
55  */
56 
57 /*----------------------------------------------------------------------------
58  * Function pointer types
59  *----------------------------------------------------------------------------*/
60 
61 typedef void
63  bool symmetric,
64  bool interleaved,
65  bool copy,
66  const cs_real_t *restrict da,
67  const cs_real_t *restrict xa);
68 
69 typedef void
71 
72 typedef void
74  cs_real_t *restrict da);
75 
76 typedef void
77 (cs_matrix_vector_product_t) (bool exclude_diag,
78  const cs_matrix_t *matrix,
79  const cs_real_t *restrict x,
80  cs_real_t *restrict y);
81 
82 
83 /*----------------------------------------------------------------------------
84  * Matrix types
85  *----------------------------------------------------------------------------*/
86 
87 /* Native matrix structure representation */
88 /*----------------------------------------*/
89 
90 /* Note: the members of this structure are already available through the top
91  * matrix structure, but are replicated here in case of future removal
92  * from the top structure (which would require computation/assignment of
93  * matrix coefficients in another form) */
94 
96 
97  cs_lnum_t n_cells; /* Local number of cells */
98  cs_lnum_t n_cells_ext; /* Local number of participating cells
99  (cells + ghost cells sharing a face) */
100  cs_lnum_t n_faces; /* Local number of faces
101  (for extra-diagonal terms */
102 
103  /* Pointers to shared arrays */
104 
105  const cs_lnum_t *face_cell; /* Face -> cells connectivity (1 to n) */
106 
108 
109 /* Native matrix coefficients */
110 /*----------------------------*/
111 
113 
114  bool symmetric; /* Symmetry indicator */
115  int max_block_size; /* Current max allocated block size */
116 
117  /* Pointers to possibly shared arrays */
118 
119  const cs_real_t *da; /* Diagonal terms */
120  const cs_real_t *xa; /* Extra-diagonal terms */
121 
122  /* Pointers to private arrays (NULL if shared) */
123 
124  cs_real_t *_da; /* Diagonal terms */
125  cs_real_t *_xa; /* Extra-diagonal terms */
126 
128 
129 /* CSR (Compressed Sparse Row) matrix structure representation */
130 /*-------------------------------------------------------------*/
131 
132 typedef struct _cs_matrix_struct_csr_t {
133 
134  cs_lnum_t n_rows; /* Local number of rows */
135  cs_lnum_t n_cols; /* Local number of columns
136  (> n_rows in case of ghost cells) */
137  cs_lnum_t n_cols_max; /* Maximum number of nonzero values
138  on a given row */
139 
140  /* Pointers to structure arrays and info (row_index, col_id) */
141 
142  bool have_diag; /* Has non-zero diagonal */
143  bool direct_assembly; /* True if each value corresponds to
144  a unique face ; false if multiple
145  faces contribute to the same
146  value (i.e. we have split faces) */
147 
148  cs_lnum_t *row_index; /* Row index (0 to n-1) */
149  cs_lnum_t *col_id; /* Column id (0 to n-1) */
150 
152 
153 /* CSR matrix coefficients representation */
154 /*----------------------------------------*/
155 
156 typedef struct _cs_matrix_coeff_csr_t {
157 
158  int n_prefetch_rows; /* Number of rows at a time for which
159  the x values in y = Ax should be
160  prefetched (0 if no prefetch) */
161 
162  cs_real_t *val; /* Matrix coefficients */
163 
164  cs_real_t *x_prefetch; /* Prefetch array for x in y = Ax */
165 
166  /* Pointers to auxiliary arrays used for queries */
167 
168  const cs_real_t *d_val; /* Pointer to diagonal matrix
169  coefficients, if queried */
170  cs_real_t *_d_val; /* Diagonal matrix coefficients,
171  if queried */
172 
174 
175 /* CSR_SYM (Symmetric Compressed Sparse Row) matrix structure representation */
176 /*---------------------------------------------------------------------------*/
177 
179 
180  cs_lnum_t n_rows; /* Local number of rows */
181  cs_lnum_t n_cols; /* Local number of columns
182  (> n_rows in case of ghost cells) */
183  cs_lnum_t n_cols_max; /* Maximum number of nonzero values
184  on a given row */
185 
186  /* Pointers to structure arrays and info (row_index, col_id) */
187 
188  bool have_diag; /* Has non-zero diagonal */
189  bool direct_assembly; /* True if each value corresponds to
190  a unique face ; false if multiple
191  faces contribute to the same
192  value (i.e. we have split faces) */
193 
194  cs_lnum_t *row_index; /* Row index (0 to n-1) */
195  cs_lnum_t *col_id; /* Column id (0 to n-1) */
196 
198 
199 /* symmetric CSR matrix coefficients representation */
200 /*--------------------------------------------------*/
201 
203 
204  cs_real_t *val; /* Matrix coefficients */
205 
206  /* Pointers to auxiliary arrays used for queries */
207 
208  const cs_real_t *d_val; /* Pointer to diagonal matrix
209  coefficients, if queried */
210  cs_real_t *_d_val; /* Diagonal matrix coefficients,
211  if queried */
212 
214 
215 /* MSR matrix coefficients representation */
216 /*----------------------------------------*/
217 
218 typedef struct _cs_matrix_coeff_msr_t {
219 
220  int n_prefetch_rows; /* Number of rows at a time for which
221  the x values in y = Ax should be
222  prefetched (0 if no prefetch) */
223  int max_block_size; /* Current max allocated block size */
224 
225  /* Pointers to possibly shared arrays */
226 
227  const cs_real_t *d_val; /* Diagonal matrix coefficients */
228 
229  /* Pointers to private arrays (NULL if shared) */
230 
231  cs_real_t *_d_val; /* Diagonal matrix coefficients */
232  cs_real_t *x_val; /* Extra-diagonal matrix coefficients */
233 
234  cs_real_t *x_prefetch; /* Prefetch array for x in y = Ax */
235 
237 
238 /* Matrix structure (representation-independent part) */
239 /*----------------------------------------------------*/
240 
242 
243  cs_matrix_type_t type; /* Matrix storage and definition type */
244 
245  cs_lnum_t n_cells; /* Local number of cells */
246  cs_lnum_t n_cells_ext; /* Local number of participating cells
247  (cells + ghost cells sharing a face) */
248  cs_lnum_t n_faces; /* Local Number of mesh faces
249  (necessary to affect coefficients) */
250 
251  void *structure; /* Matrix structure */
252 
253  /* Pointers to shared arrays from mesh structure
254  (face->cell connectivity for coefficient assignment,
255  local->local cell numbering for future info or renumbering,
256  and halo) */
257 
258  const cs_lnum_t *face_cell; /* Face -> cells connectivity (1 to n) */
259  const cs_gnum_t *cell_num; /* Global cell numbers */
260  const cs_halo_t *halo; /* Parallel or periodic halo */
261  const cs_numbering_t *numbering; /* Vectorization or thread-related
262  numbering information */
263 };
264 
265 /* Structure associated with Matrix (representation-independent part) */
266 /*--------------------------------------------------------------------*/
267 
268 struct _cs_matrix_t {
269 
270  cs_matrix_type_t type; /* Matrix storage and definition type */
271 
272  cs_lnum_t n_cells; /* Local number of cells */
273  cs_lnum_t n_cells_ext; /* Local number of participating cells
274  (cells + ghost cells sharing a face) */
275  cs_lnum_t n_faces; /* Local Number of mesh faces
276  (necessary to affect coefficients) */
277 
278  int b_size[4]; /* Block size, including padding:
279  0: useful block size
280  1: vector block extents
281  2: matrix line extents
282  3: matrix line*column extents */
283 
284  /* Pointer to shared structure */
285 
286  const void *structure; /* Matrix structure */
287 
288  /* Pointers to shared arrays from mesh structure
289  (face->cell connectivity for coefficient assignment,
290  local->local cell numbering for future info or renumbering,
291  and halo) */
292 
293  const cs_lnum_t *face_cell; /* Face -> cells connectivity (1 to n) */
294  const cs_gnum_t *cell_num; /* Global cell numbers */
295  const cs_halo_t *halo; /* Parallel or periodic halo */
296  const cs_numbering_t *numbering; /* Vectorization or thread-related
297  numbering information */
298 
299  /* Pointer to private data */
300 
301  void *coeffs; /* Matrix coefficients */
302 
303  /* Function pointers */
304 
308 
309  /* Function pointer arrays, with 4 variants:
310  block_flag*2 + exclude_diagonal_flag */
311 
312  cs_matrix_vector_product_t *vector_multiply[4];
313 
314  /* Loop lenght parameter for some SpMv algorithms */
315 
317 
318 };
319 
320 /* Structure used for tuning variants */
321 /*------------------------------------*/
322 
324 
325  char name[32]; /* Variant name */
326 
327  cs_matrix_type_t type; /* Matrix storage and definition type */
328 
329  int symmetry; /* 0 for non-symmetric, 1 for symmetric,
330  2 for both */
331 
332  /* Loop lenght parameter for some SpMv algorithms */
333 
335 
336  /* Function pointer arrays, with 4 variants:
337  block_flag*2 + exclude_diagonal_flag */
338 
339  cs_matrix_vector_product_t *vector_multiply[4];
340 
341  /* Measured structure creation cost, or -1 otherwise */
342 
344 
345  /* Measured assignment costs for each available operation, or -1 otherwise
346  (up to 4 measures per variant: block_flag * 2 + sym_flag */
347 
348  double matrix_assign_cost[4];
349 
350  /* Measured operation costs for each available operation, or -1 otherwise
351  (up to 8 measures per variant:
352  block_flag*4 + sym_flag*2 + exclude_diagonal_flag) */
353 
354  double matrix_vector_cost[8];
355 
356 };
357 
358 /*=============================================================================
359  * Semi-private function prototypes
360  *============================================================================*/
361 
362 /*----------------------------------------------------------------------------*/
363 
365 
366 #endif /* __CS_MATRIX_PRIV_H__ */
void() cs_matrix_release_coeffs_t(cs_matrix_t *matrix)
Definition: cs_matrix_priv.h:70
cs_lnum_t * col_id
Definition: cs_matrix_priv.h:195
const cs_lnum_t * face_cell
Definition: cs_matrix_priv.h:105
#define restrict
Definition: cs_defs.h:105
cs_lnum_t n_cols
Definition: cs_matrix_priv.h:181
cs_real_t * val
Definition: cs_matrix_priv.h:204
const cs_lnum_t * face_cell
Definition: cs_matrix_priv.h:293
cs_real_t * _xa
Definition: cs_matrix_priv.h:125
struct _cs_matrix_coeff_msr_t cs_matrix_coeff_msr_t
void * coeffs
Definition: cs_matrix_priv.h:301
cs_real_t * x_val
Definition: cs_matrix_priv.h:232
bool have_diag
Definition: cs_matrix_priv.h:188
cs_lnum_t * row_index
Definition: cs_matrix_priv.h:148
struct _cs_matrix_coeff_native_t cs_matrix_coeff_native_t
cs_matrix_type_t type
Definition: cs_matrix_priv.h:327
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
Definition: cs_matrix_priv.h:132
const cs_real_t * da
Definition: cs_matrix_priv.h:119
cs_real_t * val
Definition: cs_matrix_priv.h:162
cs_real_t * _d_val
Definition: cs_matrix_priv.h:231
Definition: cs_matrix_priv.h:95
const cs_gnum_t * cell_num
Definition: cs_matrix_priv.h:294
int loop_length
Definition: cs_matrix_priv.h:334
Definition: cs_halo.h:75
const void * structure
Definition: cs_matrix_priv.h:286
Definition: cs_matrix_priv.h:268
cs_lnum_t n_cells_ext
Definition: cs_matrix_priv.h:273
struct _cs_matrix_coeff_csr_t cs_matrix_coeff_csr_t
struct _cs_matrix_coeff_csr_sym_t cs_matrix_coeff_csr_sym_t
const cs_lnum_t * face_cell
Definition: cs_matrix_priv.h:258
cs_matrix_copy_diagonal_t * copy_diagonal
Definition: cs_matrix_priv.h:307
struct _cs_matrix_struct_native_t cs_matrix_struct_native_t
const cs_numbering_t * numbering
Definition: cs_matrix_priv.h:261
cs_lnum_t n_rows
Definition: cs_matrix_priv.h:180
cs_matrix_type_t type
Definition: cs_matrix_priv.h:270
cs_matrix_release_coeffs_t * release_coefficients
Definition: cs_matrix_priv.h:306
void() cs_matrix_copy_diagonal_t(const cs_matrix_t *matrix, cs_real_t *restrict da)
Definition: cs_matrix_priv.h:73
cs_lnum_t n_cells_ext
Definition: cs_matrix_priv.h:246
cs_lnum_t n_cells_ext
Definition: cs_matrix_priv.h:98
subroutine matrix(ncelet, ncel, nfac, nfabor, iconvp, idiffp, ndircp, isym, nfecra, thetap, imucpp, ifacel, ifabor, coefbp, cofbfp, rovsdt, flumas, flumab, viscf, viscb, xcpp, da, xa)
Definition: matrix.f90:94
cs_real_t * _da
Definition: cs_matrix_priv.h:124
int cs_lnum_t
Definition: cs_defs.h:260
Definition: cs_matrix_priv.h:178
int max_block_size
Definition: cs_matrix_priv.h:115
cs_lnum_t * col_id
Definition: cs_matrix_priv.h:149
const cs_real_t * d_val
Definition: cs_matrix_priv.h:168
int loop_length
Definition: cs_matrix_priv.h:316
int symmetry
Definition: cs_matrix_priv.h:329
const cs_real_t * d_val
Definition: cs_matrix_priv.h:227
cs_lnum_t n_cells
Definition: cs_matrix_priv.h:245
cs_lnum_t n_rows
Definition: cs_matrix_priv.h:134
cs_matrix_type_t
Definition: cs_matrix.h:56
void() cs_matrix_vector_product_t(bool exclude_diag, const cs_matrix_t *matrix, const cs_real_t *restrict x, cs_real_t *restrict y)
Definition: cs_matrix_priv.h:77
const cs_numbering_t * numbering
Definition: cs_matrix_priv.h:296
cs_matrix_type_t type
Definition: cs_matrix_priv.h:243
const cs_halo_t * halo
Definition: cs_matrix_priv.h:295
unsigned cs_gnum_t
Definition: cs_defs.h:255
cs_lnum_t n_cells
Definition: cs_matrix_priv.h:272
cs_real_t * x_prefetch
Definition: cs_matrix_priv.h:234
cs_lnum_t n_cols
Definition: cs_matrix_priv.h:135
bool direct_assembly
Definition: cs_matrix_priv.h:189
const cs_real_t * d_val
Definition: cs_matrix_priv.h:208
struct _cs_matrix_struct_csr_t cs_matrix_struct_csr_t
const cs_gnum_t * cell_num
Definition: cs_matrix_priv.h:259
BEGIN_C_DECLS typedef void() cs_matrix_set_coeffs_t(cs_matrix_t *matrix, bool symmetric, bool interleaved, bool copy, const cs_real_t *restrict da, const cs_real_t *restrict xa)
void * structure
Definition: cs_matrix_priv.h:251
cs_lnum_t n_faces
Definition: cs_matrix_priv.h:248
cs_matrix_set_coeffs_t * set_coefficients
Definition: cs_matrix_priv.h:305
cs_real_t * _d_val
Definition: cs_matrix_priv.h:210
#define END_C_DECLS
Definition: cs_defs.h:366
const cs_real_t * xa
Definition: cs_matrix_priv.h:120
Definition: cs_matrix_priv.h:241
int max_block_size
Definition: cs_matrix_priv.h:223
double cs_real_t
Definition: cs_defs.h:264
double matrix_create_cost
Definition: cs_matrix_priv.h:343
cs_real_t * x_prefetch
Definition: cs_matrix_priv.h:164
cs_lnum_t n_faces
Definition: cs_matrix_priv.h:100
Definition: cs_matrix_priv.h:218
Definition: cs_matrix_priv.h:323
cs_lnum_t n_cols_max
Definition: cs_matrix_priv.h:137
cs_lnum_t n_cells
Definition: cs_matrix_priv.h:97
bool direct_assembly
Definition: cs_matrix_priv.h:143
Definition: cs_matrix_priv.h:156
bool symmetric
Definition: cs_matrix_priv.h:114
cs_real_t * _d_val
Definition: cs_matrix_priv.h:170
int n_prefetch_rows
Definition: cs_matrix_priv.h:158
bool have_diag
Definition: cs_matrix_priv.h:142
Definition: cs_numbering.h:66
Definition: cs_matrix_priv.h:112
Definition: cs_matrix_priv.h:202
cs_lnum_t n_faces
Definition: cs_matrix_priv.h:275
int n_prefetch_rows
Definition: cs_matrix_priv.h:220
cs_lnum_t n_cols_max
Definition: cs_matrix_priv.h:183
struct _cs_matrix_struct_csr_sym_t cs_matrix_struct_csr_sym_t
cs_lnum_t * row_index
Definition: cs_matrix_priv.h:194
const cs_halo_t * halo
Definition: cs_matrix_priv.h:260