programmer's 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-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 #include "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------
33  * External library headers
34  *----------------------------------------------------------------------------*/
35 
36 /*----------------------------------------------------------------------------
37  * Local headers
38  *----------------------------------------------------------------------------*/
39 
40 #include "cs_base.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*============================================================================
51  * Type definitions
52  *============================================================================*/
53 
54 /* BLAS reduction algorithm families */
55 
56 typedef enum {
57 
60 
62 
63 /*============================================================================
64  * Public function prototypes
65  *============================================================================*/
66 
67 /*----------------------------------------------------------------------------*/
76 /*----------------------------------------------------------------------------*/
77 
78 void
80 
81 /*----------------------------------------------------------------------------
82  * Constant times a vector plus a vector: y <-- ax + y
83  *
84  * parameters:
85  * n <-- size of arrays x and y
86  * a <-- multiplier for x
87  * x <-- array of floating-point values
88  * y <-- array of floating-point values
89  *----------------------------------------------------------------------------*/
90 
91 void
93  double a,
94  const cs_real_t *x,
95  cs_real_t *restrict y);
96 
97 /*----------------------------------------------------------------------------
98  * Return the sum of a vector. For better precision, a superblock algorithm
99  * is used.
100  *
101  * parameters:
102  * n <-- size of array x
103  * x <-- array of floating-point values
104  *
105  * returns:
106  * the resulting sum
107  *----------------------------------------------------------------------------*/
108 
109 double
110 cs_sum(cs_lnum_t n,
111  const cs_real_t *x);
112 
113 /*----------------------------------------------------------------------------
114  * Return the dot product of 2 vectors: x.y
115  *
116  * parameters:
117  * n <-- size of arrays x and y
118  * x <-- array of floating-point values
119  * y <-- array of floating-point values
120  *
121  * returns:
122  * dot product
123  *----------------------------------------------------------------------------*/
124 
125 double
126 cs_dot(cs_lnum_t n,
127  const cs_real_t *x,
128  const cs_real_t *y);
129 
130 /*----------------------------------------------------------------------------
131  * Return dot products of a vector with itself: x.x
132  *
133  * parameters:
134  * n <-- size of arrays x
135  * x <-- array of floating-point values
136  *
137  * returns:
138  * dot product
139  *----------------------------------------------------------------------------*/
140 
141 double
143  const cs_real_t *x);
144 
145 /*----------------------------------------------------------------------------
146  * Return weighted dot products of a vector with itself: x.x
147  *
148  * For better precision, a superblock algorithm is used.
149  *
150  * parameters:
151  * n <-- size of arrays x
152  * w <-- array of weights
153  * x <-- array of floating-point values
154  *
155  * returns:
156  * dot product
157  *----------------------------------------------------------------------------*/
158 
159 double
161  const cs_real_t *w,
162  const cs_real_t *x);
163 
164 /*----------------------------------------------------------------------------
165  * Return the double dot product of 2 vectors: x.x, and x.y
166  *
167  * The products could be computed separately, but computing them
168  * simultaneously adds more optimization opportunities and possibly better
169  * cache behavior.
170  *
171  * parameters:
172  * n <-- size of arrays x and y
173  * x <-- array of floating-point values
174  * y <-- array of floating-point values
175  * xx --> x.x dot product
176  * xy --> x.y dot product
177  *----------------------------------------------------------------------------*/
178 
179 void
181  const cs_real_t *restrict x,
182  const cs_real_t *restrict y,
183  double *xx,
184  double *xy);
185 
186 /*----------------------------------------------------------------------------
187  * Return the double dot product of 3 vectors: x.y, and y.z
188  *
189  * The products could be computed separately, but computing them
190  * simultaneously adds more optimization opportunities and possibly better
191  * cache behavior.
192  *
193  * parameters:
194  * n <-- size of arrays x and y
195  * x <-- array of floating-point values
196  * y <-- array of floating-point values
197  * z <-- array of floating-point values
198  * xy --> x.y dot product
199  * yz --> x.z dot product
200  *----------------------------------------------------------------------------*/
201 
202 void
204  const cs_real_t *restrict x,
205  const cs_real_t *restrict y,
206  const cs_real_t *restrict z,
207  double *xx,
208  double *xy);
209 
210 /*----------------------------------------------------------------------------
211  * Return 3 dot products of 3 vectors: x.x, x.y, and y.z
212  *
213  * The products could be computed separately, but computing them
214  * simultaneously adds more optimization opportunities and possibly better
215  * cache behavior.
216  *
217  * parameters:
218  * n <-- size of arrays x and y
219  * x <-- array of floating-point values
220  * y <-- array of floating-point values
221  * z <-- array of floating-point values
222  * xx --> x.y dot product
223  * xy --> x.y dot product
224  * yz --> y.z dot product
225  *----------------------------------------------------------------------------*/
226 
227 void
229  const cs_real_t *restrict x,
230  const cs_real_t *restrict y,
231  const cs_real_t *restrict z,
232  double *xx,
233  double *xy,
234  double *yz);
235 
236 /*----------------------------------------------------------------------------
237  * Return 5 dot products of 3 vectors: x.x, y.y, x.y, x.z, and y.z
238  *
239  * The products could be computed separately, but computing them
240  * simultaneously adds more optimization opportunities and possibly better
241  * cache behavior.
242  *
243  * parameters:
244  * n <-- size of arrays x and y
245  * x <-- array of floating-point values
246  * y <-- array of floating-point values
247  * z <-- array of floating-point values
248  * xx --> x.y dot product
249  * yy --> y.y dot product
250  * xy --> x.y dot product
251  * xz --> x.z dot product
252  * yz --> y.z dot product
253  *----------------------------------------------------------------------------*/
254 
255 void
257  const cs_real_t *restrict x,
258  const cs_real_t *restrict y,
259  const cs_real_t *restrict z,
260  double *xx,
261  double *yy,
262  double *xy,
263  double *xz,
264  double *yz);
265 
266 /*----------------------------------------------------------------------------
267  * Return the global dot product of 2 vectors: x.y
268  *
269  * In parallel mode, the local results are summed on the default
270  * global communicator.
271  *
272  * parameters:
273  * n <-- size of arrays x and y
274  * x <-- array of floating-point values
275  * y <-- array of floating-point values
276  *
277  * returns:
278  * dot product
279  *----------------------------------------------------------------------------*/
280 
281 double
283  const cs_real_t *x,
284  const cs_real_t *y);
285 
286 /*----------------------------------------------------------------------------
287  * Return the global residual of 2 extensive vectors:
288  * 1/sum(vol) . sum(X.Y/vol)
289  *
290  * parameters:
291  * n <-- size of arrays x and y
292  * vol <-- array of floating-point values
293  * x <-- array of floating-point values
294  * y <-- array of floating-point values
295  *
296  * returns:
297  * global residual
298  *----------------------------------------------------------------------------*/
299 
300 double
302  const cs_real_t *vol,
303  const cs_real_t *x,
304  const cs_real_t *y);
305 
306 /*----------------------------------------------------------------------------*/
307 
309 
310 #endif /* __CS_BLAS_H__ */
#define restrict
Definition: cs_defs.h:122
cs_blas_reduce_t
Reduction algorithm type.
Definition: cs_blas.h:56
#define BEGIN_C_DECLS
Definition: cs_defs.h:462
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.c:1588
void cs_axpy(cs_lnum_t n, double a, const cs_real_t *x, cs_real_t *restrict y)
Constant times a vector plus a vector: y <– ax + y.
Definition: cs_blas.c:1280
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.c:1368
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_blas.h:59
double cs_dot_wxx(cs_lnum_t n, const cs_real_t *w, const cs_real_t *x)
Definition: cs_blas.c:1408
void cs_dot_xx_xy(cs_lnum_t n, const cs_real_t *restrict x, const cs_real_t *restrict y, double *xx, double *xy)
Return 2 dot products of 2 vectors: x.x, and x.y.
Definition: cs_blas.c:1469
double precision, save a
Definition: cs_fuel_incl.f90:146
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.c:1389
void cs_blas_set_reduce_algorithm(cs_blas_reduce_t mode)
Set the preferred BLAS reduction algorithm family.
Definition: cs_blas.c:1241
void cs_dot_xx_xy_yz(cs_lnum_t n, const cs_real_t *restrict x, const cs_real_t *restrict y, const cs_real_t *restrict z, double *xx, double *xy, double *yz)
Return 3 dot products of 3 vectors: x.x, x.y, and y.z.
Definition: cs_blas.c:1525
double cs_sum(cs_lnum_t n, const cs_real_t *x)
Definition: cs_blas.c:1313
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
#define END_C_DECLS
Definition: cs_defs.h:463
void cs_dot_xx_yy_xy_xz_yz(cs_lnum_t n, const cs_real_t *restrict x, const cs_real_t *restrict y, const cs_real_t *restrict z, double *xx, double *yy, double *xy, double *xz, double *yz)
Return 5 dot products of 3 vectors: x.x, y.y, x.y, x.z, and y.z.
Definition: cs_blas.c:1557
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 extensive vectors: 1/sum(vol) . sum(X.Y/vol)
Definition: cs_blas.c:1617
Definition: cs_blas.h:58
void cs_dot_xy_yz(cs_lnum_t n, const cs_real_t *restrict x, const cs_real_t *restrict y, const cs_real_t *restrict z, double *xx, double *xy)
Return 2 dot products of 3 vectors: x.y, and y.z.
Definition: cs_blas.c:1496