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

📄 zdrive.c

📁 SuperLU is a general purpose library for the direct solution of large, sparse, nonsymmetric systems
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * -- SuperLU routine (version 3.0) -- * Univ. of California Berkeley, Xerox Palo Alto Research Center, * and Lawrence Berkeley National Lab. * October 15, 2003 * *//* * File name:		zdrive.c * Purpose:             MAIN test program */#include <string.h>#include "slu_zdefs.h"#define NTESTS    5      /* Number of test types */#define NTYPES    11     /* Number of matrix types */#define NTRAN     2    #define THRESH    20.0#define FMT1      "%10s:n=%d, test(%d)=%12.5g\n"#define	FMT2      "%10s:fact=%4d, trans=%4d, equed=%c, n=%d, imat=%d, test(%d)=%12.5g\n"#define FMT3      "%10s:info=%d, izero=%d, n=%d, nrhs=%d, imat=%d, nfail=%d\n"static voidparse_command_line(int argc, char *argv[], char *matrix_type,		   int *n, int *w, int *relax, int *nrhs, int *maxsuper,		   int *rowblk, int *colblk, int *lwork, double *u);main(int argc, char *argv[]){/*  * Purpose * ======= * * ZDRIVE is the main test program for the DOUBLE COMPLEX linear  * equation driver routines ZGSSV and ZGSSVX. *  * The program is invoked by a shell script file -- ztest.csh. * The output from the tests are written into a file -- ztest.out. * * ===================================================================== */    doublecomplex         *a, *a_save;    int            *asub, *asub_save;    int            *xa, *xa_save;    SuperMatrix  A, B, X, L, U;    SuperMatrix  ASAV, AC;    mem_usage_t    mem_usage;    int            *perm_r; /* row permutation from partial pivoting */    int            *perm_c, *pc_save; /* column permutation */    int            *etree;    doublecomplex  zero = {0.0, 0.0};    double         *R, *C;    double         *ferr, *berr;    double         *rwork;    doublecomplex	   *wwork;    void           *work;    int            info, lwork, nrhs, panel_size, relax;    int            m, n, nnz;    doublecomplex         *xact;    doublecomplex         *rhsb, *solx, *bsav;    int            ldb, ldx;    double         rpg, rcond;    int            i, j, k1;    double         rowcnd, colcnd, amax;    int            maxsuper, rowblk, colblk;    int            prefact, nofact, equil, iequed;    int            nt, nrun, nfail, nerrs, imat, fimat, nimat;    int            nfact, ifact, itran;    int            kl, ku, mode, lda;    int            zerot, izero, ioff;    double         anorm, cndnum, u, drop_tol = 0.;    doublecomplex         *Afull;    double         result[NTESTS];    superlu_options_t options;    fact_t         fact;    trans_t        trans;    SuperLUStat_t  stat;    static char    matrix_type[8];    static char    equed[1], path[3], sym[1], dist[1];    /* Fixed set of parameters */    int            iseed[]  = {1988, 1989, 1990, 1991};    static char    equeds[]  = {'N', 'R', 'C', 'B'};    static fact_t  facts[] = {FACTORED, DOFACT, SamePattern,			      SamePattern_SameRowPerm};    static trans_t transs[]  = {NOTRANS, TRANS, CONJ};    /* Some function prototypes */     extern int zgst01(int, int, SuperMatrix *, SuperMatrix *, 		      SuperMatrix *, int *, int *, double *);    extern int zgst02(trans_t, int, int, int, SuperMatrix *, doublecomplex *,                      int, doublecomplex *, int, double *resid);    extern int zgst04(int, int, doublecomplex *, int,                       doublecomplex *, int, double rcond, double *resid);    extern int zgst07(trans_t, int, int, SuperMatrix *, doublecomplex *, int,                         doublecomplex *, int, doublecomplex *, int,                          double *, double *, double *);    extern int zlatb4_(char *, int *, int *, int *, char *, int *, int *, 	               double *, int *, double *, char *);    extern int zlatms_(int *, int *, char *, int *, char *, double *d,                       int *, double *, double *, int *, int *,                       char *, doublecomplex *, int *, doublecomplex *, int *);    extern int sp_zconvert(int, int, doublecomplex *, int, int, int,	                   doublecomplex *a, int *, int *, int *);    /* Executable statements */    strcpy(path, "ZGE");    nrun  = 0;    nfail = 0;    nerrs = 0;    /* Defaults */    lwork      = 0;    n          = 1;    nrhs       = 1;    panel_size = sp_ienv(1);    relax      = sp_ienv(2);    u          = 1.0;    strcpy(matrix_type, "LA");    parse_command_line(argc, argv, matrix_type, &n,		       &panel_size, &relax, &nrhs, &maxsuper,		       &rowblk, &colblk, &lwork, &u);    if ( lwork > 0 ) {	work = SUPERLU_MALLOC(lwork);	if ( !work ) {	    fprintf(stderr, "expert: cannot allocate %d bytes\n", lwork);	    exit (-1);	}    }    /* Set the default input options. */    set_default_options(&options);    options.DiagPivotThresh = u;    options.PrintStat = NO;    options.PivotGrowth = YES;    options.ConditionNumber = YES;    options.IterRefine = DOUBLE;        if ( strcmp(matrix_type, "LA") == 0 ) {	/* Test LAPACK matrix suite. */	m = n;	lda = SUPERLU_MAX(n, 1);	nnz = n * n;        /* upper bound */	fimat = 1;	nimat = NTYPES;	Afull = doublecomplexCalloc(lda * n);	zallocateA(n, nnz, &a, &asub, &xa);    } else {	/* Read a sparse matrix */	fimat = nimat = 0;	zreadhb(&m, &n, &nnz, &a, &asub, &xa);    }    zallocateA(n, nnz, &a_save, &asub_save, &xa_save);    rhsb = doublecomplexMalloc(m * nrhs);    bsav = doublecomplexMalloc(m * nrhs);    solx = doublecomplexMalloc(n * nrhs);    ldb  = m;    ldx  = n;    zCreate_Dense_Matrix(&B, m, nrhs, rhsb, ldb, SLU_DN, SLU_Z, SLU_GE);    zCreate_Dense_Matrix(&X, n, nrhs, solx, ldx, SLU_DN, SLU_Z, SLU_GE);    xact = doublecomplexMalloc(n * nrhs);    etree   = intMalloc(n);    perm_r  = intMalloc(n);    perm_c  = intMalloc(n);    pc_save = intMalloc(n);    R       = (double *) SUPERLU_MALLOC(m*sizeof(double));    C       = (double *) SUPERLU_MALLOC(n*sizeof(double));    ferr    = (double *) SUPERLU_MALLOC(nrhs*sizeof(double));    berr    = (double *) SUPERLU_MALLOC(nrhs*sizeof(double));    j = SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs);        rwork   = (double *) SUPERLU_MALLOC(j*sizeof(double));    for (i = 0; i < j; ++i) rwork[i] = 0.;    if ( !R ) ABORT("SUPERLU_MALLOC fails for R");    if ( !C ) ABORT("SUPERLU_MALLOC fails for C");    if ( !ferr ) ABORT("SUPERLU_MALLOC fails for ferr");    if ( !berr ) ABORT("SUPERLU_MALLOC fails for berr");    if ( !rwork ) ABORT("SUPERLU_MALLOC fails for rwork");    wwork   = doublecomplexCalloc( SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs) );    for (i = 0; i < n; ++i) perm_c[i] = pc_save[i] = i;    options.ColPerm = MY_PERMC;    for (imat = fimat; imat <= nimat; ++imat) { /* All matrix types */		if ( imat ) {	    /* Skip types 5, 6, or 7 if the matrix size is too small. */	    zerot = (imat >= 5 && imat <= 7);	    if ( zerot && n < imat-4 )		continue;	    	    /* Set up parameters with ZLATB4 and generate a test matrix	       with ZLATMS.  */	    zlatb4_(path, &imat, &n, &n, sym, &kl, &ku, &anorm, &mode,		    &cndnum, dist);	    zlatms_(&n, &n, dist, iseed, sym, &rwork[0], &mode, &cndnum,		    &anorm, &kl, &ku, "No packing", Afull, &lda,		    &wwork[0], &info);	    if ( info ) {		printf(FMT3, "ZLATMS", info, izero, n, nrhs, imat, nfail);		continue;	    }	    /* For types 5-7, zero one or more columns of the matrix	       to test that INFO is returned correctly.   */	    if ( zerot ) {		if ( imat == 5 ) izero = 1;		else if ( imat == 6 ) izero = n;		else izero = n / 2 + 1;		ioff = (izero - 1) * lda;		if ( imat < 7 ) {		    for (i = 0; i < n; ++i) Afull[ioff + i] = zero;		} else {		    for (j = 0; j < n - izero + 1; ++j)			for (i = 0; i < n; ++i)			    Afull[ioff + i + j*lda] = zero;		}	    } else {		izero = 0;	    }	    /* Convert to sparse representation. */	    sp_zconvert(n, n, Afull, lda, kl, ku, a, asub, xa, &nnz);	} else {	    izero = 0;	    zerot = 0;	}		zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE);	/* Save a copy of matrix A in ASAV */	zCreate_CompCol_Matrix(&ASAV, m, n, nnz, a_save, asub_save, xa_save,			      SLU_NC, SLU_Z, SLU_GE);	zCopy_CompCol_Matrix(&A, &ASAV);		/* Form exact solution. */	zGenXtrue(n, nrhs, xact, ldx);		StatInit(&stat);	for (iequed = 0; iequed < 4; ++iequed) {	    *equed = equeds[iequed];	    if (iequed == 0) nfact = 4;	    else nfact = 1; /* Only test factored, pre-equilibrated matrix */	    for (ifact = 0; ifact < nfact; ++ifact) {		fact = facts[ifact];		options.Fact = fact;		for (equil = 0; equil < 2; ++equil) {		    options.Equil = equil;		    prefact   = ( options.Fact == FACTORED ||				  options.Fact == SamePattern_SameRowPerm );                                /* Need a first factor */		    nofact    = (options.Fact != FACTORED);  /* Not factored */		    /* Restore the matrix A. */		    zCopy_CompCol_Matrix(&ASAV, &A);					    if ( zerot ) {                        if ( prefact ) continue;		    } else if ( options.Fact == FACTORED ) {                        if ( equil || iequed ) {			    /* Compute row and column scale factors to			       equilibrate matrix A.    */

⌨️ 快捷键说明

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