




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















computation time
in optimization methods is
spent on numerical linear algebra,
e.g.,
-^ constructing sets of linear equations (
e.g., Newton or KKT systems)
-^ matrix-matrix products, matrix-vector products,... • and solving them –^ factoring, forward and backward substitution,.. .... so knowing about numerical linear algebra is a good thing Prof. S. Boyd, EE364b, Stanford University
whenever possible, rely on
existing, mature
software libraries
-^ you can focus on the higher-level algorithm •^ your code will be more portable, less buggy, and will runfaster—sometimes
much^ faster Prof. S. Boyd, EE364b, Stanford University
the grandfather of
all^ numerical linear algebra web sites^ http://www.netlib.org
-^ maintained by University of Tennessee, Oak Ridge National Laboratory,and colleagues worldwide •^ most of the code is public domain or freely licensed •^ much written in FORTRAN 77 (gasp!) Prof. S. Boyd, EE364b, Stanford University
Level 1^ addition/scaling
αx,^
αx^ +^ y dot products, norms
T^ xy,^ ‖ x‖,^ ‖x‖^21
Level 2^ matrix/vector products
αAx^ +^ βy,
T^ αAx^ +^ βy
rank 1 updates
T^ αxy,^ A^ +^ Tαxx
rank 2 updates
T^ T αxy+^ αyx triangular solves
− αT 1 −T^ x,^ αT^ x Level 3^ matrix/matrix products
αAB^ +^ βC
T^ , αAB+^ βCT T^ T^ αAB + βC, αAB+ βC
rank-k^ updates
αAA
T^ +^ βC,^ αA
T^ A^ +^ βC
rank-^2 k^ updates
T αA T^ B^ +^ αBA^ +
βC
triangular solves
− αT 1 −T^ C,^ αT^ C
Prof. S. Boyd, EE364b, Stanford University
BLAS routines have a Fortran-inspired naming convention:
cblas_^
X^ XXXX prefix data type^ operation data types:^ s^ single precision real
d^ double precision real c^ single precision complex
z^ double precision complex operations:^ axpy^
y^ ←^ αx^ +^ y^
Tdot r ← x y
nrm2^ r^ ← ‖
√T^ x‖= xx^2 asum^ r^ ← ‖
∑x‖= |x| 1 i^ i^
example:^ cblas_ddot
double precision real dot product Prof. S. Boyd, EE364b, Stanford University
always choose a higher-level BLAS routine over multiple calls to alower-level BLAS routine^ A^ ←
k∑T A +^ xyii^ i=
m×n, A ∈ R m, x∈ R, yi i n∈ R
two choices:^ k
separate calls to the Level 2 routine
cblas_dger A^ ←^ A^ +^ xy^1
T A + xykk
or a single call to the Level 3 routine
cblas_dgemm A^ ←^ A^ +^ XY
T^ ,^ X^ = [x^1 · · ·^ x]^ ,^ Y^ = [k
y· · ·^ y]^1 k
the Level 3 choice will perform much better Prof. S. Boyd, EE364b, Stanford University
why use BLAS when writing your own routines is so easy?^ A^ ←^
m×nA ∈ R, X m×p ∈ R, Y^ ∈ n×p R A←^ A+ij^ ij^
p∑^ XYikjk k= void matmultadd( int m, int n, int p, double* A,
const double* X, const double* Y ) { int i, j, k;for ( i = 0 ; i < m ; ++i )for ( j = 0 ; j < n ; ++j )for ( k = 0 ; k < p ; ++k )A[ i + j * n ] += X[ i + k * p ] * Y[ j + k * p ];} Prof. S. Boyd, EE364b, Stanford University
auxiliary^ routines,
computational
routines, and^ driver
routines Prof. S. Boyd, EE364b, Stanford University
driver routines call a sequence of computational routines to solve standardlinear algebra problems, such as^ •^ linear equations:
-^ linear least squares: minimize
‖b^ −^ Ax‖x 2
-^ linear least-norm:
minimize
‖y‖y (^2) subject to d^ =^ By
-^ generalized linear least squares problems:minimize
‖c^ −^ Ax‖x (^2) subject to Bx^ =^ d
minimize‖yy^
subject to^ d^
=^ Ax^ +^ By
Prof. S. Boyd, EE364b, Stanford University
solve KKT system
] [^ ]^ [^ xa^ =yb
n x ∈ R,^ v^ ∈^ R mT^ ,^ H^ =^ H≻
0 ,^ m < n option 1^ : driver routine
dsysv^ uses computational routine
dsytrf^ to
compute permuted
T^ LDLfactorization [^ H^ A A^0
T
and performs remaining computations to compute solution
[^ ]xT^ =^ P^ Ly
[^ ]a b
Prof. S. Boyd, EE364b, Stanford University
BLAS and LAPACK routines can be called from C, C++, Java, Python,... an alternative is to use a “native” library, such as^ •^ C++: Boost uBlas, Matrix Template Library^ •^ Python: NumPy/SciPy, CVXOPT^ •^ Java: JAMA Prof. S. Boyd, EE364b, Stanford University
0 5 30 35 40 10 15 20 25 30 35 40 nz = 505 m×n^ • A ∈ R is^ sparse^ if it has “enough zeros that it pays to takeadvantage of them” (J. Wilkinson)
-^ usually this means
n, number of elements known to be nonzero, isnz small:^ n≪^ nz^
mn Prof. S. Boyd, EE364b, Stanford University