7.0
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-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  * rotation_mode <-- halo update option for rotational periodicity
70  * f_id <-- associated field id, or < 0
71  * dam <-- Matrix diagonal
72  * xam <-- Matrix extra-diagonal terms
73  * vx <-- A*vx
74  * vy <-> vy = A*vx
75  *----------------------------------------------------------------------------*/
76 
77 void
79  const cs_lnum_t db_size[4],
80  const cs_lnum_t eb_size[4],
81  cs_halo_rotation_t rotation_mode,
82  int f_id,
83  const cs_real_t *dam,
84  const cs_real_t *xam,
85  cs_real_t *vx,
86  cs_real_t *vy);
87 
88 /*----------------------------------------------------------------------------
89  * Initialize sparse matrix API.
90  *----------------------------------------------------------------------------*/
91 
92 void
94 
95 /*----------------------------------------------------------------------------
96  * Finalize sparse matrix API.
97  *----------------------------------------------------------------------------*/
98 
99 void
100 cs_matrix_finalize(void);
101 
102 /*----------------------------------------------------------------------------
103  * Update sparse matrix API in case of mesh modification.
104  *----------------------------------------------------------------------------*/
105 
106 void
108 
109 /*----------------------------------------------------------------------------
110  * Return default matrix for a given fill type
111  *
112  * parameters:
113  * symmetric <-- Indicates if matrix coefficients are symmetric
114  * diag_block_size <-- Block sizes for diagonal, or NULL
115  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
116  *
117  * returns:
118  * pointer to default matrix structure adapted to fill type
119  *----------------------------------------------------------------------------*/
120 
121 cs_matrix_t *
122 cs_matrix_default(bool symmetric,
123  const cs_lnum_t *diag_block_size,
124  const cs_lnum_t *extra_diag_block_size);
125 
126 /*----------------------------------------------------------------------------
127  * Return MSR matrix for a given fill type
128  *
129  * parameters:
130  * symmetric <-- Indicates if matrix coefficients are symmetric
131  * diag_block_size <-- Block sizes for diagonal, or NULL
132  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
133  *
134  * returns:
135  * pointer to MSR matrix adapted to fill type
136  *----------------------------------------------------------------------------*/
137 
138 cs_matrix_t *
139 cs_matrix_msr(bool symmetric,
140  const cs_lnum_t *diag_block_size,
141  const cs_lnum_t *extra_diag_block_size);
142 
143 /*----------------------------------------------------------------------------
144  * Return native matrix for a given fill type
145  *
146  * parameters:
147  * symmetric <-- Indicates if matrix coefficients are symmetric
148  * diag_block_size <-- Block sizes for diagonal, or NULL
149  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
150  *
151  * returns:
152  * pointer to native matrix adapted to fill type
153  *----------------------------------------------------------------------------*/
154 
155 cs_matrix_t *
156 cs_matrix_native(bool symmetric,
157  const cs_lnum_t *diag_block_size,
158  const cs_lnum_t *extra_diag_block_size);
159 
160 /*----------------------------------------------------------------------------
161  * Determine or apply default tuning for a given matrix type
162  *
163  * Information from the variant used fo this definition is copied,
164  * so it may be freed after calling this function.
165  *
166  * parameters:
167  * fill type <-- Fill type for which tuning behavior is set
168  * mv <-- Matrix variant to use for this type
169  *----------------------------------------------------------------------------*/
170 
171 void
173 
174 /*----------------------------------------------------------------------------
175  * Set number of matrix computation runs for tuning.
176  *
177  * If this function is not called, defaults are:
178  * - minimum of 10 runs
179  * - minimum of 0.5 seconds of running
180  *
181  * parameters:
182  * n_min_products <-- minimum number of expected SpM.V products for
183  * coefficients assign amortization.
184  * t_measure <-- minimum running time per measure
185  *----------------------------------------------------------------------------*/
186 
187 void
188 cs_matrix_set_tuning_runs(int n_min_products,
189  double t_measure);
190 
191 /*----------------------------------------------------------------------------
192  * Get number of matrix computation runs for tuning.
193  *
194  * parameters:
195  * n_min_products --> minimum number of expected SpM.V products for
196  * coefficients assign amortization.
197  * t_measure --> minimum running time per measure, or NULL
198  *----------------------------------------------------------------------------*/
199 
200 void
201 cs_matrix_get_tuning_runs(int *n_min_products,
202  double *t_measure);
203 
204 /*----------------------------------------------------------------------------*/
211 /*----------------------------------------------------------------------------*/
212 
213 void
215  cs_matrix_type_t type);
216 
217 /*----------------------------------------------------------------------------
218  * Return a (0-based) global block row numbering.
219  *
220  * The numbering is built if not previously present, and returned otherwise.
221  *
222  * Currently, the function only handles one n_rows/halo combination, and does
223  * not check for consistency.
224  *
225  * parameters:
226  * n_rows <-- associated number of local rows
227  * halo <-- associated halo, or NULL
228  *
229  * returns:
230  * pointer to requested global numbering
231  *----------------------------------------------------------------------------*/
232 
233 const cs_gnum_t *
235  const cs_halo_t *halo);
236 
237 /*----------------------------------------------------------------------------*/
254 /*----------------------------------------------------------------------------*/
255 
256 cs_matrix_t *
258  cs_matrix_type_t type,
259  bool symmetric,
260  const cs_lnum_t *diag_block_size,
261  const cs_lnum_t *extra_diag_block_size,
262  const cs_real_t *da,
263  const cs_real_t *xa);
264 
265 /*----------------------------------------------------------------------------*/
266 
268 
269 #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:725
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_halo_rotation_t
Definition: cs_halo.h:60
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:702
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:601
void cs_matrix_get_tuning_runs(int *n_min_products, double *t_measure)
Definition: cs_matrix_default.c:679
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
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:573
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:71
void cs_matrix_default_set_tuned(cs_matrix_t *m)
Definition: cs_matrix_default.c:624
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:94
void cs_matrix_initialize(void)
Definition: cs_matrix_default.c:432
void cs_matrix_finalize(void)
Definition: cs_matrix_default.c:453
cs_matrix_type_t
Definition: cs_matrix.h:55
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
#define END_C_DECLS
Definition: cs_defs.h:496
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.c:490
void cs_matrix_set_tuning_runs(int n_min_products, double t_measure)
Definition: cs_matrix_default.c:659
void cs_matrix_vector_native_multiply(bool symmetric, const cs_lnum_t db_size[4], const cs_lnum_t eb_size[4], cs_halo_rotation_t rotation_mode, 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:382
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:758
cs_matrix_fill_type_t
Definition: cs_matrix.h:71