UMFPACK Quick Start Guide: Timothy A. Davis VERSION 5.7.7, Mar 23, 2018
UMFPACK Quick Start Guide: Timothy A. Davis VERSION 5.7.7, Mar 23, 2018
Timothy A. Davis
[email protected], http://www.suitesparse.com
Abstract
UMFPACK is a set of routines for solving unsymmetric sparse linear systems, Ax = b,
using the Unsymmetric-pattern MultiFrontal method and direct sparse LU factorization. It is
written in ANSI/ISO C, with a MATLAB interface. UMFPACK relies on the Level-3 Basic
Linear Algebra Subprograms (dense matrix multiply) for its performance. This code works on
Windows and many versions of Unix (Sun Solaris, Red Hat Linux, IBM AIX, SGI IRIX, and
Compaq Alpha). This is a “quick start” guide for Unix users of the C interface.
Copyright
1995-2018
c by Timothy A. Davis. All Rights Reserved. Refer to the UMFPACK
User Guide for the License. See http://www.suitesparse.com for the code and full documentation.
1 Overview
UMFPACK is a set of routines for solving systems of linear equations, Ax = b, when A is sparse
and unsymmetric. The sparse matrix A can be square or rectangular, singular or non-singular,
and real or complex (or any combination). Only square matrices A can be used to solve Ax = b
or related systems. Rectangular matrices can only be factorized.
UMFPACK is a built-in routine in MATLAB used by the forward and backslash operator, and
the lu routine. The following is a short introduction to Unix users of the C interface of UMFPACK.
The C-callable UMFPACK library consists of 32 user-callable routines and one include file.
Twenty-eight of the routines come in four versions, with different sizes of integers and for real
or complex floating-point numbers. This Quick Start Guide assumes you are working with real
matrices (not complex) and with int’s as integers (not long’s). Refer to the User Guide for
information about the complex and long integer versions. The include file umfpack.h must be
included in any C program that uses UMFPACK.
For more details, see: A column pre-ordering strategy for the unsymmetric-pattern multifrontal
method, Davis, T. A., ACM Trans. Math. Software, vol 30. no 2, 2004, pp. 165-195, and Algorithm
832: UMFPACK, an unsymmetric-pattern multifrontal method, same issue, pp. 196-199.
1
sparse matrices, getting the LU factors, save and loading the LU factors from a file, computing the
determinant, and reporting results. See the User Guide for more information.
• umfpack di symbolic:
Pre-orders the columns of A to reduce fill-in and performs a symbolic analysis. Returns an
opaque Symbolic object as a void * pointer. The object contains the symbolic analysis and
is needed for the numerical factorization.
• umfpack di numeric:
Numerically scales and then factorizes a sparse matrix PAQ, PRAQ, or PR−1 AQ into the
product LU, where P and Q are permutation matrices, R is a diagonal matrix of scale factors,
L is lower triangular with unit diagonal, and U is upper triangular. Requires the symbolic
ordering and analysis computed by umfpack di symbolic. Returns an opaque Numeric ob-
ject as a void * pointer. The object contains the numerical factorization and is used by
umfpack di solve.
• umfpack di solve:
Solves a sparse linear system (Ax = b, AT x = b, or systems involving just L or U), using
the numeric factorization computed by umfpack di numeric.
The matrix A is represented in compressed column form, which is identical to the sparse matrix
representation used by MATLAB. It consists of three arrays, where the matrix is m-by-n, with nz
entries:
int Ap [n+1] ;
int Ai [nz] ;
double Ax [nz] ;
All nonzeros are entries, but an entry may be numerically zero. The row indices of entries in
column j are stored in Ai[Ap[j] ... Ap[j+1]-1]. The corresponding numerical values are stored
in Ax[Ap[j] ... Ap[j+1]-1].
No duplicate row indices may be present, and the row indices in any given column must be
sorted in ascending order. The first entry Ap[0] must be zero. The total number of entries in the
matrix is thus nz = Ap[n]. Except for the fact that extra zero entries can be included, there is
thus a unique compressed column representation of any given matrix A.
Here is a simple main program, umfpack simple.c, that illustrates the basic usage of UMF-
PACK.
#include <stdio.h>
#include "umfpack.h"
2
int n = 5 ;
int Ap [ ] = {0, 2, 5, 9, 10, 12} ;
int Ai [ ] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4} ;
double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ;
double b [ ] = {8., 45., -3., 3., 19.} ;
double x [5] ;
and the solution is x = [1 2 3 4 5]T . The program uses default control settings and does not return
any statistics about the ordering, factorization, or solution (Control and Info are both (double
*) NULL).
For routines to manipulate a simpler “triplet-form” data structure for your sparse matrix A,
refer to the UMFPACK User Guide.
umfpack_di_defaults (Control) ;
status = umfpack_di_symbolic (m, n, Ap, Ai, Ax, &Symbolic, Control, Info) ;
status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, Control, Info) ;
status = umfpack_di_solve (sys, Ap, Ai, Ax, X, B, Numeric, Control, Info) ;
umfpack_di_free_symbolic (&Symbolic) ;
umfpack_di_free_numeric (&Numeric) ;
3
4 Installation
You will need to install both UMFPACK and AMD to use UMFPACK. The UMFPACK and AMD
subdirectories must be placed side-by-side within the same parent directory. AMD is a stand-alone
package that is required by UMFPACK. UMFPACK can be compiled without the BLAS but your
performance will be much less than what it should be.
UMFPACK also requires CHOLMOD, CCAMD, CCOLAMD, COLAMD, and metis-5.1.0 by de-
fault. You can remove this dependency by compiling with -DNCHOLMOD. Add this to the UMFPACK CONFIG
definition in SuiteSparse config/SuiteSparse config.mk.
System-dependent configurations are in the SuiteSparse config/SuiteSparse config.mk file.
The default settings will work on most systems, except perhaps for the BLAS definition. Sample
configurations are provided for Linux, Mac, Sun Solaris, and IBM AIX. The Makefile file will
automatically detect what system you have and will set the compile parameters accordingly.
To compile both packages, go to the UMFPACK directory and type make. This will compile
the static libraries (AMD/Lib/libamd.* and UMFPACK/Lib/libumfpack.*). A demo of the AMD
ordering routine will be compiled and tested in the AMD/Demo directory, and five demo programs will
then be compiled and tested in the UMFPACK/Demo directory. The outputs of these demo programs
will then be compared with output files in the distribution. Expect to see a few differences, such
as residual norms, compile-time control settings, and perhaps memory usage differences.
To install into /usr/local/lib and /usr/local/include, do make install. To uninstall from there,
do make uninstall. For more options, see the SuiteSparse/README.txt file.
Use the MATLAB command umfpack make in the MATLAB directory to compile UMFPACK
and AMD for use in MATLAB.
If you compile UMFPACK and AMD and then later change the SuiteSparse config/SuiteSparse config.mk
file then you should type make purge and then make to recompile.
Here are a few of the various parameters that you can control in your SuiteSparse config/SuiteSparse config
file. To list them all, do make config.
• UMFPACK CONFIG = configuration settings for the BLAS, memory allocation routines, and
timing routines.
4
The UMFPACK CONFIG string can include combinations of the following; most deal with how the
BLAS are called:
• -DNSUNPERF if you are on Solaris but do not have the Sun Performance Library.
• -DBLAS NO UNDERSCORE for controlling how C calls the Fortran BLAS. This is set automati-
cally for Windows, Sun Solaris, SGI Irix, Red Hat Linux, Compaq Alpha, and AIX (the IBM
RS 6000).
• -DNRECIPROCAL controls a trade-off between speed and accuracy. This is off by default (speed
preferred over accuracy) except when compiling for MATLAB.
When you compile your program that uses the C-callable UMFPACK library, you need to
link your program with all libraries: -lumfpack -lamd -lcholmod -lcolamd -lccolamd -lcamd -
lmetis. If you don’t compile UMFPACK to use METIS, then you can All libraries are placed
in SuiteSparse/lib and all include files are placed in SuiteSparse/include.
You do not need to directly include any AMD include files in your program, unless you directly
call AMD routines. You only need the
#include "umfpack.h"
5
5 The primary UMFPACK routines
5.1 umfpack di symbolic
int umfpack_di_symbolic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
) ;
Purpose:
Returns:
Arguments:
6
must be in ascending order, and no duplicate row indices may be present.
Row indices must be in the range 0 to n_row-1 (the matrix is 0-based).
The numerical values of the sparse matrix A. The nonzero pattern (row
indices) for column j is stored in Ai [(Ap [j]) ... (Ap [j+1]-1)], and
the corresponding numerical values are stored in
Ax [(Ap [j]) ... (Ap [j+1]-1)]. Used only by the 2-by-2 strategy to
determine whether entries are "large" or "small". You do not have to
pass the same numerical values to umfpack_di_numeric. If Ax is not
present (a (double *) NULL pointer), then any entry in A is assumed to
be "large".
7
diagonal pivoting during numerical factorization. No refinement
of the column preordering is performed during factorization.
UMFPACK_OK
UMFPACK_ERROR_n_nonpositive
UMFPACK_ERROR_invalid_matrix
UMFPACK_ERROR_out_of_memory
UMFPACK_ERROR_argument_missing
8
UMFPACK_ERROR_internal_error
9
Info [UMFPACK_SYMBOLIC_TIME]: The CPU time taken, in seconds.
10
5.2 umfpack di numeric
int umfpack_di_numeric
(
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void *Symbolic,
void **Numeric,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
) ;
Purpose:
Returns:
Arguments:
The numerical values of the sparse matrix A. The nonzero pattern (row
indices) for column j is stored in Ai [(Ap [j]) ... (Ap [j+1]-1)], and
the corresponding numerical values are stored in
Ax [(Ap [j]) ... (Ap [j+1]-1)].
11
void **Numeric ; Output argument.
i j
i: 0 x
j: x 0
12
j i
i: x 0
j: 0 x
There are three valid settings for this parameter. If any other
value is provided, the default is used.
Default: UMFPACK_SCALE_SUM.
UMFPACK_OK
UMFPACK_WARNING_singular_matrix
UMFPACK_ERROR_out_of_memory
13
Insufficient memory to complete the numeric factorization.
UMFPACK_ERROR_argument_missing
UMFPACK_ERROR_invalid_Symbolic_object
UMFPACK_ERROR_different_pattern
The pattern (Ap and/or Ai) has changed since the call to
umfpack_di_symbolic which produced the Symbolic object.
14
Info [UMFPACK_NUMERIC_TIME]: The CPU time taken, in seconds.
15
5.3 umfpack di solve
int umfpack_di_solve
(
int sys,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
double X [ ],
const double B [ ],
void *Numeric,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
) ;
Purpose:
Returns:
Arguments:
UMFPACK_A Ax=b
UMFPACK_At A’x=b
UMFPACK_Pt_L P’Lx=b
UMFPACK_L Lx=b
UMFPACK_Lt_P L’Px=b
UMFPACK_Lt L’x=b
UMFPACK_U_Qt UQ’x=b
UMFPACK_U Ux=b
UMFPACK_Q_Ut QU’x=b
UMFPACK_Ut U’x=b
UMFPACK_A Ax=b
UMFPACK_At A’x=b
16
For the other values of the sys argument, iterative refinement is not
performed (Control [UMFPACK_IRSTEP], Ap, Ai, and Ax are ignored).
17
UMFPACK_OK
UMFPACK_WARNING_singular_matrix
A = [2 0] b = [ 1 ] returns x = [ 0.5 ]
[0 0] [ 0 ] [ Inf ]
UMFPACK_ERROR_out_of_memory
UMFPACK_ERROR_argument_missing
UMFPACK_ERROR_invalid_system
UMFPACK_ERROR_invalid_Numeric_object
18
5.4 umfpack di free symbolic
void umfpack_di_free_symbolic
(
void **Symbolic
) ;
Purpose:
Deallocates the Symbolic object and sets the Symbolic handle to NULL.
Arguments:
Purpose:
Deallocates the Numeric object and sets the Numeric handle to NULL.
Arguments:
Purpose:
Arguments:
19