/*--------------------------------------------------------------------*/ int main ( int argc, char *argv[] ) /* ------------------------------------- test the Chv_r1upd() method. the program's output is a matlab file to check correctness of the code. created -- 98apr30, cca ------------------------------------- */ { Chv *chv ; double imag, real, t1, t2 ; double *entries ; Drand *drand ; FILE *msgFile ; int ii, irow, jcol, msglvl, ncol, nD, nent, nL, nrow, nU, rc, seed, symflag, tag, type ; int *colind, *rowind ; if ( argc != 8 ) { fprintf(stdout, "\n\n usage : %s msglvl msgFile nD nU type symflag seed " "\n msglvl -- message level" "\n msgFile -- message file" "\n nD -- # of rows and columns in the (1,1) block" "\n nU -- # of columns in the (1,2) block" "\n type -- entries type" "\n 1 --> real" "\n 2 --> complex" "\n symflag -- symmetry flag" "\n 0 --> hermitian" "\n 1 --> symmetric" "\n 2 --> nonsymmetric " "\n seed -- random number seed" "\n", argv[0]) ; return(0) ; } if ( (msglvl = atoi(argv[1])) < 0 ) { fprintf(stderr, "\n message level must be positive\n") ; exit(-1) ; } if ( strcmp(argv[2], "stdout") == 0 ) { msgFile = stdout ; } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) { fprintf(stderr, "\n unable to open file %s\n", argv[2]) ; return(-1) ; } nD = atoi(argv[3]) ; nU = atoi(argv[4]) ; type = atoi(argv[5]) ; symflag = atoi(argv[6]) ; seed = atoi(argv[7]) ; fprintf(msgFile, "\n %% testChv:" "\n %% msglvl = %d" "\n %% msgFile = %s" "\n %% nD = %d" "\n %% nU = %d" "\n %% type = %d" "\n %% symflag = %d" "\n %% seed = %d", msglvl, argv[2], nD, nU, type, symflag, seed) ; nL = nU ; /* ----------------------------- check for errors in the input ----------------------------- */ if ( nD <= 0 || nL < 0 || nU < 0 || symflag < 0 || symflag > 3 ) { fprintf(stderr, "\n invalid input" "\n nD = %d, nL = %d, nU = %d, symflag = %d\n", nD, nL, nU, symflag) ; exit(-1) ; } if ( symflag <= 2 && nL != nU ) { fprintf(stderr, "\n invalid input" "\n symflag = %d, nL = %d, nU = %d", symflag, nL, nU) ; exit(-1) ; } /* -------------------------------------- initialize the random number generator -------------------------------------- */ drand = Drand_new() ; Drand_init(drand) ; Drand_setSeed(drand, seed) ; Drand_setNormal(drand, 0.0, 1.0) ; /* ---------------------------- initialize the Chv object ---------------------------- */ MARKTIME(t1) ; chv = Chv_new() ; Chv_init(chv, 0, nD, nL, nU, type, symflag) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize chv object", t2 - t1) ; fflush(msgFile) ; Chv_columnIndices(chv, &ncol, &colind) ; IVramp(ncol, colind, 0, 1) ; if ( CHV_IS_NONSYMMETRIC(chv) ) { Chv_rowIndices(chv, &nrow, &rowind) ; IVramp(nrow, rowind, 0, 1) ; } /* ------------------------------------ load the entries with random entries ------------------------------------ */ nent = Chv_nent(chv) ; entries = Chv_entries(chv) ; if ( CHV_IS_REAL(chv) ) { Drand_fillDvector(drand, nent, entries) ; } else if ( CHV_IS_COMPLEX(chv) ) { Drand_fillDvector(drand, 2*nent, entries) ; } if ( CHV_IS_HERMITIAN(chv) ) { for ( irow = 0 ; irow < nD ; irow++ ) { Chv_complexEntry(chv, irow, irow, &real, &imag) ; Chv_setComplexEntry(chv, irow, irow, real, 0.0) ; } } fprintf(msgFile, "\n %% matrix entries") ; Chv_writeForMatlab(chv, "a", msgFile) ; /* --------------------------------------- write out matlab code for rank-1 update --------------------------------------- */ fprintf(msgFile, "\n nD = %d ;" "\n nL = %d ;" "\n nU = %d ;" "\n nrow = nD + nL ;" "\n ncol = nD + nU ;" "\n b = a ; " "\n d = a(1,1) ;" "\n l = a(2:nrow,1) / d ; " "\n u = a(1,2:ncol) ; " "\n b(2:nrow,2:ncol) = a(2:nrow,2:ncol) - l * u ; " "\n u = u / d ; " "\n b(1,1) = d ; " "\n b(1,2:ncol) = u ; " "\n b(2:nrow,1) = l ; ", nD, nL, nU) ; if ( nL > 0 && nU > 0 ) { fprintf(msgFile, "\n b(nD+1:nrow,nD+1:ncol) = 0.0 ;") ; } /* ------------------------- perform the rank-1 update ------------------------- */ rc = Chv_r1upd(chv) ; /* fprintf(msgFile, "\n raw entries vector") ; DVfprintf(msgFile, 2*nent, entries) ; */ fprintf(msgFile, "\n %% matrix entries after update") ; Chv_writeForMatlab(chv, "c", msgFile) ; fprintf(msgFile, "\n maxerr = max(max(abs(c-b)))") ; /* ------------------------ free the working storage ------------------------ */ Chv_free(chv) ; Drand_free(drand) ; fprintf(msgFile, "\n") ; return(1) ; }
/* ------------------------------------------------------------ load entries from sigma*A chv -- pointer to the Chv object that holds the front pencil -- pointer to a Pencil that holds the matrix entries msglvl -- message level msgFile -- message file created -- 97jul18, cca ------------------------------------------------------------ */ void FrontMtx_loadEntries ( Chv *chv, Pencil *pencil, int msglvl, FILE *msgFile ) { InpMtx *inpmtxA, *inpmtxB ; double one[2] = {1.0,0.0} ; double *sigma ; double *chvent ; int chvsize, ichv, ncol, nD, nL, nU ; int *chvind, *colind ; /* --------------- check the input --------------- */ if ( chv == NULL || (msglvl > 0 && msgFile == NULL) ) { fprintf(stderr, "\n fatal error in FrontMtx_loadEntries(%p,%p,%d,%p)" "\n bad input\n", chv, pencil, msglvl, msgFile) ; exit(-1) ; } if ( msglvl > 3 ) { fprintf(msgFile, "\n\n # inside loadEntries for chv %d" ", sigma = %12.4e + i*%12.4e", chv->id, pencil->sigma[0], pencil->sigma[1]) ; fflush(msgFile) ; } Chv_dimensions(chv, &nD, &nL, &nU) ; Chv_columnIndices(chv, &ncol, &colind) ; /* ---------------------------------------- load the original entries, A + sigma * B ---------------------------------------- */ inpmtxA = pencil->inpmtxA ; sigma = pencil->sigma ; inpmtxB = pencil->inpmtxB ; if ( inpmtxA != NULL ) { int ii ; /* ------------------- load entries from A ------------------- */ for ( ii = 0 ; ii < nD ; ii++ ) { ichv = colind[ii] ; if ( INPMTX_IS_REAL_ENTRIES(inpmtxA) ) { InpMtx_realVector(inpmtxA, ichv, &chvsize, &chvind, &chvent) ; } else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtxA) ) { InpMtx_complexVector(inpmtxA, ichv, &chvsize, &chvind, &chvent) ; } if ( chvsize > 0 ) { if ( msglvl > 3 ) { int ierr ; fprintf(msgFile, "\n inpmtxA chevron %d : chvsize = %d", ichv, chvsize) ; fprintf(msgFile, "\n chvind") ; IVfp80(msgFile, chvsize, chvind, 80, &ierr) ; fprintf(msgFile, "\n chvent") ; if ( INPMTX_IS_REAL_ENTRIES(inpmtxA) ) { DVfprintf(msgFile, chvsize, chvent) ; } else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtxA) ) { DVfprintf(msgFile, 2*chvsize, chvent) ; } fflush(msgFile) ; } Chv_addChevron(chv, one, ichv, chvsize, chvind, chvent) ; } } } else { double *entries ; int ii, off, stride ; /* ----------------- load the identity ----------------- */ entries = Chv_entries(chv) ; if ( CHV_IS_REAL(chv) ) { if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { stride = nD + chv->nU ; off = 0 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[off] += 1.0 ; off += stride ; stride-- ; } } else if ( CHV_IS_NONSYMMETRIC(chv) ) { stride = 2*nD + chv->nL + chv->nU - 2 ; off = nD + chv->nL - 1 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[off] += 1.0 ; off += stride ; stride -= 2 ; } } } else if ( CHV_IS_COMPLEX(chv) ) { if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { stride = nD + chv->nU ; off = 0 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[2*off] += 1.0 ; off += stride ; stride-- ; } } else if ( CHV_IS_NONSYMMETRIC(chv) ) { stride = 2*nD + chv->nL + chv->nU - 2 ; off = nD + chv->nL - 1 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[2*off] += 1.0 ; off += stride ; stride -= 2 ; } } } } if ( inpmtxB != NULL ) { int ii ; /* ------------------------- load entries from sigma*B ------------------------- */ for ( ii = 0 ; ii < nD ; ii++ ) { ichv = colind[ii] ; if ( INPMTX_IS_REAL_ENTRIES(inpmtxB) ) { InpMtx_realVector(inpmtxB, ichv, &chvsize, &chvind, &chvent) ; } else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtxA) ) { InpMtx_complexVector(inpmtxB, ichv, &chvsize, &chvind, &chvent) ; } if ( chvsize > 0 ) { if ( msglvl > 3 ) { int ierr ; fprintf(msgFile, "\n inpmtxB chevron %d : chvsize = %d", ichv, chvsize) ; fprintf(msgFile, "\n chvind") ; IVfp80(msgFile, chvsize, chvind, 80, &ierr) ; fprintf(msgFile, "\n chvent") ; if ( INPMTX_IS_REAL_ENTRIES(inpmtxA) ) { DVfprintf(msgFile, chvsize, chvent) ; } else if ( INPMTX_IS_COMPLEX_ENTRIES(inpmtxA) ) { DVfprintf(msgFile, 2*chvsize, chvent) ; } } Chv_addChevron(chv, sigma, ichv, chvsize, chvind, chvent) ; } } } else { double *entries ; int ii, off, stride ; /* -------------------------------------- load a scalar multiple of the identity -------------------------------------- */ entries = Chv_entries(chv) ; if ( CHV_IS_REAL(chv) ) { if ( CHV_IS_SYMMETRIC(chv) ) { stride = nD + chv->nU ; off = 0 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[off] += sigma[0] ; off += stride ; stride-- ; } } else if ( CHV_IS_NONSYMMETRIC(chv) ) { stride = 2*nD + chv->nL + chv->nU - 2 ; off = nD + chv->nL - 1 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[off] += sigma[0] ; off += stride ; stride -= 2 ; } } } else if ( CHV_IS_COMPLEX(chv) ) { if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { if ( CHV_IS_HERMITIAN(chv) && sigma[1] != 0.0 ) { fprintf(stderr, "\n fatal error in FrontMtx_loadEntries()" "\n chevron is hermitian" "\n sigma = %12.4e + %12.4e*i\n", sigma[0], sigma[1]) ; exit(-1) ; } stride = nD + chv->nU ; off = 0 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[2*off] += sigma[0] ; entries[2*off+1] += sigma[1] ; off += stride ; stride-- ; } } else if ( CHV_IS_NONSYMMETRIC(chv) ) { stride = 2*nD + chv->nL + chv->nU - 2 ; off = nD + chv->nL - 1 ; for ( ii = 0 ; ii < nD ; ii++ ) { entries[2*off] += sigma[0] ; entries[2*off+1] += sigma[1] ; off += stride ; stride -= 2 ; } } } } return ; }
/*--------------------------------------------------------------------*/ int main ( int argc, char *argv[] ) /* ------------------------------------ test the Chv_assembleChv() method. created -- 98apr18, cca ------------------------------------ */ { Chv *chvI, *chvJ ; double imag, real, t1, t2 ; double *entriesI, *entriesJ ; Drand *drand ; FILE *msgFile ; int ierr, ii, irow, jcol, lastcol, msglvl, ncolI, ncolJ, nDI, nDJ, nentI, nentJ, nrowI, nrowJ, nUI, nUJ, seed, symflag, type ; int *colindI, *colindJ, *rowindI, *rowindJ, *temp ; if ( argc != 10 ) { fprintf(stdout, "\n\n usage : %s msglvl msgFile nDJ nUJ nDI nUI type symflag seed " "\n msglvl -- message level" "\n msgFile -- message file" "\n nDJ -- # of rows and columns in the (1,1) block" "\n nUJ -- # of columns in the (1,2) block" "\n nDI -- # of rows and columns in the (1,1) block" "\n nUI -- # of columns in the (1,2) block" "\n type -- entries type" "\n 1 --> real" "\n 2 --> complex" "\n symflag -- symmetry flag" "\n 0 --> symmetric" "\n 1 --> hermitian" "\n 2 --> nonsymmetric" "\n seed -- random number seed" "\n", argv[0]) ; return(0) ; } if ( (msglvl = atoi(argv[1])) < 0 ) { fprintf(stderr, "\n message level must be positive\n") ; exit(-1) ; } if ( strcmp(argv[2], "stdout") == 0 ) { msgFile = stdout ; } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) { fprintf(stderr, "\n unable to open file %s\n", argv[2]) ; return(-1) ; } nDJ = atoi(argv[3]) ; nUJ = atoi(argv[4]) ; nDI = atoi(argv[5]) ; nUI = atoi(argv[6]) ; type = atoi(argv[7]) ; symflag = atoi(argv[8]) ; seed = atoi(argv[9]) ; if ( nDJ <= 0 || nUJ < 0 || nDI <= 0 || nUI < 0 || nDI >= nDJ || (nDI + nUI) >= (nDJ + nUJ) || nUI >= (nDJ + nUJ - nDI) || ( symflag != SPOOLES_SYMMETRIC && symflag != SPOOLES_HERMITIAN && symflag != SPOOLES_NONSYMMETRIC) ) { fprintf(stderr, "\n invalid input" "\n nDJ = %d, nUJ = %d, nDI = %d, nUI = %d, symflag = %d\n", nDJ, nUJ, nDI, nUI, symflag) ; exit(-1) ; } /* -------------------------------------- initialize the random number generator -------------------------------------- */ drand = Drand_new() ; Drand_init(drand) ; Drand_setSeed(drand, seed) ; Drand_setUniform(drand, -1.0, 1.0) ; /* ---------------------------- initialize the ChvJ object ---------------------------- */ MARKTIME(t1) ; chvJ = Chv_new() ; Chv_init(chvJ, 0, nDJ, nUJ, nUJ, type, symflag) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize chv object", t2 - t1) ; fflush(msgFile) ; Chv_columnIndices(chvJ, &ncolJ, &colindJ) ; temp = IVinit(2*(nDJ+nUJ), -1) ; IVramp(2*(nDJ+nUJ), temp, 0, 1) ; IVshuffle(2*(nDJ+nUJ), temp, ++seed) ; IVcopy(ncolJ, colindJ, temp) ; IVfree(temp) ; IVqsortUp(ncolJ, colindJ) ; if ( CHV_IS_NONSYMMETRIC(chvJ) ) { Chv_rowIndices(chvJ, &nrowJ, &rowindJ) ; IVcopy(nrowJ, rowindJ, colindJ) ; } if ( msglvl > 2 ) { fprintf(msgFile, "\n %% column indices") ; IVfprintf(msgFile, ncolJ, colindJ) ; } lastcol = colindJ[ncolJ-1] ; nentJ = Chv_nent(chvJ) ; entriesJ = Chv_entries(chvJ) ; if ( CHV_IS_REAL(chvJ) ) { Drand_fillDvector(drand, nentJ, entriesJ) ; } else if ( CHV_IS_COMPLEX(chvJ) ) { Drand_fillDvector(drand, 2*nentJ, entriesJ) ; } if ( CHV_IS_HERMITIAN(chvJ) ) { /* --------------------------------------------------------- hermitian example, set imaginary part of diagonal to zero --------------------------------------------------------- */ for ( irow = 0 ; irow < nDJ ; irow++ ) { Chv_complexEntry(chvJ, irow, irow, &real, &imag) ; Chv_setComplexEntry(chvJ, irow, irow, real, 0.0) ; } } /* --------------------------- initialize the ChvI object --------------------------- */ chvI = Chv_new() ; Chv_init(chvI, 0, nDI, nUI, nUI, type, symflag) ; Chv_columnIndices(chvI, &ncolI, &colindI) ; temp = IVinit(ncolJ, -1) ; IVramp(ncolJ, temp, 0, 1) ; while ( 1 ) { IVshuffle(ncolJ, temp, ++seed) ; IVqsortUp(ncolI, temp) ; if ( temp[0] < nDJ ) { break ; } } for ( ii = 0 ; ii < ncolI ; ii++ ) { colindI[ii] = colindJ[temp[ii]] ; } IVfree(temp) ; if ( CHV_IS_NONSYMMETRIC(chvI) ) { Chv_rowIndices(chvI, &nrowI, &rowindI) ; IVcopy(nrowI, rowindI, colindI) ; } nentI = Chv_nent(chvI) ; entriesI = Chv_entries(chvI) ; if ( CHV_IS_REAL(chvI) ) { Drand_fillDvector(drand, nentI, entriesI) ; } else if ( CHV_IS_COMPLEX(chvI) ) { Drand_fillDvector(drand, 2*nentI, entriesI) ; } if ( CHV_IS_HERMITIAN(chvI) ) { /* --------------------------------------------------------- hermitian example, set imaginary part of diagonal to zero --------------------------------------------------------- */ for ( irow = 0 ; irow < nDI ; irow++ ) { Chv_complexEntry(chvI, irow, irow, &real, &imag) ; Chv_setComplexEntry(chvI, irow, irow, real, 0.0) ; } } /* -------------------------------------------------- write out the two chevron objects to a matlab file -------------------------------------------------- */ if ( msglvl > 1 ) { fprintf(msgFile, "\n a = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; Chv_writeForMatlab(chvJ, "a", msgFile) ; fprintf(msgFile, "\n b = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; Chv_writeForMatlab(chvI, "b", msgFile) ; } /* --------------------------------------------- assemble the chvI object into the chvJ object --------------------------------------------- */ Chv_assembleChv(chvJ, chvI) ; if ( msglvl > 1 ) { fprintf(msgFile, "\n %% after assembly") ; fprintf(msgFile, "\n c = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; Chv_writeForMatlab(chvJ, "c", msgFile) ; } /* ----------------- compute the error ----------------- */ fprintf(msgFile, "\n max(max(abs(c - (b + a))))") ; /* ------------------------ free the working storage ------------------------ */ Chv_free(chvJ) ; Chv_free(chvI) ; Drand_free(drand) ; fprintf(msgFile, "\n") ; return(1) ; }
/*--------------------------------------------------------------------*/ int main ( int argc, char *argv[] ) /* ------------------------------------- test the Chv_update{H,S,N}() methods. T := T - U^T * D * U T := T - U^H * D * U T := T - L * D * U created -- 98apr23, cca ------------------------------------- */ { Chv *chvT ; SubMtx *mtxD, *mtxL, *mtxU ; double imag, ops, real, t1, t2 ; Drand *drand ; DV *tempDV ; FILE *msgFile ; int irow, msglvl, ncolT, nDT, ncolU, nentT, nentU, nrowD, nrowL, nrowT, offset, seed, size, sparsityflag, symflag, type ; int *colindT, *colindU, *ivec, *rowindL, *rowindT ; if ( argc != 13 ) { fprintf(stdout, "\n\n usage : %s msglvl msgFile type symflag sparsityflag" "\n ncolT ncolU nrowD nentU offset seed" "\n msglvl -- message level" "\n msgFile -- message file" "\n type -- entries type" "\n 1 -- real" "\n 2 -- complex" "\n symflag -- type of matrix U" "\n 0 -- symmetric" "\n 1 -- hermitian" "\n 2 -- nonsymmetric" "\n sparsityflag -- dense or sparse" "\n 0 -- dense" "\n 1 -- sparse" "\n ncolT -- # of rows and columns in matrix T" "\n nDT -- # of internal rows and columns in matrix T" "\n ncolU -- # of rows and columns in matrix U" "\n nrowD -- # of rows and columns in matrix D" "\n nentU -- # of entries in matrix U" "\n offset -- distance between D_I and T" "\n seed -- random number seed" "\n", argv[0]) ; return(0) ; } if ( (msglvl = atoi(argv[1])) < 0 ) { fprintf(stderr, "\n message level must be positive\n") ; spoolesFatal(); } if ( strcmp(argv[2], "stdout") == 0 ) { msgFile = stdout ; } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) { fprintf(stderr, "\n unable to open file %s\n", argv[2]) ; return(-1) ; } type = atoi(argv[3]) ; symflag = atoi(argv[4]) ; sparsityflag = atoi(argv[5]) ; ncolT = atoi(argv[6]) ; nDT = atoi(argv[7]) ; ncolU = atoi(argv[8]) ; nrowD = atoi(argv[9]) ; nentU = atoi(argv[10]) ; offset = atoi(argv[11]) ; seed = atoi(argv[12]) ; fprintf(msgFile, "\n %% %s:" "\n %% msglvl = %d" "\n %% msgFile = %s" "\n %% type = %d" "\n %% symflag = %d" "\n %% sparsityflag = %d" "\n %% ncolT = %d" "\n %% nDT = %d" "\n %% ncolU = %d" "\n %% nrowD = %d" "\n %% nentU = %d" "\n %% offset = %d" "\n %% seed = %d", argv[0], msglvl, argv[2], type, symflag, sparsityflag, ncolT, nDT, ncolU, nrowD, nentU, offset, seed) ; /* ----------------------------- check for errors in the input ----------------------------- */ if ( (type != SPOOLES_REAL && type != SPOOLES_COMPLEX) || (symflag != SPOOLES_SYMMETRIC && symflag != SPOOLES_HERMITIAN && symflag != SPOOLES_NONSYMMETRIC) || (sparsityflag < 0 || sparsityflag > 1) || ncolT <= 0 || ncolU > (ncolT + offset) || nrowD <= 0 ) { fprintf(stderr, "\n invalid input\n") ; spoolesFatal(); } /* -------------------------------------- initialize the random number generator -------------------------------------- */ drand = Drand_new() ; Drand_init(drand) ; Drand_setSeed(drand, ++seed) ; Drand_setNormal(drand, 0.0, 1.0) ; /* ----------------------- get a vector of indices ----------------------- */ size = nrowD + offset + ncolT ; ivec = IVinit(size, -1) ; IVramp(size, ivec, 0, 1) ; /* ---------------------------- initialize the T Chv object ---------------------------- */ fprintf(msgFile, "\n\n %% symflag = %d", symflag) ; MARKTIME(t1) ; chvT = Chv_new() ; Chv_init(chvT, 0, nDT, ncolT - nDT, ncolT - nDT, type, symflag) ; nentT = Chv_nent(chvT) ; if ( CHV_IS_REAL(chvT) ) { Drand_fillDvector(drand, nentT, Chv_entries(chvT)) ; } else if ( CHV_IS_COMPLEX(chvT) ) { Drand_fillDvector(drand, 2*nentT, Chv_entries(chvT)) ; } Chv_columnIndices(chvT, &ncolT, &colindT) ; IVcopy(ncolT, colindT, ivec + nrowD + offset) ; if ( CHV_IS_NONSYMMETRIC(chvT) ) { Chv_rowIndices(chvT, &nrowT, &rowindT) ; IVcopy(nrowT, rowindT, colindT) ; } IVfree(ivec) ; if ( CHV_IS_HERMITIAN(chvT) ) { fprintf(msgFile, "\n\n %% hermitian\n") ; /* --------------------------------------------------------- hermitian example, set imaginary part of diagonal to zero --------------------------------------------------------- */ for ( irow = 0 ; irow < nDT ; irow++ ) { Chv_complexEntry(chvT, irow, irow, &real, &imag) ; Chv_setComplexEntry(chvT, irow, irow, real, 0.0) ; } } MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize chvT Chv object", t2 - t1) ; fprintf(msgFile, "\n T = zeros(%d,%d); ", size, size) ; Chv_writeForMatlab(chvT, "T", msgFile) ; /* --------------------------- initialize the D Mtx object --------------------------- */ MARKTIME(t1) ; mtxD = SubMtx_new() ; if ( CHV_IS_REAL(chvT) ) { if ( CHV_IS_SYMMETRIC(chvT) ) { SubMtx_initRandom(mtxD, SPOOLES_REAL, SUBMTX_BLOCK_DIAGONAL_SYM, 0, 0, nrowD, nrowD, nrowD*nrowD, ++seed) ; } else { SubMtx_initRandom(mtxD, SPOOLES_REAL, SUBMTX_DIAGONAL, 0, 0, nrowD, nrowD, nrowD*nrowD, ++seed) ; } } else if ( CHV_IS_COMPLEX(chvT) ) { if ( CHV_IS_HERMITIAN(chvT) ) { SubMtx_initRandom(mtxD,SPOOLES_COMPLEX,SUBMTX_BLOCK_DIAGONAL_HERM, 0, 0, nrowD, nrowD, nrowD*nrowD, ++seed) ; } else if ( CHV_IS_SYMMETRIC(chvT) ) { SubMtx_initRandom(mtxD,SPOOLES_COMPLEX, SUBMTX_BLOCK_DIAGONAL_SYM, 0, 0, nrowD, nrowD, nrowD*nrowD, ++seed) ; } else { SubMtx_initRandom(mtxD, SPOOLES_COMPLEX, SUBMTX_DIAGONAL, 0, 0, nrowD, nrowD, nrowD*nrowD, ++seed) ; } } MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize D SubMtx object", t2 - t1) ; fprintf(msgFile, "\n D = zeros(%d,%d) ;", nrowD, nrowD) ; SubMtx_writeForMatlab(mtxD, "D", msgFile) ; /* ---------------------------- initialize the U SubMtx object ---------------------------- */ MARKTIME(t1) ; mtxU = SubMtx_new() ; if ( CHV_IS_REAL(chvT) ) { if ( sparsityflag == 0 ) { SubMtx_initRandom(mtxU, SPOOLES_REAL, SUBMTX_DENSE_COLUMNS, 0, 0, nrowD, ncolU, nentU, ++seed) ; } else { SubMtx_initRandom(mtxU, SPOOLES_REAL, SUBMTX_SPARSE_COLUMNS, 0, 0, nrowD, ncolU, nentU, ++seed) ; } } else if ( CHV_IS_COMPLEX(chvT) ) { if ( sparsityflag == 0 ) { SubMtx_initRandom(mtxU, SPOOLES_COMPLEX, SUBMTX_DENSE_COLUMNS, 0, 0, nrowD, ncolU, nentU, ++seed) ; } else { SubMtx_initRandom(mtxU, SPOOLES_COMPLEX, SUBMTX_SPARSE_COLUMNS, 0, 0, nrowD, ncolU, nentU, ++seed) ; } } ivec = IVinit(offset + ncolT, -1) ; IVramp(offset + ncolT, ivec, nrowD, 1) ; IVshuffle(offset + ncolT, ivec, ++seed) ; SubMtx_columnIndices(mtxU, &ncolU, &colindU) ; IVcopy(ncolU, colindU, ivec) ; IVqsortUp(ncolU, colindU) ; IVfree(ivec) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize U SubMtx object", t2 - t1) ; fprintf(msgFile, "\n U = zeros(%d,%d) ;", nrowD, size) ; SubMtx_writeForMatlab(mtxU, "U", msgFile) ; if ( CHV_IS_NONSYMMETRIC(chvT) ) { /* ---------------------------- initialize the L SubMtx object ---------------------------- */ MARKTIME(t1) ; mtxL = SubMtx_new() ; if ( CHV_IS_REAL(chvT) ) { if ( sparsityflag == 0 ) { SubMtx_initRandom(mtxL, SPOOLES_REAL, SUBMTX_DENSE_ROWS, 0, 0, ncolU, nrowD, nentU, ++seed) ; } else { SubMtx_initRandom(mtxL, SPOOLES_REAL, SUBMTX_SPARSE_ROWS, 0, 0, ncolU, nrowD, nentU, ++seed) ; } } else if ( CHV_IS_COMPLEX(chvT) ) { if ( sparsityflag == 0 ) { SubMtx_initRandom(mtxL, SPOOLES_COMPLEX, SUBMTX_DENSE_ROWS, 0, 0, ncolU, nrowD, nentU, ++seed) ; } else { SubMtx_initRandom(mtxL, SPOOLES_COMPLEX, SUBMTX_SPARSE_ROWS, 0, 0, ncolU, nrowD, nentU, ++seed) ; } } SubMtx_rowIndices(mtxL, &nrowL, &rowindL) ; IVcopy(nrowL, rowindL, colindU) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize L SubMtx object", t2 - t1) ; fprintf(msgFile, "\n L = zeros(%d,%d) ;", size, nrowD) ; SubMtx_writeForMatlab(mtxL, "L", msgFile) ; } else { mtxL = NULL ; } /* -------------------------------- compute the matrix-matrix update -------------------------------- */ tempDV = DV_new() ; ops = 8*nrowD*nrowD*ncolU ; if ( CHV_IS_SYMMETRIC(chvT) ) { Chv_updateS(chvT, mtxD, mtxU, tempDV) ; } else if ( CHV_IS_HERMITIAN(chvT) ) { Chv_updateH(chvT, mtxD, mtxU, tempDV) ; } else if ( CHV_IS_NONSYMMETRIC(chvT) ) { Chv_updateN(chvT, mtxL, mtxD, mtxU, tempDV) ; } MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to compute m-m, %.3f mflops", t2 - t1, ops*1.e-6/(t2 - t1)) ; if ( msglvl > 1 ) { fprintf(msgFile, "\n\n %% Z Chv object") ; fprintf(msgFile, "\n Z = zeros(%d,%d); ", size, size) ; Chv_writeForMatlab(chvT, "Z", msgFile) ; fflush(msgFile) ; } /* ----------------- check with matlab ----------------- */ if ( msglvl > 1 ) { if ( CHV_IS_HERMITIAN(chvT) ) { fprintf(msgFile, "\n\n B = ctranspose(U) * D * U ;") ; } else if ( CHV_IS_SYMMETRIC(chvT) ) { fprintf(msgFile, "\n\n B = transpose(U) * D * U ;") ; } else { fprintf(msgFile, "\n\n B = L * D * U ;") ; } fprintf(msgFile, "\n\n for irow = 1:%d" "\n for jcol = 1:%d" "\n if T(irow,jcol) ~= 0.0" "\n T(irow,jcol) = T(irow,jcol) - B(irow,jcol) ;" "\n end" "\n end" "\n end" "\n emtx = abs(Z - T) ;", size, size) ; fprintf(msgFile, "\n\n maxabs = max(max(emtx)) ") ; fflush(msgFile) ; } /* ------------------------ free the working storage ------------------------ */ if ( mtxL != NULL ) { SubMtx_free(mtxL) ; } Chv_free(chvT) ; SubMtx_free(mtxD) ; SubMtx_free(mtxU) ; DV_free(tempDV) ; Drand_free(drand) ; fprintf(msgFile, "\n") ; return(1) ; }
/*--------------------------------------------------------------------*/ int main ( int argc, char *argv[] ) /* --------------------------------------- test the Chv_addChevron() method. created -- 98apr18, cca --------------------------------------- */ { Chv *chv ; double alpha[2] ; double imag, real, t1, t2 ; double *chvent, *entries ; Drand *drand ; FILE *msgFile ; int chvsize, count, ichv, ierr, ii, iloc, irow, jcol, lastcol, msglvl, ncol, nD, nent, nL, nrow, nU, off, seed, symflag, type, upper ; int *chvind, *colind, *keys, *rowind, *temp ; if ( argc != 10 ) { fprintf(stdout, "\n\n usage : %s msglvl msgFile nD nU type symflag seed " "\n alphareal alphaimag" "\n msglvl -- message level" "\n msgFile -- message file" "\n nD -- # of rows and columns in the (1,1) block" "\n nU -- # of columns in the (1,2) block" "\n type -- entries type" "\n 1 --> real" "\n 2 --> complex" "\n symflag -- symmetry flag" "\n 0 --> symmetric" "\n 1 --> hermitian" "\n 2 --> nonsymmetric" "\n seed -- random number seed" "\n alpha -- scaling parameter" "\n", argv[0]) ; return(0) ; } if ( (msglvl = atoi(argv[1])) < 0 ) { fprintf(stderr, "\n message level must be positive\n") ; exit(-1) ; } if ( strcmp(argv[2], "stdout") == 0 ) { msgFile = stdout ; } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) { fprintf(stderr, "\n unable to open file %s\n", argv[2]) ; return(-1) ; } nD = atoi(argv[3]) ; nU = atoi(argv[4]) ; type = atoi(argv[5]) ; symflag = atoi(argv[6]) ; seed = atoi(argv[7]) ; alpha[0] = atof(argv[8]) ; alpha[1] = atof(argv[9]) ; if ( nD <= 0 || nU < 0 || symflag < 0 || symflag > 2 ) { fprintf(stderr, "\n invalid input" "\n nD = %d, nU = %d, symflag = %d\n", nD, nU, symflag) ; exit(-1) ; } fprintf(msgFile, "\n alpha = %12.4e + %12.4e*i ;", alpha[0], alpha[1]) ; nL = nU ; /* -------------------------------------- initialize the random number generator -------------------------------------- */ drand = Drand_new() ; Drand_init(drand) ; Drand_setSeed(drand, seed) ; Drand_setUniform(drand, -1.0, 1.0) ; /* ---------------------------- initialize the Chv object ---------------------------- */ MARKTIME(t1) ; chv = Chv_new() ; Chv_init(chv, 0, nD, nL, nU, type, symflag) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize chv object", t2 - t1) ; fflush(msgFile) ; Chv_columnIndices(chv, &ncol, &colind) ; temp = IVinit(2*(nD+nU), -1) ; IVramp(2*(nD+nU), temp, 0, 1) ; IVshuffle(2*(nD+nU), temp, ++seed) ; IVcopy(ncol, colind, temp) ; IVqsortUp(ncol, colind) ; if ( CHV_IS_NONSYMMETRIC(chv) ) { Chv_rowIndices(chv, &nrow, &rowind) ; IVcopy(nrow, rowind, colind) ; } if ( msglvl > 2 ) { fprintf(msgFile, "\n %% column indices") ; IVfprintf(msgFile, ncol, colind) ; } lastcol = colind[ncol-1] ; nent = Chv_nent(chv) ; entries = Chv_entries(chv) ; if ( CHV_IS_REAL(chv) ) { Drand_fillDvector(drand, nent, entries) ; } else if ( CHV_IS_COMPLEX(chv) ) { Drand_fillDvector(drand, 2*nent, entries) ; } if ( CHV_IS_HERMITIAN(chv) ) { /* --------------------------------------------------------- hermitian example, set imaginary part of diagonal to zero --------------------------------------------------------- */ for ( irow = 0 ; irow < nD ; irow++ ) { Chv_complexEntry(chv, irow, irow, &real, &imag) ; Chv_setComplexEntry(chv, irow, irow, real, 0.0) ; } } if ( msglvl > 1 ) { fprintf(msgFile, "\n a = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; Chv_writeForMatlab(chv, "a", msgFile) ; } /* -------------------------------------------------- fill a chevron with random numbers and indices that are a subset of a front's, as in the assembly of original matrix entries. -------------------------------------------------- */ Drand_setUniform(drand, 0, nD) ; iloc = (int) Drand_value(drand) ; ichv = colind[iloc] ; if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { upper = nD - iloc + nU ; } else { upper = 2*(nD - iloc) - 1 + nL + nU ; } Drand_setUniform(drand, 1, upper) ; chvsize = (int) Drand_value(drand) ; fprintf(msgFile, "\n %% iloc = %d, ichv = %d, chvsize = %d", iloc, ichv, chvsize) ; chvind = IVinit(chvsize, -1) ; chvent = DVinit(2*chvsize, 0.0) ; Drand_setNormal(drand, 0.0, 1.0) ; if ( CHV_IS_REAL(chv) ) { Drand_fillDvector(drand, chvsize, chvent) ; } else if ( CHV_IS_COMPLEX(chv) ) { Drand_fillDvector(drand, 2*chvsize, chvent) ; } keys = IVinit(upper+1, -1) ; keys[0] = 0 ; if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { for ( ii = iloc + 1, count = 1 ; ii < nD + nU ; ii++ ) { keys[count++] = colind[ii] - ichv ; } } else { for ( ii = iloc + 1, count = 1 ; ii < nD + nU ; ii++ ) { keys[count++] = colind[ii] - ichv ; keys[count++] = - colind[ii] + ichv ; } } if ( msglvl > 3 ) { fprintf(msgFile, "\n %% iloc = %d, ichv = %d", iloc, ichv) ; fprintf(msgFile, "\n %% upper = %d", upper) ; fprintf(msgFile, "\n %% chvsize = %d", chvsize) ; fprintf(msgFile, "\n %% initial keys") ; IVfprintf(msgFile, count, keys) ; } IVshuffle(count, keys, ++seed) ; if ( msglvl > 3 ) { fprintf(msgFile, "\n %% shuffled keys") ; IVfp80(msgFile, count, keys, 80, &ierr) ; } IVcopy(chvsize, chvind, keys) ; if ( CHV_IS_REAL(chv) ) { IVDVqsortUp(chvsize, chvind, chvent) ; } else if ( CHV_IS_COMPLEX(chv) ) { IVZVqsortUp(chvsize, chvind, chvent) ; } if ( msglvl > 3 ) { fprintf(msgFile, "\n %% chvind") ; IVfprintf(msgFile, chvsize, chvind) ; } if ( CHV_IS_HERMITIAN(chv) ) { for ( ii = 0 ; ii < chvsize ; ii++ ) { if ( chvind[ii] == 0 ) { chvent[2*ii+1] = 0.0 ; } } } if ( msglvl > 1 ) { fprintf(msgFile, "\n b = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; if ( CHV_IS_REAL(chv) ) { if ( CHV_IS_SYMMETRIC(chv) ) { for ( ii = 0 ; ii < chvsize ; ii++ ) { off = chvind[ii] ; fprintf(msgFile, "\n b(%d,%d) = %20.12e ;", colind[iloc]+1, colind[iloc]+off+1, chvent[ii]) ; fprintf(msgFile, "\n b(%d,%d) = %20.12e ;", colind[iloc]+off+1, colind[iloc]+1, chvent[ii]) ; } } else { for ( ii = 0 ; ii < chvsize ; ii++ ) { off = chvind[ii] ; if ( off > 0 ) { fprintf(msgFile, "\n b(%d,%d) = %20.12e ;", colind[iloc]+1, colind[iloc]+off+1, chvent[ii]) ; } else { fprintf(msgFile, "\n b(%d,%d) = %20.12e ;", colind[iloc]-off+1, colind[iloc]+1, chvent[ii]) ; } } } } else if ( CHV_IS_COMPLEX(chv) ) { if ( CHV_IS_SYMMETRIC(chv) || CHV_IS_HERMITIAN(chv) ) { for ( ii = 0 ; ii < chvsize ; ii++ ) { off = chvind[ii] ; fprintf(msgFile, "\n b(%d,%d) = %20.12e + %20.12e*i;", colind[iloc]+1, colind[iloc]+off+1, chvent[2*ii], chvent[2*ii+1]) ; if ( CHV_IS_HERMITIAN(chv) ) { fprintf(msgFile, "\n b(%d,%d) = %20.12e + %20.12e*i;", colind[iloc]+off+1, colind[iloc]+1, chvent[2*ii], -chvent[2*ii+1]) ; } else { fprintf(msgFile, "\n b(%d,%d) = %20.12e + %20.12e*i;", colind[iloc]+off+1, colind[iloc]+1, chvent[2*ii], chvent[2*ii+1]) ; } } } else { for ( ii = 0 ; ii < chvsize ; ii++ ) { off = chvind[ii] ; if ( off > 0 ) { fprintf(msgFile, "\n b(%d,%d) = %20.12e + %20.12e*i;", colind[iloc]+1, colind[iloc]+off+1, chvent[2*ii], chvent[2*ii+1]) ; } else { fprintf(msgFile, "\n b(%d,%d) = %20.12e + %20.12e*i;", colind[iloc]-off+1, colind[iloc]+1, chvent[2*ii], chvent[2*ii+1]) ; } } } } } /* ------------------------------------ add the chevron into the Chv object ------------------------------------ */ Chv_addChevron(chv, alpha, ichv, chvsize, chvind, chvent) ; if ( msglvl > 1 ) { fprintf(msgFile, "\n %% after adding the chevron") ; fprintf(msgFile, "\n c = zeros(%d,%d) ;", lastcol+1, lastcol+1) ; Chv_writeForMatlab(chv, "c", msgFile) ; } /* ----------------- compute the error ----------------- */ fprintf(msgFile, "\n max(max(abs(c - (a + alpha*b))))") ; /* ------------------------ free the working storage ------------------------ */ Chv_free(chv) ; Drand_free(drand) ; IVfree(temp) ; IVfree(chvind) ; DVfree(chvent) ; IVfree(keys) ; fprintf(msgFile, "\n") ; return(1) ; }
/* ---------------------------------------- purpose -- to write the object to a file in human readable form created -- 98apr30, cca ---------------------------------------- */ void Chv_writeForHumanEye ( Chv *chv, FILE *fp ) { A2 mtx ; int ierr, ncol, nD, nL, nrow, nU ; int *colind, *rowind ; /* --------------- check the input --------------- */ if ( chv == NULL || fp == NULL ) { fprintf(stderr, "\n fatal error in Chv_writeForHumanEye(%p,%p)" "\n bad input\n", chv, fp) ; exit(-1) ; } Chv_dimensions(chv, &nD, &nL, &nU) ; fprintf(fp, "\n Chv object at address %p" "\n id = %d, nD = %d, nL = %d, nU = %d, type = %d, symflag = %d", chv, chv->id, nD, nL, nU, chv->type, chv->symflag) ; if ( CHV_IS_REAL(chv) ) { if ( CHV_IS_SYMMETRIC(chv) ) { fprintf(fp, "\n chv is real and symmetric") ; } else if ( CHV_IS_NONSYMMETRIC(chv) ) { fprintf(fp, "\n chv is real and nonsymmetric") ; } else { fprintf(fp, "\n chv has unknown symmetry type %d", chv->symflag) ; } } else if ( CHV_IS_COMPLEX(chv) ) { if ( CHV_IS_SYMMETRIC(chv) ) { fprintf(fp, "\n chv is complex and symmetric") ; } else if ( CHV_IS_HERMITIAN(chv) ) { fprintf(fp, "\n chv is complex and hermitian") ; } else if ( CHV_IS_NONSYMMETRIC(chv) ) { fprintf(fp, "\n chv is complex and nonsymmetric") ; } else { fprintf(fp, "\n chv has unknown symmetry type %d", chv->symflag) ; } } else { fprintf(fp, "\n chv has unknown type %d", chv->type) ; } Chv_rowIndices(chv, &nrow, &rowind) ; if ( nrow > 0 && rowind != NULL ) { fprintf(fp, "\n chv's row indices at %p", rowind) ; IVfp80(fp, nrow, rowind, 80, &ierr) ; } Chv_columnIndices(chv, &ncol, &colind) ; if ( ncol > 0 && colind != NULL ) { fprintf(fp, "\n chv's column indices at %p", colind) ; IVfp80(fp, ncol, colind, 80, &ierr) ; } /* -------------------- load the (1,1) block -------------------- */ A2_setDefaultFields(&mtx) ; Chv_fill11block(chv, &mtx) ; fprintf(fp, "\n (1,1) block") ; A2_writeForHumanEye(&mtx, fp) ; if ( nU > 0 ) { /* -------------------- load the (1,2) block -------------------- */ Chv_fill12block(chv, &mtx) ; fprintf(fp, "\n (1,2) block") ; A2_writeForHumanEye(&mtx, fp) ; } if ( nL > 0 && CHV_IS_NONSYMMETRIC(chv) == 1 ) { /* -------------------- load the (2,1) block -------------------- */ Chv_fill21block(chv, &mtx) ; fprintf(fp, "\n (2,1) block") ; A2_writeForHumanEye(&mtx, fp) ; } A2_clearData(&mtx) ; return ; }
/*--------------------------------------------------------------------*/ int main ( int argc, char *argv[] ) /* --------------------------------------------------- test the Chv_findPivot(), swap and update methods. the program's output is a matlab file to check correctness of the code. created -- 98jan24, cca --------------------------------------------------- */ { Chv *chv ; double imag, real, tau, t1, t2 ; double *entries ; Drand *drand ; DV *workDV ; FILE *msgFile ; int icol, ii, ipvt, irow, jcol, jpvt, jrow, msglvl, ncol, nD, ndelay, nent, nL, nrow, ntest, nU, rc, pivotsize, seed, symflag, tag, temp, type ; int *colind, *rowind ; if ( argc != 9 ) { fprintf(stdout, "\n\n usage : %s msglvl msgFile nD nU type symflag seed tau " "\n msglvl -- message level" "\n msgFile -- message file" "\n nD -- # of rows and columns in the (1,1) block" "\n nU -- # of columns in the (1,2) block" "\n type -- entries type" "\n 1 --> real" "\n 2 --> complex" "\n symflag -- symmetry flag" "\n 0 --> symmetric" "\n 1 --> hermitian" "\n 2 --> nonsymmetric" "\n seed -- random number seed" "\n tau -- bound on magnitudes of factor entries" "\n", argv[0]) ; return(0) ; } if ( (msglvl = atoi(argv[1])) < 0 ) { fprintf(stderr, "\n message level must be positive\n") ; exit(-1) ; } if ( strcmp(argv[2], "stdout") == 0 ) { msgFile = stdout ; } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) { fprintf(stderr, "\n unable to open file %s\n", argv[2]) ; return(-1) ; } nD = atoi(argv[3]) ; nU = atoi(argv[4]) ; type = atoi(argv[5]) ; symflag = atoi(argv[6]) ; seed = atoi(argv[7]) ; tau = atof(argv[8]) ; fprintf(msgFile, "\n %% testChv:" "\n %% msglvl = %d" "\n %% msgFile = %s" "\n %% nD = %d" "\n %% nU = %d" "\n %% type = %d" "\n %% symflag = %d" "\n %% seed = %d" "\n %% tau = %12.4e", msglvl, argv[2], nD, nU, type, symflag, seed, tau) ; nL = nU ; nrow = nD + nL ; ncol = nD + nU ; /* ----------------------------- check for errors in the input ----------------------------- */ if ( nD <= 0 || nU < 0 || (symflag != SPOOLES_SYMMETRIC && symflag != SPOOLES_HERMITIAN && symflag != SPOOLES_NONSYMMETRIC) ) { fprintf(stderr, "\n invalid input" "\n nD = %d, nL = %d, nU = %d, symflag = %d\n", nD, nL, nU, symflag) ; exit(-1) ; } if ( (symflag == SPOOLES_SYMMETRIC || symflag == SPOOLES_HERMITIAN) && nL != nU ) { fprintf(stderr, "\n invalid input" "\n symflag = %d, nL = %d, nU = %d", symflag, nL, nU) ; exit(-1) ; } fprintf(msgFile, "\n nD = %d ;" "\n nL = %d ;" "\n nU = %d ;" "\n nrow = nD + nL ;" "\n ncol = nD + nU ;", nD, nL, nU) ; /* -------------------------------------- initialize the random number generator -------------------------------------- */ drand = Drand_new() ; Drand_init(drand) ; Drand_setSeed(drand, seed) ; Drand_setNormal(drand, 0.0, 1.0) ; /* -------------------------- initialize the Chv object -------------------------- */ MARKTIME(t1) ; chv = Chv_new() ; Chv_init(chv, 0, nD, nL, nU, type, symflag) ; MARKTIME(t2) ; fprintf(msgFile, "\n %% CPU : %.3f to initialize chv object", t2 - t1) ; fflush(msgFile) ; Chv_columnIndices(chv, &ncol, &colind) ; IVramp(ncol, colind, 0, 1) ; if ( CHV_IS_NONSYMMETRIC(chv) ) { Chv_rowIndices(chv, &nrow, &rowind) ; IVramp(nrow, rowind, 0, 1) ; } /* ------------------------------------ load the entries with random entries ------------------------------------ */ nent = Chv_nent(chv) ; entries = Chv_entries(chv) ; if ( CHV_IS_REAL(chv) ) { Drand_fillDvector(drand, nent, entries) ; } else if ( CHV_IS_COMPLEX(chv) ) { Drand_fillDvector(drand, 2*nent, entries) ; } if ( msglvl > 4 ) { fprintf(msgFile, "\n raw entries vector") ; DVfprintf(msgFile, 2*nent, entries) ; fflush(msgFile) ; } if ( CHV_IS_HERMITIAN(chv) ) { /* --------------------------------------------------------- hermitian example, set imaginary part of diagonal to zero --------------------------------------------------------- */ for ( irow = 0 ; irow < nD ; irow++ ) { Chv_complexEntry(chv, irow, irow, &real, &imag) ; Chv_setComplexEntry(chv, irow, irow, real, 0.0) ; } } fprintf(msgFile, "\n %% matrix entries") ; Chv_writeForMatlab(chv, "a", msgFile) ; /* ------------ find a pivot ------------ */ workDV = DV_new() ; ndelay = 0 ; ntest = 0 ; pivotsize = Chv_findPivot(chv, workDV, tau, ndelay, &irow, &jcol, &ntest) ; fprintf(msgFile, "\n\n %% pivotsize = %d", pivotsize) ; ipvt = irow ; jpvt = jcol ; if ( (symflag == SPOOLES_SYMMETRIC || symflag == SPOOLES_HERMITIAN) && irow > jcol ) { temp = irow ; irow = jcol ; jcol = temp ; } fprintf(msgFile, "\n\n irow = %d ; \n jcol = %d ;", irow+1, jcol+1) ; /* ------------------------- swap the rows and columns ------------------------- */ if ( pivotsize == 0 ) { exit(0) ; } else if ( pivotsize == 1 ) { fprintf(msgFile, "\n b = a ;" "\n xtemp = b(irow,:) ;" "\n b(irow,:) = b(1,:) ;" "\n b(1,:) = xtemp ;" "\n xtemp = b(:,jcol) ;" "\n b(:,jcol) = b(:,1) ;" "\n b(:,1) = xtemp ;") ; if ( CHV_IS_SYMMETRIC(chv) || symflag == CHV_IS_HERMITIAN(chv) ) { Chv_swapRowsAndColumns(chv, 0, irow) ; } else { Chv_swapRows(chv, 0, irow) ; Chv_swapColumns(chv, 0, jcol) ; } } else if ( pivotsize == 2 ) { if ( symflag < 2 ) { fprintf(msgFile, "\n b = a ;" "\n xtemp = b(irow,:) ;" "\n b(irow,:) = b(1,:) ;" "\n b(1,:) = xtemp ;" "\n xtemp = b(:,irow) ;" "\n b(:,irow) = b(:,1) ;" "\n b(:,1) = xtemp ;" "\n xtemp = b(jcol,:) ;" "\n b(jcol,:) = b(2,:) ;" "\n b(2,:) = xtemp ;" "\n xtemp = b(:,jcol) ;" "\n b(:,jcol) = b(:,2) ;" "\n b(:,2) = xtemp ;") ; Chv_swapRowsAndColumns(chv, 0, irow) ; Chv_swapRowsAndColumns(chv, 1, jcol) ; } else { fprintf(stderr, "\n fatal error, symflag = %d, pvtsize = %d", symflag, pivotsize) ; exit(-1) ; } } /* ----------------------------------------- check that the swap was executed properly ----------------------------------------- */ fprintf(msgFile, "\n %% matrix entries") ; Chv_writeForMatlab(chv, "c", msgFile) ; fprintf(msgFile, "\n maxerrswap = norm(c - a)") ; /* --------------------------- ramp the indices once again --------------------------- */ IVramp(ncol, colind, 0, 1) ; if ( CHV_IS_NONSYMMETRIC(chv) ) { Chv_rowIndices(chv, &nrow, &rowind) ; IVramp(nrow, rowind, 0, 1) ; } /* ----------------------------------- perform the rank-1 or rank-2 update ----------------------------------- */ fprintf(msgFile, "\n\n ckeep = b ;") ; fprintf(msgFile, "\n\n c = b ;") ; if ( pivotsize == 1 ) { rc = Chv_r1upd(chv) ; fprintf(msgFile, "\n\n d = c(1,1) ;" "\n l = c(2:nrow,1)/d ;" "\n u = c(1,2:ncol) ;") ; if ( nD > 1 ) { fprintf(msgFile, "\n c(2:nrow,2:ncol) = c(2:nrow,2:ncol) - l*u ;") ; } fprintf(msgFile, "\n u = u / d ;" "\n c(1:1,1:1) = d ; " "\n c(1:1,2:ncol) = u ; " "\n c(2:ncol,1:1) = l ; ") ; fprintf(msgFile, "\n c(nD+1:nrow,nD+1:ncol) = 0 ;") ; } else { rc = Chv_r2upd(chv) ; fprintf(msgFile, "\n\n d = c(1:2,1:2) ;" "\n l = c(3:nrow,1:2) / d ;" "\n u = c(1:2,3:ncol) ;") ; if ( nD > 2 ) { fprintf(msgFile, "\n c(3:nrow,3:ncol) = c(3:nrow,3:ncol) - l*u ;") ; } fprintf(msgFile, "\n u = d \\ u ; " "\n c(1:2,1:2) = d ; " "\n c(1:2,3:ncol) = u ; " "\n c(3:ncol,1:2) = l ; ") ; if ( nU > 0 ) { fprintf(msgFile, "\n c(nD+1:nrow,nD+1:ncol) = 0 ;") ; } } fprintf(msgFile, "\n %% matrix entries after update") ; Chv_writeForMatlab(chv, "f", msgFile) ; fprintf(msgFile, "\n maxerrupd = norm(f - c)") ; /* ------------------------------------------------------ check out the maximum magnitude of elements in l and u ------------------------------------------------------ */ fprintf(msgFile, "\n ipvt = %d", ipvt + 1) ; fprintf(msgFile, "\n jpvt = %d", jpvt + 1) ; fprintf(msgFile, "\n pivotsize = %d", pivotsize) ; fprintf(msgFile, "\n tau = %12.4e", tau) ; if ( symflag < 2 ) { fprintf(msgFile, "\n ubound = max(max(abs(u))) ") ; } else { fprintf(msgFile, "\n lbound = max(max(abs(l))) " "\n ubound = max(max(abs(u))) ") ; } /* ------------------------ free the working storage ------------------------ */ Chv_free(chv) ; Drand_free(drand) ; DV_free(workDV) ; fprintf(msgFile, "\n") ; return(1) ; }