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-2018 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_halo.h"
37 #include "cs_matrix.h"
38 #include "cs_numbering.h"
39 #include "cs_halo_perio.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 /*============================================================================
50  * Type definitions
51  *============================================================================*/
52 
53 /*============================================================================
54  * Global variables
55  *============================================================================*/
56 
57 /*=============================================================================
58  * Public function prototypes
59  *============================================================================*/
60 
61 /*----------------------------------------------------------------------------
62  * Matrix (native format) vector product
63  *
64  * parameters:
65  * isym <-- Symmetry indicator:
66  * 1: symmetric; 2: not symmetric
67  * ibsize <-- Block size of element ii
68  * iesize <-- Block size of element ij
69  * iinvpe <-- Indicator to cancel increments
70  * in rotational periodicty (2) or
71  * to exchange them as scalars (1)
72  * f_id <-- field id
73  * dam <-- Matrix diagonal
74  * xam <-- Matrix extra-diagonal terms
75  * vx <-- A*vx
76  * vy <-> vy = A*vx
77  *----------------------------------------------------------------------------*/
78 
79 void
81  int ibsize,
82  int iesize,
83  int iinvpe,
84  int f_id,
85  const cs_real_t *dam,
86  const cs_real_t *xam,
87  cs_real_t *vx,
88  cs_real_t *vy);
89 
90 /*----------------------------------------------------------------------------
91  * Initialize sparse matrix API.
92  *----------------------------------------------------------------------------*/
93 
94 void
96 
97 /*----------------------------------------------------------------------------
98  * Finalize sparse matrix API.
99  *----------------------------------------------------------------------------*/
100 
101 void
102 cs_matrix_finalize(void);
103 
104 /*----------------------------------------------------------------------------
105  * Update sparse matrix API in case of mesh modification.
106  *----------------------------------------------------------------------------*/
107 
108 void
110 
111 /*----------------------------------------------------------------------------
112  * Return default matrix for a given fill type
113  *
114  * parameters:
115  * symmetric <-- Indicates if matrix coefficients are symmetric
116  * diag_block_size <-- Block sizes for diagonal, or NULL
117  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
118  *
119  * returns:
120  * pointer to default matrix structure adapted to fill type
121  *----------------------------------------------------------------------------*/
122 
123 cs_matrix_t *
124 cs_matrix_default(bool symmetric,
125  const int *diag_block_size,
126  const int *extra_diag_block_size);
127 
128 /*----------------------------------------------------------------------------
129  * Return MSR matrix for a given fill type
130  *
131  * parameters:
132  * symmetric <-- Indicates if matrix coefficients are symmetric
133  * diag_block_size <-- Block sizes for diagonal, or NULL
134  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
135  *
136  * returns:
137  * pointer to MSR matrix adapted to fill type
138  *----------------------------------------------------------------------------*/
139 
140 cs_matrix_t *
141 cs_matrix_msr(bool symmetric,
142  const int *diag_block_size,
143  const int *extra_diag_block_size);
144 
145 /*----------------------------------------------------------------------------
146  * Return native matrix for a given fill type
147  *
148  * parameters:
149  * symmetric <-- Indicates if matrix coefficients are symmetric
150  * diag_block_size <-- Block sizes for diagonal, or NULL
151  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
152  *
153  * returns:
154  * pointer to native matrix adapted to fill type
155  *----------------------------------------------------------------------------*/
156 
157 cs_matrix_t *
158 cs_matrix_native(bool symmetric,
159  const int *diag_block_size,
160  const int *extra_diag_block_size);
161 
162 /*----------------------------------------------------------------------------
163  * Force matrix variant for a given fill type
164  *
165  * Information from the variant used fo this definition is copied,
166  * so it may be freed after calling this function.
167  *
168  * parameters:
169  * fill type <-- Fill type for which tuning behavior is set
170  * mv <-- Matrix variant to use for this type
171  *----------------------------------------------------------------------------*/
172 
173 void
175  const cs_matrix_variant_t *mv);
176 
177 /*----------------------------------------------------------------------------
178  * Set matrix tuning behavior for a given fill type
179  *
180  * parameters:
181  * fill type <-- Fill type for which tuning behavior is set
182  * tune <-- 1 to activate tuning, 0 to deactivate
183  *----------------------------------------------------------------------------*/
184 
185 void
187  int tune);
188 
189 /*----------------------------------------------------------------------------
190  * Return matrix tuning behavior for a given fill type.
191  *
192  * parameters:
193  * fill type <-- Fill type for which tuning behavior is set
194  *
195  * returns:
196  * 1 if tuning is active, 0 otherwise
197  *----------------------------------------------------------------------------*/
198 
199 int
201 
202 /*----------------------------------------------------------------------------
203  * Set number of matrix computation runs for tuning.
204  *
205  * If this function is not called, defaults are:
206  * - minimum of 10 runs
207  * - minimum of 0.5 seconds of running
208  *
209  * parameters:
210  * n_min_products <-- minimum number of expected SpM.V products for
211  * coefficients assign amortization.
212  * t_measure <-- minimum running time per measure
213  *----------------------------------------------------------------------------*/
214 
215 void
216 cs_matrix_set_tuning_runs(int n_min_products,
217  double t_measure);
218 
219 /*----------------------------------------------------------------------------
220  * Get number of matrix computation runs for tuning.
221  *
222  * parameters:
223  * n_min_products --> minimum number of expected SpM.V products for
224  * coefficients assign amortization.
225  * t_measure --> minimum running time per measure, or NULL
226  *----------------------------------------------------------------------------*/
227 
228 void
229 cs_matrix_get_tuning_runs(int *n_min_products,
230  double *t_measure);
231 
232 /*----------------------------------------------------------------------------
233  * Return a (0-based) global block row numbering.
234  *
235  * The numbering is built if not previously present, and returned otherwise.
236  *
237  * Currently, the function only handles one n_rows/halo combination, and does
238  * not check for consistency.
239  *
240  * parameters:
241  * n_rows <-- associated number of local rows
242  * halo <-- associated halo, or NULL
243  *
244  * returns:
245  * pointer to requested global numbering
246  *----------------------------------------------------------------------------*/
247 
248 const cs_gnum_t *
250  const cs_halo_t *halo);
251 
252 /*----------------------------------------------------------------------------*/
253 
255 
256 #endif /* __CS_MATRIX_DEFAULT_H__ */
cs_matrix_t * cs_matrix_msr(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:623
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:885
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:281
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:94
void cs_matrix_vector_native_multiply(int isym, int ibsize, int iesize, int iinvpe, 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:222
void cs_matrix_get_tuning_runs(int *n_min_products, double *t_measure)
Definition: cs_matrix_default.c:855
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
Definition: cs_halo.h:71
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:90
int cs_matrix_get_tuning(cs_matrix_fill_type_t fill_type)
Definition: cs_matrix_default.c:808
void cs_matrix_initialize(void)
Definition: cs_matrix_default.c:310
void cs_matrix_finalize(void)
Definition: cs_matrix_default.c:441
cs_matrix_t * cs_matrix_native(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:696
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
cs_matrix_t * cs_matrix_default(bool symmetric, const int *diag_block_size, const int *extra_diag_block_size)
Definition: cs_matrix_default.c:594
#define END_C_DECLS
Definition: cs_defs.h:452
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.c:477
void cs_matrix_set_variant(cs_matrix_fill_type_t fill_type, const cs_matrix_variant_t *mv)
Definition: cs_matrix_default.c:756
void cs_matrix_set_tuning_runs(int n_min_products, double t_measure)
Definition: cs_matrix_default.c:835
void cs_matrix_set_tuning(cs_matrix_fill_type_t fill_type, int tune)
Definition: cs_matrix_default.c:783
cs_matrix_fill_type_t
Definition: cs_matrix.h:67