Numerical Methods Contents - SAM
Numerical Methods Contents - SAM
Numerical Methods Contents - SAM
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Syntax of BLAS calls:<br />
The functions have been implemented for different types, and are distinguished by the first letter of the<br />
function name. E.g. sdot is the dot product implementation for single precision and ddot for double<br />
precision.<br />
BLAS LEVEL 1: vector operations, asymptotic complexity O(n), n ˆ= vector length<br />
• dot product<br />
ρ = x T y<br />
xDOT(N,X,INCX,Y,INCY)<br />
– x ∈ {S, D}, scalar type: S ˆ= type float, D ˆ= type double<br />
– N ˆ= length of vector (modulo stride INCX)<br />
– X ˆ= vector x: array of type x<br />
– INCX ˆ= stride for traversing vector X<br />
– Y ˆ= vector y: array of type x<br />
– INCY ˆ= stride for traversing vector Y<br />
• vector operations y = αx + y<br />
xAXPY(N,ALPHA,X,INCX,Y,INCY)<br />
Ôº ½º<br />
– x ∈ {S, D, C, Z}, S ˆ= type float, D ˆ= type double, C ˆ= type complex<br />
– N ˆ= length of vector (modulo stride INCX)<br />
– ALPHA ˆ= scalar α<br />
– X ˆ= vector x: array of type x<br />
– INCX ˆ= stride for traversing vector X<br />
– Y ˆ= vector y: array of type x<br />
– INCY ˆ= stride for traversing vector Y<br />
BLAS LEVEL 2: matrix-vector operations, asymptotic complexity O(mn), (m, n) ˆ= matrix size<br />
• matrix×vector multiplication<br />
y = αAx + βy<br />
xGEMV(TRANS,M,N,ALPHA,A,LDA,X,<br />
INCX,BETA,Y,INCY)<br />
– x ∈ {S, D, C, Z}, scalar type: S ˆ= type float, D ˆ= type double, C ˆ= type complex<br />
– M,N ˆ= size of matrix A<br />
– ALPHA ˆ= scalar parameter α<br />
– A ˆ= matrix A stored in linear array of length M · N (column major arrangement)<br />
(A) i,j = A[N ∗ (j − 1) + i] .<br />
– LDA ˆ= “leading dimension” of A ∈ K n,m , that is, the number n of rows.<br />
– X ˆ= vector x: array of type x<br />
– INCX ˆ= stride for traversing vector X<br />
– BETA ˆ= scalar paramter β<br />
– Y ˆ= vector y: array of type x<br />
– INCY ˆ= stride for traversing vector Y<br />
• BLAS LEVEL 3: matrix-matrix operations, asymptotic complexity O(mnk), (m, n,k) ˆ= matrix<br />
sizes<br />
– matrix×matrix multiplication C = αAB + βC<br />
xGEMM(TRANSA,TRANSB,M,N,K,<br />
ALPHA,A,LDA,X,B,LDB,<br />
BETA,C,LDC)<br />
(☞ meaning of arguments as above)<br />
Example 1.4.1 (Gaining efficiency through use of BLAS).<br />
Code 1.4.2: ColumnMajor Matrix Class in C++, Ex. 1.4.1<br />
1 /∗ Author : Manfred Quack<br />
2 ∗ ColumnMajorMatrix . h<br />
3 ∗ This Class Implements a ColumnMajor M a trix S t r u c t u r e i n C++<br />
4 ∗ − i t provides an access operator ( ) using ColumnMajor Access<br />
5 ∗ − i t also provides 4 d i f f e r e n t implementations o f a Matrix−M a trix<br />
M u l t i p l i c a t i o n<br />
6 ∗/<br />
7 #include <br />
8 #include < c s t d l i b ><br />
9 #include < s t d i o . h><br />
10 #include <br />
11 # ifndef _USE_MKL<br />
12 # i f d e f _MAC_OS<br />
13 #include / / part of Accelerate Framework<br />
14 # endif<br />
15 # i f d e f _LINUX<br />
16 extern "C" {<br />
17 #include <br />
18 }<br />
19 # endif<br />
20 #else<br />
Ôº¼ ½º<br />
Ôº¾ ½º<br />
21 #include <br />
Ôº½ ½º