My Project
programmer's 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-2019 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 int db_size[4],
80  const int 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 int *diag_block_size,
124  const int *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 int *diag_block_size,
141  const int *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 int *diag_block_size,
158  const int *extra_diag_block_size);
159 
160 /*----------------------------------------------------------------------------
161  * Force matrix variant for a given fill 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  const cs_matrix_variant_t *mv);
174 
175 /*----------------------------------------------------------------------------
176  * Set matrix tuning behavior for a given fill type
177  *
178  * parameters:
179  * fill type <-- Fill type for which tuning behavior is set
180  * tune <-- 1 to activate tuning, 0 to deactivate
181  *----------------------------------------------------------------------------*/
182 
183 void
185  int tune);
186 
187 /*----------------------------------------------------------------------------
188  * Return matrix tuning behavior for a given fill type.
189  *
190  * parameters:
191  * fill type <-- Fill type for which tuning behavior is set
192  *
193  * returns:
194  * 1 if tuning is active, 0 otherwise
195  *----------------------------------------------------------------------------*/
196 
197 int
199 
200 /*----------------------------------------------------------------------------
201  * Set number of matrix computation runs for tuning.
202  *
203  * If this function is not called, defaults are:
204  * - minimum of 10 runs
205  * - minimum of 0.5 seconds of running
206  *
207  * parameters:
208  * n_min_products <-- minimum number of expected SpM.V products for
209  * coefficients assign amortization.
210  * t_measure <-- minimum running time per measure
211  *----------------------------------------------------------------------------*/
212 
213 void
214 cs_matrix_set_tuning_runs(int n_min_products,
215  double t_measure);
216 
217 /*----------------------------------------------------------------------------
218  * Get number of matrix computation runs for tuning.
219  *
220  * parameters:
221  * n_min_products --> minimum number of expected SpM.V products for
222  * coefficients assign amortization.
223  * t_measure --> minimum running time per measure, or NULL
224  *----------------------------------------------------------------------------*/
225 
226 void
227 cs_matrix_get_tuning_runs(int *n_min_products,
228  double *t_measure);
229 
230 /*----------------------------------------------------------------------------
231  * Return a (0-based) global block row numbering.
232  *
233  * The numbering is built if not previously present, and returned otherwise.
234  *
235  * Currently, the function only handles one n_rows/halo combination, and does
236  * not check for consistency.
237  *
238  * parameters:
239  * n_rows <-- associated number of local rows
240  * halo <-- associated halo, or NULL
241  *
242  * returns:
243  * pointer to requested global numbering
244  *----------------------------------------------------------------------------*/
245 
246 const cs_gnum_t *
248  const cs_halo_t *halo);
249 
250 /*----------------------------------------------------------------------------*/
267 /*----------------------------------------------------------------------------*/
268 
269 cs_matrix_t *
272  bool symmetric,
273  const int *diag_block_size,
274  const int *extra_diag_block_size,
275  const cs_real_t *da,
276  const cs_real_t *xa);
277 
278 /*----------------------------------------------------------------------------*/
279 
281 
282 #endif /* __CS_MATRIX_DEFAULT_H__ */
f_id
void const int * f_id
Definition: cs_gui.h:292
cs_defs.h
cs_matrix_update_mesh
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.c:551
cs_matrix_set_coefficients_coupled
cs_matrix_t * cs_matrix_set_coefficients_coupled(const cs_field_t *f, cs_matrix_type_t type, bool symmetric, const int *diag_block_size, const int *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:1000
cs_numbering.h
cs_matrix_set_variant
void cs_matrix_set_variant(cs_matrix_fill_type_t fill_type, const cs_matrix_variant_t *mv)
Definition: cs_matrix_default.c:838
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_matrix_initialize
void cs_matrix_initialize(void)
Definition: cs_matrix_default.c:361
cs_matrix_get_block_row_g_id
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:967
cs_matrix_set_tuning
void cs_matrix_set_tuning(cs_matrix_fill_type_t fill_type, int tune)
Definition: cs_matrix_default.c:865
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_matrix_t
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:90
cs_matrix_default
cs_matrix_t * cs_matrix_default(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:676
cs_matrix_variant_t
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:94
da
void const int const int const int const cs_real_t const int const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t cs_real_t da[]
Definition: cs_matrix_building.h:65
cs_halo.h
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_matrix_finalize
void cs_matrix_finalize(void)
Definition: cs_matrix_default.c:505
cs_matrix_get_tuning
int cs_matrix_get_tuning(cs_matrix_fill_type_t fill_type)
Definition: cs_matrix_default.c:890
cs_matrix_get_tuning_runs
void cs_matrix_get_tuning_runs(int *n_min_products, double *t_measure)
Definition: cs_matrix_default.c:937
cs_field.h
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_matrix_set_tuning_runs
void cs_matrix_set_tuning_runs(int n_min_products, double t_measure)
Definition: cs_matrix_default.c:917
cs_matrix_msr
cs_matrix_t * cs_matrix_msr(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:705
cs_halo_perio.h
cs_halo_t
Definition: cs_halo.h:71
cs_matrix_fill_type_t
cs_matrix_fill_type_t
Definition: cs_matrix.h:67
cs_matrix_type_t
cs_matrix_type_t
Definition: cs_matrix.h:55
cs_matrix_native
cs_matrix_t * cs_matrix_native(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:778
cs_matrix.h
cs_halo_rotation_t
cs_halo_rotation_t
Definition: cs_halo.h:60
cs_field_t
Field descriptor.
Definition: cs_field.h:124
type
void const cs_int_t * type
Definition: cs_measures_util.h:425
xa
void const int const int const int const cs_real_t const int const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t const cs_real_t cs_real_t cs_real_t xa[]
Definition: cs_matrix_building.h:65
cs_matrix_vector_native_multiply
void cs_matrix_vector_native_multiply(bool symmetric, const int db_size[4], const int 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:311