9.2
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-2026 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 * Macro definitions
46 *============================================================================*/
47
48/*============================================================================
49 * Type definitions
50 *============================================================================*/
51
52/* BLAS reduction algorithm families */
53
55typedef enum {
56
63
64/*============================================================================
65 * Public function prototypes
66 *============================================================================*/
67
68/*----------------------------------------------------------------------------*/
69/*
70 * \brief Constant times a vector plus a vector: y <-- ax + y
71 *
72 * \param[in] ctx reference to dispatch context
73 * \param[in] n size of arrays x and y
74 * \param[in] a multiplier for x
75 * \param[in] x array of floating-point values
76 * \param[in, out] y array of floating-point values
77 */
78/*----------------------------------------------------------------------------*/
79
80void
82 cs_lnum_t n,
83 cs_real_t a,
84 const cs_real_t *x,
86
87/*----------------------------------------------------------------------------*/
88/*
89 * \brief Return the dot product of 2 vectors: x.y
90 *
91 * \param[in] ctx reference to dispatch context
92 * \param[in] n size of arrays x and y
93 * \param[in] x array of floating-point values
94 * \param[in] y array of floating-point values
95 *
96 * \return dot product
97 */
98/*----------------------------------------------------------------------------*/
99
100double
102 cs_lnum_t n,
103 const cs_real_t *x,
104 const cs_real_t *y);
105
106/*----------------------------------------------------------------------------*/
107/*
108 * \brief Return dot products of a vector with itself: x.x
109 *
110 * For better precision, a superblock algorithm is used.
111 *
112 * \param[in] ctx reference to dispatch context
113 * \param[in] n size of array x
114 * \param[in] x array of floating-point values
115 *
116 * \return dot product
117 */
118/*----------------------------------------------------------------------------*/
119
120double
121cs_dot_xx([[maybe_unused]] cs_dispatch_context &ctx,
122 cs_lnum_t n,
123 const cs_real_t *x);
124
125/*----------------------------------------------------------------------------*/
126/*
127 * \brief Print information on BLAS libraries used.
128 *
129 * \param[in] log_type log type
130 */
131/*----------------------------------------------------------------------------*/
132
133void
135
136/*----------------------------------------------------------------------------*/
137/*
138 * \brief Set the preferred BLAS reduction algorithm family.
139 *
140 * This may not be enforced for all algorithms, though it should at least
141 * be enforced for the most general functions such as \ref cs_dot.
142 *
143 * \param[in] mode BLAS mode to use
144 */
145/*----------------------------------------------------------------------------*/
146
147void
149
150/*----------------------------------------------------------------------------
151 * Constant times a vector plus a vector: y <-- ax + y
152 *
153 * parameters:
154 * n <-- size of arrays x and y
155 * a <-- multiplier for x
156 * x <-- array of floating-point values
157 * y <-- array of floating-point values
158 *----------------------------------------------------------------------------*/
159
160void
162 double a,
163 const cs_real_t *x,
164 cs_real_t *y);
165
166/*----------------------------------------------------------------------------
167 * Return the sum of a vector. For better precision, a superblock algorithm
168 * is used.
169 *
170 * parameters:
171 * n <-- size of array x
172 * x <-- array of floating-point values
173 *
174 * returns:
175 * the resulting sum
176 *----------------------------------------------------------------------------*/
177
178double
180 const cs_real_t *x);
181
182/*----------------------------------------------------------------------------
183 * Return the weighted sum of a vector. For better precision, a superblock
184 * algorithm is used.
185 *
186 * \param[in] n size of array x
187 * \param[in] w array of floating-point weights
188 * \param[in] x array of floating-point values
189 *
190 * \return the resulting weighted sum
191 *----------------------------------------------------------------------------*/
192
193double
195 const cs_real_t *w,
196 const cs_real_t *x);
197
198
199/*----------------------------------------------------------------------------
200 * Return the dot product of 2 vectors: x.y
201 *
202 * parameters:
203 * n <-- size of arrays x and y
204 * x <-- array of floating-point values
205 * y <-- array of floating-point values
206 *
207 * returns:
208 * dot product
209 *----------------------------------------------------------------------------*/
210
211double
213 const cs_real_t *x,
214 const cs_real_t *y);
215
216/*----------------------------------------------------------------------------
217 * Return dot products of a vector with itself: x.x
218 *
219 * parameters:
220 * n <-- size of arrays x
221 * x <-- array of floating-point values
222 *
223 * returns:
224 * dot product
225 *----------------------------------------------------------------------------*/
226
227double
229 const cs_real_t *x);
230
231/*----------------------------------------------------------------------------
232 * Return weighted dot products of a vector with itself: x.x
233 *
234 * For better precision, a superblock algorithm is used.
235 *
236 * parameters:
237 * n <-- size of arrays x
238 * w <-- array of weights
239 * x <-- array of floating-point values
240 *
241 * returns:
242 * dot product
243 *----------------------------------------------------------------------------*/
244
245double
247 const cs_real_t *w,
248 const cs_real_t *x);
249
250/*----------------------------------------------------------------------------
251 * Return the double dot product of 2 vectors: x.x, and x.y
252 *
253 * The products could be computed separately, but computing them
254 * simultaneously adds more optimization opportunities and possibly better
255 * cache behavior.
256 *
257 * parameters:
258 * n <-- size of arrays x and y
259 * x <-- array of floating-point values
260 * y <-- array of floating-point values
261 * xx --> x.x dot product
262 * xy --> x.y dot product
263 *----------------------------------------------------------------------------*/
264
265void
267 const cs_real_t *x,
268 const cs_real_t *y,
269 double *xx,
270 double *xy);
271
272/*----------------------------------------------------------------------------
273 * Return the double dot product of 3 vectors: x.y, and y.z
274 *
275 * The products could be computed separately, but computing them
276 * simultaneously adds more optimization opportunities and possibly better
277 * cache behavior.
278 *
279 * parameters:
280 * n <-- size of arrays x and y
281 * x <-- array of floating-point values
282 * y <-- array of floating-point values
283 * z <-- array of floating-point values
284 * xy --> x.y dot product
285 * yz --> x.z dot product
286 *----------------------------------------------------------------------------*/
287
288void
290 const cs_real_t *x,
291 const cs_real_t *y,
292 const cs_real_t *z,
293 double *xx,
294 double *xy);
295
296/*----------------------------------------------------------------------------
297 * Return 3 dot products of 3 vectors: x.x, x.y, and y.z
298 *
299 * The products could be computed separately, but computing them
300 * simultaneously adds more optimization opportunities and possibly better
301 * cache behavior.
302 *
303 * parameters:
304 * n <-- size of arrays x and y
305 * x <-- array of floating-point values
306 * y <-- array of floating-point values
307 * z <-- array of floating-point values
308 * xx --> x.y dot product
309 * xy --> x.y 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 *xy,
320 double *yz);
321
322/*----------------------------------------------------------------------------
323 * Return 5 dot products of 3 vectors: x.x, y.y, x.y, x.z, and y.z
324 *
325 * The products could be computed separately, but computing them
326 * simultaneously adds more optimization opportunities and possibly better
327 * cache behavior.
328 *
329 * parameters:
330 * n <-- size of arrays x and y
331 * x <-- array of floating-point values
332 * y <-- array of floating-point values
333 * z <-- array of floating-point values
334 * xx --> x.y dot product
335 * yy --> y.y dot product
336 * xy --> x.y dot product
337 * xz --> x.z dot product
338 * yz --> y.z dot product
339 *----------------------------------------------------------------------------*/
340
341void
343 const cs_real_t *x,
344 const cs_real_t *y,
345 const cs_real_t *z,
346 double *xx,
347 double *yy,
348 double *xy,
349 double *xz,
350 double *yz);
351
352/*----------------------------------------------------------------------------
353 * Return the global dot product of 2 vectors: x.y
354 *
355 * In parallel mode, the local results are summed on the default
356 * global communicator.
357 *
358 * parameters:
359 * n <-- size of arrays x and y
360 * x <-- array of floating-point values
361 * y <-- array of floating-point values
362 *
363 * returns:
364 * dot product
365 *----------------------------------------------------------------------------*/
366
367double
369 const cs_real_t *x,
370 const cs_real_t *y);
371
372/*----------------------------------------------------------------------------
373 * Return the global dot product of a vector: x.x
374 *
375 * In parallel mode, the local results are summed on the default
376 * global communicator.
377 *
378 * parameters:
379 * n <-- size of arrays x and y
380 * x <-- array of floating-point values
381 *
382 * returns:
383 * dot product
384 *----------------------------------------------------------------------------*/
385
386double
387cs_gdot_xx(cs_lnum_t n, const cs_real_t *x);
388
389/*----------------------------------------------------------------------------
390 * Return the global double dot product of 2 vectors: x.x, and x.y
391 *
392 * The products could be computed separately, but computing them
393 * simultaneously adds more optimization opportunities and possibly better
394 * cache behavior.
395 *
396 * In parallel mode, the local results are summed on the default
397 * global communicator.
398 *
399 * parameters:
400 * n <-- size of arrays x and y
401 * x <-- array of floating-point values
402 * y <-- array of floating-point values
403 * xx --> x.x dot product
404 * xy --> x.y dot product
405 *----------------------------------------------------------------------------*/
406
407void
409 const cs_real_t *x,
410 const cs_real_t *y,
411 double *xx,
412 double *xy);
413
414/*----------------------------------------------------------------------------
415 * Return the global residual of 2 intensive vectors:
416 * 1/sum(vol) . sum(vol.x.y)
417 *
418 * parameters:
419 * n <-- size of arrays x and y
420 * vol <-- array of floating-point values
421 * x <-- array of floating-point values
422 * y <-- array of floating-point values
423 *
424 * returns:
425 * global residual
426 *----------------------------------------------------------------------------*/
427
428double
430 const cs_real_t *vol,
431 const cs_real_t *x,
432 const cs_real_t *y);
433
434/*----------------------------------------------------------------------------
435 * Return the global volume weighted mean
436 * 1/sum(vol) . sum(vol.x)
437 *
438 * parameters:
439 * n <-- size of arrays x
440 * vol <-- array of floating-point values
441 * x <-- array of floating-point values
442 *
443 * returns:
444 * global residual
445 *----------------------------------------------------------------------------*/
446
447double
449 const cs_real_t *vol,
450 const cs_real_t *x);
451
452/*----------------------------------------------------------------------------*/
453
454#endif /* CS_BLAS_H */
Definition: cs_dispatch.h:2288
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:2025
double cs_dot_wxx(cs_lnum_t n, const cs_real_t *w, const cs_real_t *x)
Definition: cs_blas.cpp:1732
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:1966
double cs_gdot_xx(cs_lnum_t n, const cs_real_t *x)
Definition: cs_blas.cpp:1938
double cs_dot(cs_dispatch_context &ctx, 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:1629
double cs_dot_xx(cs_dispatch_context &ctx, cs_lnum_t n, const cs_real_t *x)
Return dot products of a vector with itself: x.x.
Definition: cs_blas.cpp:1682
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:1367
double cs_weighted_sum(cs_lnum_t n, const cs_real_t *w, const cs_real_t *x)
Definition: cs_blas.cpp:1571
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:55
@ CS_BLAS_REDUCE_KAHAN
Definition: cs_blas.h:59
@ CS_BLAS_REDUCE_SUPERBLOCK
Definition: cs_blas.h:57
void cs_blas_set_reduce_algorithm(cs_blas_reduce_t mode)
Set the preferred BLAS reduction algorithm family.
Definition: cs_blas.cpp:1443
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:2000
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:1517
void cs_blas_library_info(cs_log_t log_type)
Print information on BLAS libraries used.
Definition: cs_blas.cpp:1415
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:1912
#define restrict
Definition: cs_defs.h:148
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_log_t
Definition: cs_log.h:44