|
kusano |
7d535a |
/*! @file superlu.c
|
|
kusano |
7d535a |
* \brief a small 5x5 example
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* * -- SuperLU routine (version 2.0) --
|
|
kusano |
7d535a |
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
|
|
kusano |
7d535a |
* and Lawrence Berkeley National Lab.
|
|
kusano |
7d535a |
* November 15, 1997
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#include "slu_ddefs.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
main(int argc, char *argv[])
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Purpose
|
|
kusano |
7d535a |
* =======
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* This is the small 5x5 example used in the Sections 2 and 3 of the
|
|
kusano |
7d535a |
* Users' Guide to illustrate how to call a SuperLU routine, and the
|
|
kusano |
7d535a |
* matrix data structures used by SuperLU.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
SuperMatrix A, L, U, B;
|
|
kusano |
7d535a |
double *a, *rhs;
|
|
kusano |
7d535a |
double s, u, p, e, r, l;
|
|
kusano |
7d535a |
int *asub, *xa;
|
|
kusano |
7d535a |
int *perm_r; /* row permutations from partial pivoting */
|
|
kusano |
7d535a |
int *perm_c; /* column permutation vector */
|
|
kusano |
7d535a |
int nrhs, info, i, m, n, nnz, permc_spec;
|
|
kusano |
7d535a |
superlu_options_t options;
|
|
kusano |
7d535a |
SuperLUStat_t stat;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Initialize matrix A. */
|
|
kusano |
7d535a |
m = n = 5;
|
|
kusano |
7d535a |
nnz = 12;
|
|
kusano |
7d535a |
if ( !(a = doubleMalloc(nnz)) ) ABORT("Malloc fails for a[].");
|
|
kusano |
7d535a |
if ( !(asub = intMalloc(nnz)) ) ABORT("Malloc fails for asub[].");
|
|
kusano |
7d535a |
if ( !(xa = intMalloc(n+1)) ) ABORT("Malloc fails for xa[].");
|
|
kusano |
7d535a |
s = 19.0; u = 21.0; p = 16.0; e = 5.0; r = 18.0; l = 12.0;
|
|
kusano |
7d535a |
a[0] = s; a[1] = l; a[2] = l; a[3] = u; a[4] = l; a[5] = l;
|
|
kusano |
7d535a |
a[6] = u; a[7] = p; a[8] = u; a[9] = e; a[10]= u; a[11]= r;
|
|
kusano |
7d535a |
asub[0] = 0; asub[1] = 1; asub[2] = 4; asub[3] = 1;
|
|
kusano |
7d535a |
asub[4] = 2; asub[5] = 4; asub[6] = 0; asub[7] = 2;
|
|
kusano |
7d535a |
asub[8] = 0; asub[9] = 3; asub[10]= 3; asub[11]= 4;
|
|
kusano |
7d535a |
xa[0] = 0; xa[1] = 3; xa[2] = 6; xa[3] = 8; xa[4] = 10; xa[5] = 12;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Create matrix A in the format expected by SuperLU. */
|
|
kusano |
7d535a |
dCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Create right-hand side matrix B. */
|
|
kusano |
7d535a |
nrhs = 1;
|
|
kusano |
7d535a |
if ( !(rhs = doubleMalloc(m * nrhs)) ) ABORT("Malloc fails for rhs[].");
|
|
kusano |
7d535a |
for (i = 0; i < m; ++i) rhs[i] = 1.0;
|
|
kusano |
7d535a |
dCreate_Dense_Matrix(&B, m, nrhs, rhs, m, SLU_DN, SLU_D, SLU_GE);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[].");
|
|
kusano |
7d535a |
if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[].");
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Set the default input options. */
|
|
kusano |
7d535a |
set_default_options(&options);
|
|
kusano |
7d535a |
options.ColPerm = NATURAL;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Initialize the statistics variables. */
|
|
kusano |
7d535a |
StatInit(&stat);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Solve the linear system. */
|
|
kusano |
7d535a |
dgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
dPrint_CompCol_Matrix("A", &A);
|
|
kusano |
7d535a |
dPrint_CompCol_Matrix("U", &U);
|
|
kusano |
7d535a |
dPrint_SuperNode_Matrix("L", &L);
|
|
kusano |
7d535a |
print_int_vec("\nperm_r", m, perm_r);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* De-allocate storage */
|
|
kusano |
7d535a |
SUPERLU_FREE (rhs);
|
|
kusano |
7d535a |
SUPERLU_FREE (perm_r);
|
|
kusano |
7d535a |
SUPERLU_FREE (perm_c);
|
|
kusano |
7d535a |
Destroy_CompCol_Matrix(&A);
|
|
kusano |
7d535a |
Destroy_SuperMatrix_Store(&B);
|
|
kusano |
7d535a |
Destroy_SuperNode_Matrix(&L);
|
|
kusano |
7d535a |
Destroy_CompCol_Matrix(&U);
|
|
kusano |
7d535a |
StatFree(&stat);
|
|
kusano |
7d535a |
}
|