9.1
general documentation
cs_blas.h
Go to the documentation of this file.
1#ifndef __CS_BLAS_H__
2#define __CS_BLAS_H__
3
4/*============================================================================
5 * BLAS (Basic Linear Algebra Subroutine) functions
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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#include "base/cs_defs.h"
31
32/*----------------------------------------------------------------------------
33 * External library headers
34 *----------------------------------------------------------------------------*/
35
36/*----------------------------------------------------------------------------
37 * Local headers
38 *----------------------------------------------------------------------------*/
39
40#include "base/cs_base.h"
41#include "base/cs_dispatch.h"
42#include "base/cs_log.h"
43
44/*----------------------------------------------------------------------------*/
45
47
48/*============================================================================
49 * Macro definitions
50 *============================================================================*/
51
52/*============================================================================
53 * Type definitions
54 *============================================================================*/
55
56/* BLAS reduction algorithm families */
57
58typedef enum {
59
62
64
65/*----------------------------------------------------------------------------*/
66
67/*============================================================================
68 * Public function prototypes
69 *============================================================================*/
70
72
73#ifdef __cplusplus
74
75/*----------------------------------------------------------------------------*/
76/*
77 * \brief Constant times a vector plus a vector: y <-- ax + y
78 *
79 * \param[in] ctx reference to dispatch context
80 * \param[in] n size of arrays x and y
81 * \param[in] a multiplier for x
82 * \param[in] x array of floating-point values
83 * \param[in, out] y array of floating-point values
84 */
85/*----------------------------------------------------------------------------*/
86
87void
89 cs_lnum_t n,
90 cs_real_t a,
91 const cs_real_t *x,
93
94#endif // __cplusplus
95
97
98/*----------------------------------------------------------------------------*/
99/*
100 * \brief Print information on BLAS libraries used.
101 *
102 * \param[in] log_type log type
103 */
104/*----------------------------------------------------------------------------*/
105
106void
108
109/*----------------------------------------------------------------------------*/
110/*
111 * \brief Set the preferred BLAS reduction algorithm family.
112 *
113 * This may not be enforced for all algorithms, though it should at least
114 * be enforced for the most general functions such as \ref cs_dot.
115 *
116 * \param[in] mode BLAS mode to use
117 */
118/*----------------------------------------------------------------------------*/
119
120void
122
123/*----------------------------------------------------------------------------
124 * Constant times a vector plus a vector: y <-- ax + y
125 *
126 * parameters:
127 * n <-- size of arrays x and y
128 * a <-- multiplier for x
129 * x <-- array of floating-point values
130 * y <-- array of floating-point values
131 *----------------------------------------------------------------------------*/
132
133void
135 double a,
136 const cs_real_t *x,
137 cs_real_t *y);
138
139/*----------------------------------------------------------------------------
140 * Return the sum of a vector. For better precision, a superblock algorithm
141 * is used.
142 *
143 * parameters:
144 * n <-- size of array x
145 * x <-- array of floating-point values
146 *
147 * returns:
148 * the resulting sum
149 *----------------------------------------------------------------------------*/
150
151double
153 const cs_real_t *x);
154
155/*----------------------------------------------------------------------------
156 * Return the weighted sum of a vector. For better precision, a superblock
157 * algorithm is used.
158 *
159 * \param[in] n size of array x
160 * \param[in] w array of floating-point weights
161 * \param[in] x array of floating-point values
162 *
163 * \return the resulting weighted sum
164 *----------------------------------------------------------------------------*/
165
166double
168 const cs_real_t *w,
169 const cs_real_t *x);
170
171/*----------------------------------------------------------------------------
172 * Return the dot product of 2 vectors: x.y
173 *
174 * parameters:
175 * n <-- size of arrays x and y
176 * x <-- array of floating-point values
177 * y <-- array of floating-point values
178 *
179 * returns:
180 * dot product
181 *----------------------------------------------------------------------------*/
182
183double
185 const cs_real_t *x,
186 const cs_real_t *y);
187
188/*----------------------------------------------------------------------------
189 * Return dot products of a vector with itself: x.x
190 *
191 * parameters:
192 * n <-- size of arrays x
193 * x <-- array of floating-point values
194 *
195 * returns:
196 * dot product
197 *----------------------------------------------------------------------------*/
198
199double
201 const cs_real_t *x);
202
203/*----------------------------------------------------------------------------
204 * Return weighted dot products of a vector with itself: x.x
205 *
206 * For better precision, a superblock algorithm is used.
207 *
208 * parameters:
209 * n <-- size of arrays x
210 * w <-- array of weights
211 * x <-- array of floating-point values
212 *
213 * returns:
214 * dot product
215 *----------------------------------------------------------------------------*/
216
217double
219 const cs_real_t *w,
220 const cs_real_t *x);
221
222/*----------------------------------------------------------------------------
223 * Return the double dot product of 2 vectors: x.x, and x.y
224 *
225 * The products could be computed separately, but computing them
226 * simultaneously adds more optimization opportunities and possibly better
227 * cache behavior.
228 *
229 * parameters:
230 * n <-- size of arrays x and y
231 * x <-- array of floating-point values
232 * y <-- array of floating-point values
233 * xx --> x.x dot product
234 * xy --> x.y dot product
235 *----------------------------------------------------------------------------*/
236
237void
239 const cs_real_t *x,
240 const cs_real_t *y,
241 double *xx,
242 double *xy);
243
244/*----------------------------------------------------------------------------
245 * Return the double dot product of 3 vectors: x.y, and y.z
246 *
247 * The products could be computed separately, but computing them
248 * simultaneously adds more optimization opportunities and possibly better
249 * cache behavior.
250 *
251 * parameters:
252 * n <-- size of arrays x and y
253 * x <-- array of floating-point values
254 * y <-- array of floating-point values
255 * z <-- array of floating-point values
256 * xy --> x.y dot product
257 * yz --> x.z dot product
258 *----------------------------------------------------------------------------*/
259
260void
262 const cs_real_t *x,
263 const cs_real_t *y,
264 const cs_real_t *z,
265 double *xx,
266 double *xy);
267
268/*----------------------------------------------------------------------------
269 * Return 3 dot products of 3 vectors: x.x, x.y, and y.z
270 *
271 * The products could be computed separately, but computing them
272 * simultaneously adds more optimization opportunities and possibly better
273 * cache behavior.
274 *
275 * parameters:
276 * n <-- size of arrays x and y
277 * x <-- array of floating-point values
278 * y <-- array of floating-point values
279 * z <-- array of floating-point values
280 * xx --> x.y dot product
281 * xy --> x.y dot product
282 * yz --> y.z dot product
283 *----------------------------------------------------------------------------*/
284
285void
287 const cs_real_t *x,
288 const cs_real_t *y,
289 const cs_real_t *z,
290 double *xx,
291 double *xy,
292 double *yz);
293
294/*----------------------------------------------------------------------------
295 * Return 5 dot products of 3 vectors: x.x, y.y, x.y, x.z, and y.z
296 *
297 * The products could be computed separately, but computing them
298 * simultaneously adds more optimization opportunities and possibly better
299 * cache behavior.
300 *
301 * parameters:
302 * n <-- size of arrays x and y
303 * x <-- array of floating-point values
304 * y <-- array of floating-point values
305 * z <-- array of floating-point values
306 * xx --> x.y dot product
307 * yy --> y.y dot product
308 * xy --> x.y dot product
309 * xz --> x.z dot product
310 * yz --> y.z dot product
311 *----------------------------------------------------------------------------*/
312
313void
315 const cs_real_t *x,
316 const cs_real_t *y,
317 const cs_real_t *z,
318 double *xx,
319 double *yy,
320 double *xy,
321 double *xz,
322 double *yz);
323
324/*----------------------------------------------------------------------------
325 * Return the global dot product of 2 vectors: x.y
326 *
327 * In parallel mode, the local results are summed on the default
328 * global communicator.
329 *
330 * parameters:
331 * n <-- size of arrays x and y
332 * x <-- array of floating-point values
333 * y <-- array of floating-point values
334 *
335 * returns:
336 * dot product
337 *----------------------------------------------------------------------------*/
338
339double
341 const cs_real_t *x,
342 const cs_real_t *y);
343
344/*----------------------------------------------------------------------------
345 * Return the global dot product of a vector: x.x
346 *
347 * In parallel mode, the local results are summed on the default
348 * global communicator.
349 *
350 * parameters:
351 * n <-- size of arrays x and y
352 * x <-- array of floating-point values
353 *
354 * returns:
355 * dot product
356 *----------------------------------------------------------------------------*/
357
358double
359cs_gdot_xx(cs_lnum_t n, const cs_real_t *x);
360
361/*----------------------------------------------------------------------------
362 * Return the global double dot product of 2 vectors: x.x, and x.y
363 *
364 * The products could be computed separately, but computing them
365 * simultaneously adds more optimization opportunities and possibly better
366 * cache behavior.
367 *
368 * In parallel mode, the local results are summed on the default
369 * global communicator.
370 *
371 * parameters:
372 * n <-- size of arrays x and y
373 * x <-- array of floating-point values
374 * y <-- array of floating-point values
375 * xx --> x.x dot product
376 * xy --> x.y dot product
377 *----------------------------------------------------------------------------*/
378
379void
381 const cs_real_t *x,
382 const cs_real_t *y,
383 double *xx,
384 double *xy);
385
386/*----------------------------------------------------------------------------
387 * Return the global residual of 2 intensive vectors:
388 * 1/sum(vol) . sum(vol.x.y)
389 *
390 * parameters:
391 * n <-- size of arrays x and y
392 * vol <-- array of floating-point values
393 * x <-- array of floating-point values
394 * y <-- array of floating-point values
395 *
396 * returns:
397 * global residual
398 *----------------------------------------------------------------------------*/
399
400double
402 const cs_real_t *vol,
403 const cs_real_t *x,
404 const cs_real_t *y);
405
406/*----------------------------------------------------------------------------
407 * Return the global volume weighted mean
408 * 1/sum(vol) . sum(vol.x)
409 *
410 * parameters:
411 * n <-- size of arrays x
412 * vol <-- array of floating-point values
413 * x <-- array of floating-point values
414 *
415 * returns:
416 * global residual
417 *----------------------------------------------------------------------------*/
418
419double
421 const cs_real_t *vol,
422 const cs_real_t *x);
423
424/*----------------------------------------------------------------------------*/
425
427
428#endif /* __CS_BLAS_H__ */
Definition: cs_dispatch.h:1711
double cs_gmean(cs_lnum_t n, const cs_real_t *vol, const cs_real_t *x)
Return the global spacial average of an intensive vectors: 1/sum(vol) . sum(x.vol)
Definition: cs_blas.cpp:1977
double cs_dot_wxx(cs_lnum_t n, const cs_real_t *w, const cs_real_t *x)
Definition: cs_blas.cpp:1684
double cs_dot(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y)
Return the dot product of 2 vectors: x.y.
Definition: cs_blas.cpp:1644
void cs_gdot_xx_xy(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y, double *xx, double *xy)
Definition: cs_blas.cpp:1918
double cs_gdot_xx(cs_lnum_t n, const cs_real_t *x)
Definition: cs_blas.cpp:1890
void cs_dot_xy_yz(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xx, double *xy)
void cs_axpy(cs_dispatch_context &ctx, cs_lnum_t n, cs_real_t a, const cs_real_t *x, cs_real_t *restrict y)
Constant times a vector plus a vector: y <– ax + y.
Definition: cs_blas.cpp:1379
double cs_weighted_sum(cs_lnum_t n, const cs_real_t *w, const cs_real_t *x)
Definition: cs_blas.cpp:1587
double cs_dot_xx(cs_lnum_t n, const cs_real_t *x)
Return dot products of a vector with itself: x.x.
Definition: cs_blas.cpp:1665
void cs_dot_xx_xy_yz(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xx, double *xy, double *yz)
cs_blas_reduce_t
Definition: cs_blas.h:58
@ CS_BLAS_REDUCE_KAHAN
Definition: cs_blas.h:61
@ CS_BLAS_REDUCE_SUPERBLOCK
Definition: cs_blas.h:60
void cs_blas_set_reduce_algorithm(cs_blas_reduce_t mode)
Set the preferred BLAS reduction algorithm family.
Definition: cs_blas.cpp:1459
void cs_dot_xx_yy_xy_xz_yz(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y, const cs_real_t *z, double *xx, double *yy, double *xy, double *xz, double *yz)
double cs_gres(cs_lnum_t n, const cs_real_t *vol, const cs_real_t *x, const cs_real_t *y)
Return the global residual of 2 intensive vectors: 1/sum(vol) . sum(x.y.vol)
Definition: cs_blas.cpp:1952
void cs_dot_xx_xy(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y, double *xx, double *xy)
double cs_sum(cs_lnum_t n, const cs_real_t *x)
Definition: cs_blas.cpp:1533
void cs_blas_library_info(cs_log_t log_type)
Print information on BLAS libraries used.
Definition: cs_blas.cpp:1431
double cs_gdot(cs_lnum_t n, const cs_real_t *x, const cs_real_t *y)
Return the global dot product of 2 vectors: x.y.
Definition: cs_blas.cpp:1864
#define restrict
Definition: cs_defs.h:158
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
cs_log_t
Definition: cs_log.h:48