1 
2 /*
3  * -- SuperLU routine (version 3.0) --
4  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
5  * and Lawrence Berkeley National Lab.
6  * October 15, 2003
7  *
8  */
9 #include "slu_sdefs.h"
10 
main(int argc,char * argv[])11 main(int argc, char *argv[])
12 {
13     SuperMatrix A;
14     NCformat *Astore;
15     float   *a;
16     int      *asub, *xa;
17     int      *perm_c; /* column permutation vector */
18     int      *perm_r; /* row permutations from partial pivoting */
19     SuperMatrix L;      /* factor L */
20     SCformat *Lstore;
21     SuperMatrix U;      /* factor U */
22     NCformat *Ustore;
23     SuperMatrix B;
24     int      nrhs, ldx, info, m, n, nnz;
25     float   *xact, *rhs;
26     mem_usage_t   mem_usage;
27     superlu_options_t options;
28     SuperLUStat_t stat;
29 
30 #if ( DEBUGlevel>=1 )
31     CHECK_MALLOC("Enter main()");
32 #endif
33 
34     /* Set the default input options:
35 	options.Fact = DOFACT;
36         options.Equil = YES;
37     	options.ColPerm = COLAMD;
38 	options.DiagPivotThresh = 1.0;
39     	options.Trans = NOTRANS;
40     	options.IterRefine = NOREFINE;
41     	options.SymmetricMode = NO;
42     	options.PivotGrowth = NO;
43     	options.ConditionNumber = NO;
44     	options.PrintStat = YES;
45      */
46     set_default_options(&options);
47 
48     /* Read the matrix in Harwell-Boeing format. */
49     sreadhb(&m, &n, &nnz, &a, &asub, &xa);
50 
51     sCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_S, SLU_GE);
52     Astore = A.Store;
53     printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz);
54 
55     nrhs   = 1;
56     if ( !(rhs = floatMalloc(m * nrhs)) ) ABORT("Malloc fails for rhs[].");
57     sCreate_Dense_Matrix(&B, m, nrhs, rhs, m, SLU_DN, SLU_S, SLU_GE);
58     xact = floatMalloc(n * nrhs);
59     ldx = n;
60     sGenXtrue(n, nrhs, xact, ldx);
61     sFillRHS(options.Trans, nrhs, xact, ldx, &A, &B);
62 
63     if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[].");
64     if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[].");
65 
66     /* Initialize the statistics variables. */
67     StatInit(&stat);
68 
69     sgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info);
70 
71     if ( info == 0 ) {
72 
73 	/* This is how you could access the solution matrix. */
74         float *sol = (float*) ((DNformat*) B.Store)->nzval;
75 
76 	 /* Compute the infinity norm of the error. */
77 	sinf_norm_error(nrhs, &B, xact);
78 
79 	Lstore = (SCformat *) L.Store;
80 	Ustore = (NCformat *) U.Store;
81     	printf("No of nonzeros in factor L = %d\n", Lstore->nnz);
82     	printf("No of nonzeros in factor U = %d\n", Ustore->nnz);
83     	printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n);
84     	printf("FILL ratio = %.1f\n", (float)(Lstore->nnz + Ustore->nnz - n)/nnz);
85 
86 	sQuerySpace(&L, &U, &mem_usage);
87 	printf("L\\U MB %.3f\ttotal MB needed %.3f\n",
88 	       mem_usage.for_lu/1e6, mem_usage.total_needed/1e6);
89 
90     } else {
91 	printf("sgssv() error returns INFO= %d\n", info);
92 	if ( info <= n ) { /* factorization completes */
93 	    sQuerySpace(&L, &U, &mem_usage);
94 	    printf("L\\U MB %.3f\ttotal MB needed %.3f\n",
95 		   mem_usage.for_lu/1e6, mem_usage.total_needed/1e6);
96 	}
97     }
98 
99     if ( options.PrintStat ) StatPrint(&stat);
100     StatFree(&stat);
101 
102     SUPERLU_FREE (rhs);
103     SUPERLU_FREE (xact);
104     SUPERLU_FREE (perm_r);
105     SUPERLU_FREE (perm_c);
106     Destroy_CompCol_Matrix(&A);
107     Destroy_SuperMatrix_Store(&B);
108     Destroy_SuperNode_Matrix(&L);
109     Destroy_CompCol_Matrix(&U);
110 
111 #if ( DEBUGlevel>=1 )
112     CHECK_MALLOC("Exit main()");
113 #endif
114 }
115 
116