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