⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgssvx.c

📁 SuperLU is a general purpose library for the direct solution of large, sparse, nonsymmetric systems
💻 C
📖 第 1 页 / 共 2 页
字号:
 * stat   (output) SuperLUStat_t* *        Record the statistics on runtime and floating-point operation count. *        See util.h for the definition of 'SuperLUStat_t'. * * info    (output) int* *         = 0: successful exit    *         < 0: if info = -i, the i-th argument had an illegal value    *         > 0: if info = i, and i is    *              <= A->ncol: U(i,i) is exactly zero. The factorization has    *                    been completed, but the factor U is exactly    *                    singular, so the solution and error bounds    *                    could not be computed.    *              = A->ncol+1: U is nonsingular, but RCOND is less than machine *                    precision, meaning that the matrix is singular to *                    working precision. Nevertheless, the solution and *                    error bounds are computed because there are a number *                    of situations where the computed solution can be more *                    accurate than the value of RCOND would suggest.    *              > A->ncol+1: number of bytes allocated when memory allocation *                    failure occurred, plus A->ncol. * </pre> */voidsgssvx(superlu_options_t *options, SuperMatrix *A, int *perm_c, int *perm_r,       int *etree, char *equed, float *R, float *C,       SuperMatrix *L, SuperMatrix *U, void *work, int lwork,       SuperMatrix *B, SuperMatrix *X, float *recip_pivot_growth,        float *rcond, float *ferr, float *berr,        mem_usage_t *mem_usage, SuperLUStat_t *stat, int *info ){    DNformat  *Bstore, *Xstore;    float    *Bmat, *Xmat;    int       ldb, ldx, nrhs;    SuperMatrix *AA;/* A in SLU_NC format used by the factorization routine.*/    SuperMatrix AC; /* Matrix postmultiplied by Pc */    int       colequ, equil, nofact, notran, rowequ, permc_spec;    trans_t   trant;    char      norm[1];    int       i, j, info1;    float    amax, anorm, bignum, smlnum, colcnd, rowcnd, rcmax, rcmin;    int       relax, panel_size;    float    diag_pivot_thresh, drop_tol;    double    t0;      /* temporary time */    double    *utime;    /* External functions */    extern float slangs(char *, SuperMatrix *);    extern double slamch_(char *);    Bstore = B->Store;    Xstore = X->Store;    Bmat   = Bstore->nzval;    Xmat   = Xstore->nzval;    ldb    = Bstore->lda;    ldx    = Xstore->lda;    nrhs   = B->ncol;    *info = 0;    nofact = (options->Fact != FACTORED);    equil = (options->Equil == YES);    notran = (options->Trans == NOTRANS);    if ( nofact ) {	*(unsigned char *)equed = 'N';	rowequ = FALSE;	colequ = FALSE;    } else {	rowequ = lsame_(equed, "R") || lsame_(equed, "B");	colequ = lsame_(equed, "C") || lsame_(equed, "B");	smlnum = slamch_("Safe minimum");	bignum = 1. / smlnum;    }#if 0printf("dgssvx: Fact=%4d, Trans=%4d, equed=%c\n",       options->Fact, options->Trans, *equed);#endif    /* Test the input parameters */    if (!nofact && options->Fact != DOFACT && options->Fact != SamePattern &&	options->Fact != SamePattern_SameRowPerm &&	!notran && options->Trans != TRANS && options->Trans != CONJ &&	!equil && options->Equil != NO)	*info = -1;    else if ( A->nrow != A->ncol || A->nrow < 0 ||	      (A->Stype != SLU_NC && A->Stype != SLU_NR) ||	      A->Dtype != SLU_S || A->Mtype != SLU_GE )	*info = -2;    else if (options->Fact == FACTORED &&	     !(rowequ || colequ || lsame_(equed, "N")))	*info = -6;    else {	if (rowequ) {	    rcmin = bignum;	    rcmax = 0.;	    for (j = 0; j < A->nrow; ++j) {		rcmin = SUPERLU_MIN(rcmin, R[j]);		rcmax = SUPERLU_MAX(rcmax, R[j]);	    }	    if (rcmin <= 0.) *info = -7;	    else if ( A->nrow > 0)		rowcnd = SUPERLU_MAX(rcmin,smlnum) / SUPERLU_MIN(rcmax,bignum);	    else rowcnd = 1.;	}	if (colequ && *info == 0) {	    rcmin = bignum;	    rcmax = 0.;	    for (j = 0; j < A->nrow; ++j) {		rcmin = SUPERLU_MIN(rcmin, C[j]);		rcmax = SUPERLU_MAX(rcmax, C[j]);	    }	    if (rcmin <= 0.) *info = -8;	    else if (A->nrow > 0)		colcnd = SUPERLU_MAX(rcmin,smlnum) / SUPERLU_MIN(rcmax,bignum);	    else colcnd = 1.;	}	if (*info == 0) {	    if ( lwork < -1 ) *info = -12;	    else if ( B->ncol < 0 || Bstore->lda < SUPERLU_MAX(0, A->nrow) ||		      B->Stype != SLU_DN || B->Dtype != SLU_S || 		      B->Mtype != SLU_GE )		*info = -13;	    else if ( X->ncol < 0 || Xstore->lda < SUPERLU_MAX(0, A->nrow) ||		      (B->ncol != 0 && B->ncol != X->ncol) ||                      X->Stype != SLU_DN ||		      X->Dtype != SLU_S || X->Mtype != SLU_GE )		*info = -14;	}    }    if (*info != 0) {	i = -(*info);	xerbla_("sgssvx", &i);	return;    }        /* Initialization for factor parameters */    panel_size = sp_ienv(1);    relax      = sp_ienv(2);    diag_pivot_thresh = options->DiagPivotThresh;    drop_tol   = 0.0;    utime = stat->utime;        /* Convert A to SLU_NC format when necessary. */    if ( A->Stype == SLU_NR ) {	NRformat *Astore = A->Store;	AA = (SuperMatrix *) SUPERLU_MALLOC( sizeof(SuperMatrix) );	sCreate_CompCol_Matrix(AA, A->ncol, A->nrow, Astore->nnz, 			       Astore->nzval, Astore->colind, Astore->rowptr,			       SLU_NC, A->Dtype, A->Mtype);	if ( notran ) { /* Reverse the transpose argument. */	    trant = TRANS;	    notran = 0;	} else {	    trant = NOTRANS;	    notran = 1;	}    } else { /* A->Stype == SLU_NC */	trant = options->Trans;	AA = A;    }    if ( nofact && equil ) {	t0 = SuperLU_timer_();	/* Compute row and column scalings to equilibrate the matrix A. */	sgsequ(AA, R, C, &rowcnd, &colcnd, &amax, &info1);		if ( info1 == 0 ) {	    /* Equilibrate matrix A. */	    slaqgs(AA, R, C, rowcnd, colcnd, amax, equed);	    rowequ = lsame_(equed, "R") || lsame_(equed, "B");	    colequ = lsame_(equed, "C") || lsame_(equed, "B");	}	utime[EQUIL] = SuperLU_timer_() - t0;    }    if ( nrhs > 0 ) {        /* Scale the right hand side if equilibration was performed. */        if ( notran ) {	    if ( rowequ ) {	        for (j = 0; j < nrhs; ++j)		    for (i = 0; i < A->nrow; ++i) {		        Bmat[i + j*ldb] *= R[i];	            }	    }        } else if ( colequ ) {	    for (j = 0; j < nrhs; ++j)	        for (i = 0; i < A->nrow; ++i) {	            Bmat[i + j*ldb] *= C[i];	        }        }    }    if ( nofact ) {	        t0 = SuperLU_timer_();	/*	 * Gnet column permutation vector perm_c[], according to permc_spec:	 *   permc_spec = NATURAL:  natural ordering 	 *   permc_spec = MMD_AT_PLUS_A: minimum degree on structure of A'+A	 *   permc_spec = MMD_ATA:  minimum degree on structure of A'*A	 *   permc_spec = COLAMD:   approximate minimum degree column ordering	 *   permc_spec = MY_PERMC: the ordering already supplied in perm_c[]	 */	permc_spec = options->ColPerm;	if ( permc_spec != MY_PERMC && options->Fact == DOFACT )            get_perm_c(permc_spec, AA, perm_c);	utime[COLPERM] = SuperLU_timer_() - t0;	t0 = SuperLU_timer_();	sp_preorder(options, AA, perm_c, etree, &AC);	utime[ETREE] = SuperLU_timer_() - t0;    /*	printf("Factor PA = LU ... relax %d\tw %d\tmaxsuper %d\trowblk %d\n", 	       relax, panel_size, sp_ienv(3), sp_ienv(4));	fflush(stdout); */		/* Compute the LU factorization of A*Pc. */	t0 = SuperLU_timer_();	sgstrf(options, &AC, drop_tol, relax, panel_size,	       etree, work, lwork, perm_c, perm_r, L, U, stat, info);	utime[FACT] = SuperLU_timer_() - t0;		if ( lwork == -1 ) {	    mem_usage->total_needed = *info - A->ncol;	    return;	}    }    if ( options->PivotGrowth ) {        if ( *info > 0 ) {	    if ( *info <= A->ncol ) {	        /* Compute the reciprocal pivot growth factor of the leading	           rank-deficient *info columns of A. */	        *recip_pivot_growth = sPivotGrowth(*info, AA, perm_c, L, U);	    }	    return;        }        /* Compute the reciprocal pivot growth factor *recip_pivot_growth. */        *recip_pivot_growth = sPivotGrowth(A->ncol, AA, perm_c, L, U);    }    if ( options->ConditionNumber ) {        /* Estimate the reciprocal of the condition number of A. */        t0 = SuperLU_timer_();        if ( notran ) {	    *(unsigned char *)norm = '1';        } else {	    *(unsigned char *)norm = 'I';        }        anorm = slangs(norm, AA);        sgscon(norm, L, U, anorm, rcond, stat, info);        utime[RCOND] = SuperLU_timer_() - t0;    }        if ( nrhs > 0 ) {        /* Compute the solution matrix X. */        for (j = 0; j < nrhs; j++)  /* Save a copy of the right hand sides */            for (i = 0; i < B->nrow; i++)	        Xmat[i + j*ldx] = Bmat[i + j*ldb];            t0 = SuperLU_timer_();        sgstrs (trant, L, U, perm_c, perm_r, X, stat, info);        utime[SOLVE] = SuperLU_timer_() - t0;            /* Use iterative refinement to improve the computed solution and compute           error bounds and backward error estimates for it. */        t0 = SuperLU_timer_();        if ( options->IterRefine != NOREFINE ) {            sgsrfs(trant, AA, L, U, perm_c, perm_r, equed, R, C, B,                   X, ferr, berr, stat, info);        } else {            for (j = 0; j < nrhs; ++j) ferr[j] = berr[j] = 1.0;        }        utime[REFINE] = SuperLU_timer_() - t0;        /* Transform the solution matrix X to a solution of the original system. */        if ( notran ) {	    if ( colequ ) {	        for (j = 0; j < nrhs; ++j)		    for (i = 0; i < A->nrow; ++i) {                        Xmat[i + j*ldx] *= C[i];	            }	    }        } else if ( rowequ ) {	    for (j = 0; j < nrhs; ++j)	        for (i = 0; i < A->nrow; ++i) {	            Xmat[i + j*ldx] *= R[i];                }        }    } /* end if nrhs > 0 */    if ( options->ConditionNumber ) {        /* Set INFO = A->ncol+1 if the matrix is singular to working precision. */        if ( *rcond < slamch_("E") ) *info = A->ncol + 1;    }    if ( nofact ) {        sQuerySpace(L, U, mem_usage);        Destroy_CompCol_Permuted(&AC);    }    if ( A->Stype == SLU_NR ) {	Destroy_SuperMatrix_Store(AA);	SUPERLU_FREE(AA);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -