8.1
general documentation
cs_matrix_default.h
Go to the documentation of this file.
1 #ifndef __CS_MATRIX_DEFAULT_H__
2 #define __CS_MATRIX_DEFAULT_H__
3 
4 /*============================================================================
5  * Default Sparse Matrix structure and Tuning.
6  *============================================================================*/
7 
8 /*
9  This file is part of code_saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2023 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_field.h"
37 #include "cs_halo.h"
38 #include "cs_matrix.h"
39 #include "cs_numbering.h"
40 #include "cs_halo_perio.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*============================================================================
51  * Type definitions
52  *============================================================================*/
53 
54 /*============================================================================
55  * Global variables
56  *============================================================================*/
57 
58 /*=============================================================================
59  * Public function prototypes
60  *============================================================================*/
61 
62 /*----------------------------------------------------------------------------
63  * Matrix (native format) vector product
64  *
65  * parameters:
66  * symmetric <-- Symmetry indicator:
67  * db_size <-- block sizes for diagonal
68  * eb_size <-- block sizes for extra diagonal
69  * f_id <-- associated field id, or < 0
70  * dam <-- Matrix diagonal
71  * xam <-- Matrix extra-diagonal terms
72  * vx <-- A*vx
73  * vy <-> vy = A*vx
74  *----------------------------------------------------------------------------*/
75 
76 void
78  cs_lnum_t db_size,
79  cs_lnum_t eb_size,
80  int f_id,
81  const cs_real_t *dam,
82  const cs_real_t *xam,
83  cs_real_t *vx,
84  cs_real_t *vy);
85 
86 /*----------------------------------------------------------------------------
87  * Initialize sparse matrix API.
88  *----------------------------------------------------------------------------*/
89 
90 void
92 
93 /*----------------------------------------------------------------------------
94  * Finalize sparse matrix API.
95  *----------------------------------------------------------------------------*/
96 
97 void
98 cs_matrix_finalize(void);
99 
100 /*----------------------------------------------------------------------------
101  * Update sparse matrix API in case of mesh modification.
102  *----------------------------------------------------------------------------*/
103 
104 void
106 
107 /*----------------------------------------------------------------------------
108  * Return default matrix for a given fill type
109  *
110  * parameters:
111  * symmetric <-- Indicates if matrix coefficients are symmetric
112  * diag_block_size <-- Block sizes for diagonal
113  * extra_diag_block_size <-- Block sizes for extra diagonal
114  *
115  * returns:
116  * pointer to default matrix structure adapted to fill type
117  *----------------------------------------------------------------------------*/
118 
119 cs_matrix_t *
120 cs_matrix_default(bool symmetric,
121  cs_lnum_t diag_block_size,
122  cs_lnum_t extra_diag_block_size);
123 
124 /*----------------------------------------------------------------------------
125  * Return MSR matrix for a given fill type
126  *
127  * parameters:
128  * symmetric <-- Indicates if matrix coefficients are symmetric
129  * diag_block_size <-- Block sizes for diagonal
130  * extra_diag_block_size <-- Block sizes for extra diagonal
131  *
132  * returns:
133  * pointer to MSR matrix adapted to fill type
134  *----------------------------------------------------------------------------*/
135 
136 cs_matrix_t *
137 cs_matrix_msr(bool symmetric,
138  cs_lnum_t diag_block_size,
139  cs_lnum_t extra_diag_block_size);
140 
141 /*----------------------------------------------------------------------------
142  * Return native matrix for a given fill type
143  *
144  * parameters:
145  * symmetric <-- Indicates if matrix coefficients are symmetric
146  * diag_block_size <-- Block sizes for diagonal
147  * extra_diag_block_size <-- Block sizes for extra diagonal
148  *
149  * returns:
150  * pointer to native matrix adapted to fill type
151  *----------------------------------------------------------------------------*/
152 
153 cs_matrix_t *
154 cs_matrix_native(bool symmetric,
155  cs_lnum_t diag_block_size,
156  cs_lnum_t extra_diag_block_size);
157 
158 /*----------------------------------------------------------------------------*/
169 /*----------------------------------------------------------------------------*/
170 
171 cs_matrix_t *
172 cs_matrix_external(const char *type_name,
173  bool symmetric,
174  cs_lnum_t diag_block_size,
175  cs_lnum_t extra_diag_block_size);
176 
177 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 
201 cs_matrix_t *
203  bool symmetric,
204  cs_lnum_t diag_block_size,
205  cs_lnum_t extra_diag_block_size);
206 
207 /*----------------------------------------------------------------------------
208  * Determine or apply default tuning for a given matrix type
209  *
210  * Information from the variant used fo this definition is copied,
211  * so it may be freed after calling this function.
212  *
213  * parameters:
214  * fill type <-- Fill type for which tuning behavior is set
215  * mv <-- Matrix variant to use for this type
216  *----------------------------------------------------------------------------*/
217 
218 void
220 
221 /*----------------------------------------------------------------------------
222  * Set number of matrix computation runs for tuning.
223  *
224  * If this function is not called, defaults are:
225  * - minimum of 10 runs
226  * - minimum of 0.5 seconds of running
227  *
228  * parameters:
229  * n_min_products <-- minimum number of expected SpM.V products for
230  * coefficients assign amortization.
231  * t_measure <-- minimum running time per measure
232  *----------------------------------------------------------------------------*/
233 
234 void
235 cs_matrix_set_tuning_runs(int n_min_products,
236  double t_measure);
237 
238 /*----------------------------------------------------------------------------
239  * Get number of matrix computation runs for tuning.
240  *
241  * parameters:
242  * n_min_products --> minimum number of expected SpM.V products for
243  * coefficients assign amortization.
244  * t_measure --> minimum running time per measure, or NULL
245  *----------------------------------------------------------------------------*/
246 
247 void
248 cs_matrix_get_tuning_runs(int *n_min_products,
249  double *t_measure);
250 
251 /*----------------------------------------------------------------------------*/
258 /*----------------------------------------------------------------------------*/
259 
260 void
262  cs_matrix_type_t type);
263 
264 /*----------------------------------------------------------------------------*/
276 /*----------------------------------------------------------------------------*/
277 
278 const cs_gnum_t *
280 
281 /*----------------------------------------------------------------------------*/
298 /*----------------------------------------------------------------------------*/
299 
300 cs_matrix_t *
302  cs_matrix_type_t type,
303  bool symmetric,
304  cs_lnum_t diag_block_size,
305  cs_lnum_t extra_diag_block_size,
306  const cs_real_t *da,
307  const cs_real_t *xa);
308 
309 /*----------------------------------------------------------------------------*/
310 
312 
313 #endif /* __CS_MATRIX_DEFAULT_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:514
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:298
#define END_C_DECLS
Definition: cs_defs.h:515
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:110
cs_matrix_fill_type_t
Definition: cs_matrix.h:72
cs_matrix_type_t
Definition: cs_matrix.h:54
cs_matrix_t * cs_matrix_external(const char *type_name, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Return matrix wrapper for external library for a given fill type.
Definition: cs_matrix_default.c:666
void cs_matrix_get_tuning_runs(int *n_min_products, double *t_measure)
Definition: cs_matrix_default.c:872
void cs_matrix_finalize(void)
Definition: cs_matrix_default.c:486
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.c:536
cs_matrix_t * cs_matrix_native(bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Definition: cs_matrix_default.c:641
void cs_matrix_vector_native_multiply(bool symmetric, cs_lnum_t db_size, cs_lnum_t eb_size, int f_id, const cs_real_t *dam, const cs_real_t *xam, cs_real_t *vx, cs_real_t *vy)
Definition: cs_matrix_default.c:419
cs_matrix_t * cs_matrix_copy_to_external(cs_matrix_t *src, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Copy base matrix to external library matrix type for given fill type.
Definition: cs_matrix_default.c:770
void cs_matrix_initialize(void)
Definition: cs_matrix_default.c:465
void cs_matrix_default_set_type(cs_matrix_fill_type_t fill_type, cs_matrix_type_t type)
Set default matrix type for a given fill type.
Definition: cs_matrix_default.c:895
void cs_matrix_default_set_tuned(cs_matrix_t *m)
Definition: cs_matrix_default.c:807
cs_matrix_t * cs_matrix_msr(bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Definition: cs_matrix_default.c:613
const cs_gnum_t * cs_matrix_get_block_row_g_id(const cs_matrix_t *m)
Return a (0-based) global block row numbering for a given matrix.
Definition: cs_matrix_default.c:916
void cs_matrix_set_tuning_runs(int n_min_products, double t_measure)
Definition: cs_matrix_default.c:852
cs_matrix_t * cs_matrix_set_coefficients_by_assembler(const cs_field_t *f, cs_matrix_type_t type, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size, const cs_real_t *da, const cs_real_t *xa)
Assign coefficients to a matrix using a matrix assembler.
Definition: cs_matrix_default.c:956
cs_matrix_t * cs_matrix_default(bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Definition: cs_matrix_default.c:578
Field descriptor.
Definition: cs_field.h:131