7.1
general documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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-2021 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  const cs_lnum_t db_size[4],
79  const cs_lnum_t eb_size[4],
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, or NULL
113  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
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  const cs_lnum_t *diag_block_size,
122  const 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, or NULL
130  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
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  const cs_lnum_t *diag_block_size,
139  const 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, or NULL
147  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
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  const cs_lnum_t *diag_block_size,
156  const 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  const cs_lnum_t *diag_block_size,
175  const cs_lnum_t *extra_diag_block_size);
176 
177 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 
201 cs_matrix_t *
203  bool symmetric,
204  const cs_lnum_t *diag_block_size,
205  const 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 /*----------------------------------------------------------------------------
265  * Return a (0-based) global block row numbering.
266  *
267  * The numbering is built if not previously present, and returned otherwise.
268  *
269  * Currently, the function only handles one n_rows/halo combination, and does
270  * not check for consistency.
271  *
272  * parameters:
273  * n_rows <-- associated number of local rows
274  * halo <-- associated halo, or NULL
275  *
276  * returns:
277  * pointer to requested global numbering
278  *----------------------------------------------------------------------------*/
279 
280 const cs_gnum_t *
282  const cs_halo_t *halo);
283 
284 /*----------------------------------------------------------------------------*/
301 /*----------------------------------------------------------------------------*/
302 
303 cs_matrix_t *
305  cs_matrix_type_t type,
306  bool symmetric,
307  const cs_lnum_t *diag_block_size,
308  const cs_lnum_t *extra_diag_block_size,
309  const cs_real_t *da,
310  const cs_real_t *xa);
311 
312 /*----------------------------------------------------------------------------*/
313 
315 
316 #endif /* __CS_MATRIX_DEFAULT_H__ */
const cs_gnum_t * cs_matrix_get_block_row_g_id(cs_lnum_t n_rows, const cs_halo_t *halo)
Definition: cs_matrix_default.c:848
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:301
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:825
Field descriptor.
Definition: cs_field.h:125
cs_matrix_t * cs_matrix_native(bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Definition: cs_matrix_default.c:609
void cs_matrix_get_tuning_runs(int *n_min_products, double *t_measure)
Definition: cs_matrix_default.c:802
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
cs_matrix_t * cs_matrix_msr(bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Definition: cs_matrix_default.c:581
cs_matrix_t * cs_matrix_default(bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Definition: cs_halo.h:77
cs_matrix_t * cs_matrix_copy_to_external(cs_matrix_t *src, bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Copy base matrix to external library matrix type for given fill type.
Definition: cs_matrix_default.c:710
void cs_matrix_default_set_tuned(cs_matrix_t *m)
Definition: cs_matrix_default.c:747
void cs_matrix_vector_native_multiply(bool symmetric, const cs_lnum_t db_size[4], const cs_lnum_t eb_size[4], 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:390
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:93
void cs_matrix_initialize(void)
Definition: cs_matrix_default.c:436
void cs_matrix_finalize(void)
Definition: cs_matrix_default.c:457
cs_matrix_type_t
Definition: cs_matrix.h:55
cs_matrix_t * cs_matrix_external(const char *type_name, bool symmetric, const cs_lnum_t *diag_block_size, const cs_lnum_t *extra_diag_block_size)
Return matrix wrapper for external library for a given fill type.
Definition: cs_matrix_default.c:634
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
#define END_C_DECLS
Definition: cs_defs.h:511
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.c:503
void cs_matrix_set_tuning_runs(int n_min_products, double t_measure)
Definition: cs_matrix_default.c:782
cs_matrix_t * cs_matrix_set_coefficients_by_assembler(const cs_field_t *f, cs_matrix_type_t type, bool symmetric, const cs_lnum_t *diag_block_size, const 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:881
cs_matrix_fill_type_t
Definition: cs_matrix.h:70