Blender V2.61 - r43446

sgssv.c

Go to the documentation of this file.
00001 
00006 /*
00007  * -- SuperLU routine (version 3.0) --
00008  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
00009  * and Lawrence Berkeley National Lab.
00010  * October 15, 2003
00011  *
00012  */
00013 #include "ssp_defs.h"
00014 
00015 void
00016 sgssv(superlu_options_t *options, SuperMatrix *A, int *perm_c, int *perm_r,
00017       SuperMatrix *L, SuperMatrix *U, SuperMatrix *B,
00018       SuperLUStat_t *stat, int *info )
00019 {
00020 /*
00021  * Purpose
00022  * =======
00023  *
00024  * SGSSV solves the system of linear equations A*X=B, using the
00025  * LU factorization from SGSTRF. It performs the following steps:
00026  *
00027  *   1. If A is stored column-wise (A->Stype = SLU_NC):
00028  *
00029  *      1.1. Permute the columns of A, forming A*Pc, where Pc
00030  *           is a permutation matrix. For more details of this step, 
00031  *           see sp_preorder.c.
00032  *
00033  *      1.2. Factor A as Pr*A*Pc=L*U with the permutation Pr determined
00034  *           by Gaussian elimination with partial pivoting.
00035  *           L is unit lower triangular with offdiagonal entries
00036  *           bounded by 1 in magnitude, and U is upper triangular.
00037  *
00038  *      1.3. Solve the system of equations A*X=B using the factored
00039  *           form of A.
00040  *
00041  *   2. If A is stored row-wise (A->Stype = SLU_NR), apply the
00042  *      above algorithm to the transpose of A:
00043  *
00044  *      2.1. Permute columns of transpose(A) (rows of A),
00045  *           forming transpose(A)*Pc, where Pc is a permutation matrix. 
00046  *           For more details of this step, see sp_preorder.c.
00047  *
00048  *      2.2. Factor A as Pr*transpose(A)*Pc=L*U with the permutation Pr
00049  *           determined by Gaussian elimination with partial pivoting.
00050  *           L is unit lower triangular with offdiagonal entries
00051  *           bounded by 1 in magnitude, and U is upper triangular.
00052  *
00053  *      2.3. Solve the system of equations A*X=B using the factored
00054  *           form of A.
00055  *
00056  *   See supermatrix.h for the definition of 'SuperMatrix' structure.
00057  * 
00058  * Arguments
00059  * =========
00060  *
00061  * options (input) superlu_options_t*
00062  *         The structure defines the input parameters to control
00063  *         how the LU decomposition will be performed and how the
00064  *         system will be solved.
00065  *
00066  * A       (input) SuperMatrix*
00067  *         Matrix A in A*X=B, of dimension (A->nrow, A->ncol). The number
00068  *         of linear equations is A->nrow. Currently, the type of A can be:
00069  *         Stype = SLU_NC or SLU_NR; Dtype = SLU_S; Mtype = SLU_GE.
00070  *         In the future, more general A may be handled.
00071  *
00072  * perm_c  (input/output) int*
00073  *         If A->Stype = SLU_NC, column permutation vector of size A->ncol
00074  *         which defines the permutation matrix Pc; perm_c[i] = j means 
00075  *         column i of A is in position j in A*Pc.
00076  *         If A->Stype = SLU_NR, column permutation vector of size A->nrow
00077  *         which describes permutation of columns of transpose(A) 
00078  *         (rows of A) as described above.
00079  * 
00080  *         If options->ColPerm = MY_PERMC or options->Fact = SamePattern or
00081  *            options->Fact = SamePattern_SameRowPerm, it is an input argument.
00082  *            On exit, perm_c may be overwritten by the product of the input
00083  *            perm_c and a permutation that postorders the elimination tree
00084  *            of Pc'*A'*A*Pc; perm_c is not changed if the elimination tree
00085  *            is already in postorder.
00086  *         Otherwise, it is an output argument.
00087  * 
00088  * perm_r  (input/output) int*
00089  *         If A->Stype = SLU_NC, row permutation vector of size A->nrow, 
00090  *         which defines the permutation matrix Pr, and is determined 
00091  *         by partial pivoting.  perm_r[i] = j means row i of A is in 
00092  *         position j in Pr*A.
00093  *         If A->Stype = SLU_NR, permutation vector of size A->ncol, which
00094  *         determines permutation of rows of transpose(A)
00095  *         (columns of A) as described above.
00096  *
00097  *         If options->RowPerm = MY_PERMR or
00098  *            options->Fact = SamePattern_SameRowPerm, perm_r is an
00099  *            input argument.
00100  *         otherwise it is an output argument.
00101  *
00102  * L       (output) SuperMatrix*
00103  *         The factor L from the factorization 
00104  *             Pr*A*Pc=L*U              (if A->Stype = SLU_NC) or
00105  *             Pr*transpose(A)*Pc=L*U   (if A->Stype = SLU_NR).
00106  *         Uses compressed row subscripts storage for supernodes, i.e.,
00107  *         L has types: Stype = SLU_SC, Dtype = SLU_S, Mtype = SLU_TRLU.
00108  *         
00109  * U       (output) SuperMatrix*
00110  *     The factor U from the factorization 
00111  *             Pr*A*Pc=L*U              (if A->Stype = SLU_NC) or
00112  *             Pr*transpose(A)*Pc=L*U   (if A->Stype = SLU_NR).
00113  *         Uses column-wise storage scheme, i.e., U has types:
00114  *         Stype = SLU_NC, Dtype = SLU_S, Mtype = SLU_TRU.
00115  *
00116  * B       (input/output) SuperMatrix*
00117  *         B has types: Stype = SLU_DN, Dtype = SLU_S, Mtype = SLU_GE.
00118  *         On entry, the right hand side matrix.
00119  *         On exit, the solution matrix if info = 0;
00120  *
00121  * stat   (output) SuperLUStat_t*
00122  *        Record the statistics on runtime and floating-point operation count.
00123  *        See util.h for the definition of 'SuperLUStat_t'.
00124  *
00125  * info    (output) int*
00126  *     = 0: successful exit
00127  *         > 0: if info = i, and i is
00128  *             <= A->ncol: U(i,i) is exactly zero. The factorization has
00129  *                been completed, but the factor U is exactly singular,
00130  *                so the solution could not be computed.
00131  *             > A->ncol: number of bytes allocated when memory allocation
00132  *                failure occurred, plus A->ncol.
00133  *   
00134  */
00135     DNformat *Bstore;
00136     SuperMatrix *AA = NULL;/* A in SLU_NC format used by the factorization routine.*/
00137     SuperMatrix AC; /* Matrix postmultiplied by Pc */
00138     int      lwork = 0, *etree, i;
00139     
00140     /* Set default values for some parameters */
00141     int      panel_size;     /* panel size */
00142     int      relax;          /* no of columns in a relaxed snodes */
00143     int      permc_spec;
00144     trans_t  trans = NOTRANS;
00145     double   *utime;
00146     double   t; /* Temporary time */
00147 
00148     /* Test the input parameters ... */
00149     *info = 0;
00150     Bstore = B->Store;
00151     if ( options->Fact != DOFACT ) *info = -1;
00152     else if ( A->nrow != A->ncol || A->nrow < 0 ||
00153      (A->Stype != SLU_NC && A->Stype != SLU_NR) ||
00154      A->Dtype != SLU_S || A->Mtype != SLU_GE )
00155     *info = -2;
00156     else if ( B->ncol < 0 || Bstore->lda < SUPERLU_MAX(0, A->nrow) ||
00157     B->Stype != SLU_DN || B->Dtype != SLU_S || B->Mtype != SLU_GE )
00158     *info = -7;
00159     if ( *info != 0 ) {
00160     i = -(*info);
00161     xerbla_("sgssv", &i);
00162     return;
00163     }
00164 
00165     utime = stat->utime;
00166 
00167     /* Convert A to SLU_NC format when necessary. */
00168     if ( A->Stype == SLU_NR ) {
00169     NRformat *Astore = A->Store;
00170     AA = (SuperMatrix *) SUPERLU_MALLOC( sizeof(SuperMatrix) );
00171     sCreate_CompCol_Matrix(AA, A->ncol, A->nrow, Astore->nnz, 
00172                    Astore->nzval, Astore->colind, Astore->rowptr,
00173                    SLU_NC, A->Dtype, A->Mtype);
00174     trans = TRANS;
00175     } else {
00176         if ( A->Stype == SLU_NC ) AA = A;
00177     }
00178 
00179     t = SuperLU_timer_();
00180     /*
00181      * Get column permutation vector perm_c[], according to permc_spec:
00182      *   permc_spec = NATURAL:  natural ordering 
00183      *   permc_spec = MMD_AT_PLUS_A: minimum degree on structure of A'+A
00184      *   permc_spec = MMD_ATA:  minimum degree on structure of A'*A
00185      *   permc_spec = COLAMD:   approximate minimum degree column ordering
00186      *   permc_spec = MY_PERMC: the ordering already supplied in perm_c[]
00187      */
00188     permc_spec = options->ColPerm;
00189     if ( permc_spec != MY_PERMC && options->Fact == DOFACT )
00190       get_perm_c(permc_spec, AA, perm_c);
00191     utime[COLPERM] = SuperLU_timer_() - t;
00192 
00193     etree = intMalloc(A->ncol);
00194 
00195     t = SuperLU_timer_();
00196     sp_preorder(options, AA, perm_c, etree, &AC);
00197     utime[ETREE] = SuperLU_timer_() - t;
00198 
00199     panel_size = sp_ienv(1);
00200     relax = sp_ienv(2);
00201 
00202     /*printf("Factor PA = LU ... relax %d\tw %d\tmaxsuper %d\trowblk %d\n", 
00203       relax, panel_size, sp_ienv(3), sp_ienv(4));*/
00204     t = SuperLU_timer_(); 
00205     /* Compute the LU factorization of A. */
00206     sgstrf(options, &AC, relax, panel_size,
00207        etree, NULL, lwork, perm_c, perm_r, L, U, stat, info);
00208     utime[FACT] = SuperLU_timer_() - t;
00209 
00210     t = SuperLU_timer_();
00211     if ( *info == 0 ) {
00212         /* Solve the system A*X=B, overwriting B with X. */
00213         sgstrs (trans, L, U, perm_c, perm_r, B, stat, info);
00214     }
00215     utime[SOLVE] = SuperLU_timer_() - t;
00216 
00217     SUPERLU_FREE (etree);
00218     Destroy_CompCol_Permuted(&AC);
00219     if ( A->Stype == SLU_NR ) {
00220     Destroy_SuperMatrix_Store(AA);
00221     SUPERLU_FREE(AA);
00222     }
00223 
00224 }