/* Subroutine */ int zhesv_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1; /* Local variables */ integer nb; extern logical lsame_(char *, char *); extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern /* Subroutine */ int zhetrf_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); integer lwkopt; logical lquery; /* -- LAPACK driver routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZHESV computes the solution to a complex system of linear equations */ /* A * X = B, */ /* where A is an N-by-N Hermitian matrix and X and B are N-by-NRHS */ /* matrices. */ /* The diagonal pivoting method is used to factor A as */ /* A = U * D * U**H, if UPLO = 'U', or */ /* A = L * D * L**H, if UPLO = 'L', */ /* where U (or L) is a product of permutation and unit upper (lower) */ /* triangular matrices, and D is Hermitian and block diagonal with */ /* 1-by-1 and 2-by-2 diagonal blocks. The factored form of A is then */ /* used to solve the system of equations A * X = B. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The number of linear equations, i.e., the order of the */ /* matrix A. N >= 0. */ /* NRHS (input) INTEGER */ /* The number of right hand sides, i.e., the number of columns */ /* of the matrix B. NRHS >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the Hermitian matrix A. If UPLO = 'U', the leading */ /* N-by-N upper triangular part of A contains the upper */ /* triangular part of the matrix A, and the strictly lower */ /* triangular part of A is not referenced. If UPLO = 'L', the */ /* leading N-by-N lower triangular part of A contains the lower */ /* triangular part of the matrix A, and the strictly upper */ /* triangular part of A is not referenced. */ /* On exit, if INFO = 0, the block diagonal matrix D and the */ /* multipliers used to obtain the factor U or L from the */ /* factorization A = U*D*U**H or A = L*D*L**H as computed by */ /* ZHETRF. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* IPIV (output) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D, as */ /* determined by ZHETRF. If IPIV(k) > 0, then rows and columns */ /* k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 */ /* diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, */ /* then rows and columns k-1 and -IPIV(k) were interchanged and */ /* D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and */ /* IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and */ /* -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 */ /* diagonal block. */ /* B (input/output) COMPLEX*16 array, dimension (LDB,NRHS) */ /* On entry, the N-by-NRHS right hand side matrix B. */ /* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The length of WORK. LWORK >= 1, and for best performance */ /* LWORK >= max(1,N*NB), where NB is the optimal blocksize for */ /* ZHETRF. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ /* has been completed, but the block diagonal matrix D is */ /* exactly singular, so the solution could not be computed. */ /* ===================================================================== */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --work; /* Function Body */ *info = 0; lquery = *lwork == -1; if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -8; } else if (*lwork < 1 && ! lquery) { *info = -10; } if (*info == 0) { if (*n == 0) { lwkopt = 1; } else { nb = ilaenv_(&c__1, "ZHETRF", uplo, n, &c_n1, &c_n1, &c_n1); lwkopt = *n * nb; } work[1].r = (doublereal) lwkopt, work[1].i = 0.; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHESV ", &i__1); return 0; } else if (lquery) { return 0; } /* Compute the factorization A = U*D*U' or A = L*D*L'. */ zhetrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], lwork, info); if (*info == 0) { /* Solve the system A*X = B, overwriting B with X. */ zhetrs_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, info); } work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZHESV */ } /* zhesv_ */
doublereal zla_hercond_x__(char *uplo, integer *n, doublecomplex *a, integer * lda, doublecomplex *af, integer *ldaf, integer *ipiv, doublecomplex * x, integer *info, doublecomplex *work, doublereal *rwork, ftnlen uplo_len) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, i__1, i__2, i__3, i__4; doublereal ret_val, d__1, d__2; doublecomplex z__1, z__2; /* Local variables */ integer i__, j; logical up; doublereal tmp; integer kase; integer isave[3]; doublereal anorm; doublereal ainvnm; /* -- LAPACK routine (version 3.2.1) -- */ /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */ /* -- Jason Riedy of Univ. of California Berkeley. -- */ /* -- April 2009 -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley and NAG Ltd. -- */ /* Purpose */ /* ======= */ /* ZLA_HERCOND_X computes the infinity norm condition number of */ /* op(A) * diag(X) where X is a COMPLEX*16 vector. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The number of linear equations, i.e., the order of the */ /* matrix A. N >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the N-by-N matrix A. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* AF (input) COMPLEX*16 array, dimension (LDAF,N) */ /* The block diagonal matrix D and the multipliers used to */ /* obtain the factor U or L as computed by ZHETRF. */ /* LDAF (input) INTEGER */ /* The leading dimension of the array AF. LDAF >= max(1,N). */ /* IPIV (input) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D */ /* as determined by CHETRF. */ /* X (input) COMPLEX*16 array, dimension (N) */ /* The vector X in the formula op(A) * diag(X). */ /* INFO (output) INTEGER */ /* = 0: Successful exit. */ /* i > 0: The ith argument is invalid. */ /* WORK (input) COMPLEX*16 array, dimension (2*N). */ /* Workspace. */ /* RWORK (input) DOUBLE PRECISION array, dimension (N). */ /* Workspace. */ /* ===================================================================== */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; --x; --work; --rwork; /* Function Body */ ret_val = 0.; *info = 0; if (*n < 0) { *info = -2; } if (*info != 0) { i__1 = -(*info); xerbla_("ZLA_HERCOND_X", &i__1); return ret_val; } up = FALSE_; if (lsame_(uplo, "U")) { up = TRUE_; } /* Compute norm of op(A)*op2(C). */ anorm = 0.; if (up) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { tmp = 0.; i__2 = i__; for (j = 1; j <= i__2; ++j) { i__3 = j + i__ * a_dim1; i__4 = j; z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4].i, z__2.i = a[i__3].r * x[i__4].i + a[i__3].i * x[i__4] .r; z__1.r = z__2.r, z__1.i = z__2.i; tmp += (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)); } i__2 = *n; for (j = i__ + 1; j <= i__2; ++j) { i__3 = i__ + j * a_dim1; i__4 = j; z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4].i, z__2.i = a[i__3].r * x[i__4].i + a[i__3].i * x[i__4] .r; z__1.r = z__2.r, z__1.i = z__2.i; tmp += (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)); } rwork[i__] = tmp; anorm = max(anorm,tmp); } } else { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { tmp = 0.; i__2 = i__; for (j = 1; j <= i__2; ++j) { i__3 = i__ + j * a_dim1; i__4 = j; z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4].i, z__2.i = a[i__3].r * x[i__4].i + a[i__3].i * x[i__4] .r; z__1.r = z__2.r, z__1.i = z__2.i; tmp += (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)); } i__2 = *n; for (j = i__ + 1; j <= i__2; ++j) { i__3 = j + i__ * a_dim1; i__4 = j; z__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4].i, z__2.i = a[i__3].r * x[i__4].i + a[i__3].i * x[i__4] .r; z__1.r = z__2.r, z__1.i = z__2.i; tmp += (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)); } rwork[i__] = tmp; anorm = max(anorm,tmp); } } /* Quick return if possible. */ if (*n == 0) { ret_val = 1.; return ret_val; } else if (anorm == 0.) { return ret_val; } /* Estimate the norm of inv(op(A)). */ ainvnm = 0.; kase = 0; L10: zlacn2_(n, &work[*n + 1], &work[1], &ainvnm, &kase, isave); if (kase != 0) { if (kase == 2) { /* Multiply by R. */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__; i__3 = i__; i__4 = i__; z__1.r = rwork[i__4] * work[i__3].r, z__1.i = rwork[i__4] * work[i__3].i; work[i__2].r = z__1.r, work[i__2].i = z__1.i; } if (up) { zhetrs_("U", n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } else { zhetrs_("L", n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } /* Multiply by inv(X). */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__; z_div(&z__1, &work[i__], &x[i__]); work[i__2].r = z__1.r, work[i__2].i = z__1.i; } } else { /* Multiply by inv(X'). */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__; z_div(&z__1, &work[i__], &x[i__]); work[i__2].r = z__1.r, work[i__2].i = z__1.i; } if (up) { zhetrs_("U", n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } else { zhetrs_("L", n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } /* Multiply by R. */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__; i__3 = i__; i__4 = i__; z__1.r = rwork[i__4] * work[i__3].r, z__1.i = rwork[i__4] * work[i__3].i; work[i__2].r = z__1.r, work[i__2].i = z__1.i; } } goto L10; } /* Compute the estimate of the reciprocal condition number. */ if (ainvnm != 0.) { ret_val = 1. / ainvnm; } return ret_val; } /* zla_hercond_x__ */
/* Subroutine */ int zhesvxx_(char *fact, char *uplo, integer *n, integer * nrhs, doublecomplex *a, integer *lda, doublecomplex *af, integer * ldaf, integer *ipiv, char *equed, doublereal *s, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *rcond, doublereal *rpvgrw, doublereal *berr, integer *n_err_bnds__, doublereal *err_bnds_norm__, doublereal *err_bnds_comp__, integer * nparams, doublereal *params, doublecomplex *work, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, err_bnds_norm_dim1, err_bnds_norm_offset, err_bnds_comp_dim1, err_bnds_comp_offset, i__1; doublereal d__1, d__2; /* Local variables */ integer j; doublereal amax, smin, smax; extern doublereal zla_herpvgrw_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublereal *); extern logical lsame_(char *, char *); doublereal scond; logical equil, rcequ; extern doublereal dlamch_(char *); logical nofact; extern /* Subroutine */ int xerbla_(char *, integer *); doublereal bignum; extern /* Subroutine */ int zlaqhe_(char *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublereal *, char *); integer infequ; extern /* Subroutine */ int zhetrf_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *); doublereal smlnum; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zlascl2_(integer *, integer *, doublereal *, doublecomplex *, integer *), zheequb_(char *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublereal *, doublecomplex *, integer *), zherfsx_(char * , char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublereal *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, doublecomplex *, doublereal *, integer * ); /* -- LAPACK driver routine (version 3.4.1) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* April 2012 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ err_bnds_comp_dim1 = *nrhs; err_bnds_comp_offset = 1 + err_bnds_comp_dim1; err_bnds_comp__ -= err_bnds_comp_offset; err_bnds_norm_dim1 = *nrhs; err_bnds_norm_offset = 1 + err_bnds_norm_dim1; err_bnds_norm__ -= err_bnds_norm_offset; a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; --s; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1; x -= x_offset; --berr; --params; --work; --rwork; /* Function Body */ *info = 0; nofact = lsame_(fact, "N"); equil = lsame_(fact, "E"); smlnum = dlamch_("Safe minimum"); bignum = 1. / smlnum; if (nofact || equil) { *(unsigned char *)equed = 'N'; rcequ = FALSE_; } else { rcequ = lsame_(equed, "Y"); } /* Default is failure. If an input parameter is wrong or */ /* factorization fails, make everything look horrible. Only the */ /* pivot growth is set here, the rest is initialized in ZHERFSX. */ *rpvgrw = 0.; /* Test the input parameters. PARAMS is not tested until ZHERFSX. */ if (! nofact && ! equil && ! lsame_(fact, "F")) { *info = -1; } else if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*nrhs < 0) { *info = -4; } else if (*lda < max(1,*n)) { *info = -6; } else if (*ldaf < max(1,*n)) { *info = -8; } else if (lsame_(fact, "F") && ! (rcequ || lsame_( equed, "N"))) { *info = -9; } else { if (rcequ) { smin = bignum; smax = 0.; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ d__1 = smin; d__2 = s[j]; // , expr subst smin = min(d__1,d__2); /* Computing MAX */ d__1 = smax; d__2 = s[j]; // , expr subst smax = max(d__1,d__2); /* L10: */ } if (smin <= 0.) { *info = -10; } else if (*n > 0) { scond = max(smin,smlnum) / min(smax,bignum); } else { scond = 1.; } } if (*info == 0) { if (*ldb < max(1,*n)) { *info = -12; } else if (*ldx < max(1,*n)) { *info = -14; } } } if (*info != 0) { i__1 = -(*info); xerbla_("ZHESVXX", &i__1); return 0; } if (equil) { /* Compute row and column scalings to equilibrate the matrix A. */ zheequb_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, &work[1], & infequ); if (infequ == 0) { /* Equilibrate the matrix. */ zlaqhe_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, equed); rcequ = lsame_(equed, "Y"); } } /* Scale the right-hand side. */ if (rcequ) { zlascl2_(n, nrhs, &s[1], &b[b_offset], ldb); } if (nofact || equil) { /* Compute the LDL^T or UDU^T factorization of A. */ zlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf); i__1 = max(1,*n) * 5; zhetrf_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &work[1], &i__1, info); /* Return if INFO is non-zero. */ if (*info > 0) { /* Pivot in column INFO is exactly 0 */ /* Compute the reciprocal pivot growth factor of the */ /* leading rank-deficient INFO columns of A. */ if (*n > 0) { *rpvgrw = zla_herpvgrw_(uplo, n, info, &a[a_offset], lda, & af[af_offset], ldaf, &ipiv[1], &rwork[1]); } return 0; } } /* Compute the reciprocal pivot growth factor RPVGRW. */ if (*n > 0) { *rpvgrw = zla_herpvgrw_(uplo, n, info, &a[a_offset], lda, &af[ af_offset], ldaf, &ipiv[1], &rwork[1]); } /* Compute the solution matrix X. */ zlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); zhetrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx, info); /* Use iterative refinement to improve the computed solution and */ /* compute error bounds and backward error estimates for it. */ zherfsx_(uplo, equed, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, & ipiv[1], &s[1], &b[b_offset], ldb, &x[x_offset], ldx, rcond, & berr[1], n_err_bnds__, &err_bnds_norm__[err_bnds_norm_offset], & err_bnds_comp__[err_bnds_comp_offset], nparams, ¶ms[1], &work[ 1], &rwork[1], info); /* Scale solutions. */ if (rcequ) { zlascl2_(n, nrhs, &s[1], &x[x_offset], ldx); } return 0; /* End of ZHESVXX */ }
/* Subroutine */ int zherfs_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, doublecomplex *af, integer *ldaf, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Builtin functions */ double d_imag(doublecomplex *); /* Local variables */ integer i__, j, k; doublereal s, xk; integer nz; doublereal eps; integer kase; doublereal safe1, safe2; extern logical lsame_(char *, char *); integer isave[3], count; extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *); logical upper; extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *), zlacn2_( integer *, doublecomplex *, doublecomplex *, doublereal *, integer *, integer *); extern doublereal dlamch_(char *); doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *); doublereal lstres; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* Modified to call ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZHERFS improves the computed solution to a system of linear */ /* equations when the coefficient matrix is Hermitian indefinite, and */ /* provides error bounds and backward error estimates for the solution. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* NRHS (input) INTEGER */ /* The number of right hand sides, i.e., the number of columns */ /* of the matrices B and X. NRHS >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,N) */ /* The Hermitian matrix A. If UPLO = 'U', the leading N-by-N */ /* upper triangular part of A contains the upper triangular part */ /* of the matrix A, and the strictly lower triangular part of A */ /* is not referenced. If UPLO = 'L', the leading N-by-N lower */ /* triangular part of A contains the lower triangular part of */ /* the matrix A, and the strictly upper triangular part of A is */ /* not referenced. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* AF (input) COMPLEX*16 array, dimension (LDAF,N) */ /* The factored form of the matrix A. AF contains the block */ /* diagonal matrix D and the multipliers used to obtain the */ /* factor U or L from the factorization A = U*D*U**H or */ /* A = L*D*L**H as computed by ZHETRF. */ /* LDAF (input) INTEGER */ /* The leading dimension of the array AF. LDAF >= max(1,N). */ /* IPIV (input) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D */ /* as determined by ZHETRF. */ /* B (input) COMPLEX*16 array, dimension (LDB,NRHS) */ /* The right hand side matrix B. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* X (input/output) COMPLEX*16 array, dimension (LDX,NRHS) */ /* On entry, the solution matrix X, as computed by ZHETRS. */ /* On exit, the improved solution matrix X. */ /* LDX (input) INTEGER */ /* The leading dimension of the array X. LDX >= max(1,N). */ /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The estimated forward error bound for each solution vector */ /* X(j) (the j-th column of the solution matrix X). */ /* If XTRUE is the true solution corresponding to X(j), FERR(j) */ /* is an estimated upper bound for the magnitude of the largest */ /* element in (X(j) - XTRUE) divided by the magnitude of the */ /* largest element in X(j). The estimate is as reliable as */ /* the estimate for RCOND, and is almost always a slight */ /* overestimate of the true error. */ /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The componentwise relative backward error of each solution */ /* vector X(j) (i.e., the smallest relative change in */ /* any element of A or B that makes X(j) an exact solution). */ /* WORK (workspace) COMPLEX*16 array, dimension (2*N) */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* Internal Parameters */ /* =================== */ /* ITMAX is the maximum number of steps of iterative refinement. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldaf < max(1,*n)) { *info = -7; } else if (*ldb < max(1,*n)) { *info = -10; } else if (*ldx < max(1,*n)) { *info = -12; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHERFS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] = 0.; berr[j] = 0.; /* L10: */ } return 0; } /* NZ = maximum number of nonzero elements in each row of A, plus 1 */ nz = *n + 1; eps = dlamch_("Epsilon"); safmin = dlamch_("Safe minimum"); safe1 = nz * safmin; safe2 = safe1 / eps; /* Do for each right hand side */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { count = 1; lstres = 3.; L20: /* Loop until stopping criterion is satisfied. */ /* Compute residual R = B - A * X */ zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); z__1.r = -1., z__1.i = -0.; zhemv_(uplo, n, &z__1, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, & c_b1, &work[1], &c__1); /* Compute componentwise relative backward error from formula */ /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */ /* where abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. If the i-th component of the denominator is less */ /* than SAFE2, then SAFE1 is added to the i-th components of the */ /* numerator and denominator before dividing. */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[ i__ + j * b_dim1]), abs(d__2)); /* L30: */ } /* Compute abs(A)*abs(X) + abs(B). */ if (upper) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), abs(d__2)); i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + k * a_dim1; rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[i__ + k * a_dim1]), abs(d__2))) * xk; i__4 = i__ + k * a_dim1; i__5 = i__ + j * x_dim1; s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[ i__ + k * a_dim1]), abs(d__2))) * ((d__3 = x[i__5] .r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), abs(d__4))); /* L40: */ } i__3 = k + k * a_dim1; rwork[k] = rwork[k] + (d__1 = a[i__3].r, abs(d__1)) * xk + s; /* L50: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), abs(d__2)); i__3 = k + k * a_dim1; rwork[k] += (d__1 = a[i__3].r, abs(d__1)) * xk; i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = i__ + k * a_dim1; rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[i__ + k * a_dim1]), abs(d__2))) * xk; i__4 = i__ + k * a_dim1; i__5 = i__ + j * x_dim1; s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a[ i__ + k * a_dim1]), abs(d__2))) * ((d__3 = x[i__5] .r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), abs(d__4))); /* L60: */ } rwork[k] += s; /* L70: */ } } s = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2))) / rwork[i__]; s = max(d__3,d__4); } else { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__] + safe1); s = max(d__3,d__4); } /* L80: */ } berr[j] = s; /* Test stopping criterion. Continue iterating if */ /* 1) The residual BERR(J) is larger than machine epsilon, and */ /* 2) BERR(J) decreased by at least a factor of 2 during the */ /* last iteration, and */ /* 3) At most ITMAX iterations tried. */ if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { /* Update solution and try again. */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[1], n, info); zaxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1); lstres = berr[j]; ++count; goto L20; } /* Bound error from formula */ /* norm(X - XTRUE) / norm(X) .le. FERR = */ /* norm( abs(inv(A))* */ /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */ /* where */ /* norm(Z) is the magnitude of the largest component of Z */ /* inv(A) is the inverse of A */ /* abs(Z) is the componentwise absolute value of the matrix or */ /* vector Z */ /* NZ is the maximum number of nonzeros in any row of A, plus 1 */ /* EPS is machine epsilon */ /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */ /* is incremented by SAFE1 if the i-th component of */ /* abs(A)*abs(X) + abs(B) is less than SAFE2. */ /* Use ZLACN2 to estimate the infinity-norm of the matrix */ /* inv(A) * diag(W), */ /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] ; } else { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] + safe1; } /* L90: */ } kase = 0; L100: zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave); if (kase != 0) { if (kase == 1) { /* Multiply by diag(W)*inv(A'). */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L110: */ } } else if (kase == 2) { /* Multiply by inv(A)*diag(W). */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L120: */ } zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } goto L100; } /* Normalize error. */ lstres = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ i__3 = i__ + j * x_dim1; d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[i__ + j * x_dim1]), abs(d__2)); lstres = max(d__3,d__4); /* L130: */ } if (lstres != 0.) { ferr[j] /= lstres; } /* L140: */ } return 0; /* End of ZHERFS */ } /* zherfs_ */
/* Subroutine */ int zhecon_(char *uplo, integer *n, doublecomplex *a, integer *lda, integer *ipiv, doublereal *anorm, doublereal *rcond, doublecomplex *work, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2; /* Local variables */ integer i__, kase; extern logical lsame_(char *, char *); integer isave[3]; logical upper; extern /* Subroutine */ int zlacn2_(integer *, doublecomplex *, doublecomplex *, doublereal *, integer *, integer *), xerbla_( char *, integer *); doublereal ainvnm; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* Modified to call ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZHECON estimates the reciprocal of the condition number of a complex */ /* Hermitian matrix A using the factorization A = U*D*U**H or */ /* A = L*D*L**H computed by ZHETRF. */ /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */ /* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the details of the factorization are stored */ /* as an upper or lower triangular matrix. */ /* = 'U': Upper triangular, form is A = U*D*U**H; */ /* = 'L': Lower triangular, form is A = L*D*L**H. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,N) */ /* The block diagonal matrix D and the multipliers used to */ /* obtain the factor U or L as computed by ZHETRF. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* IPIV (input) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D */ /* as determined by ZHETRF. */ /* ANORM (input) DOUBLE PRECISION */ /* The 1-norm of the original matrix A. */ /* RCOND (output) DOUBLE PRECISION */ /* The reciprocal of the condition number of the matrix A, */ /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */ /* estimate of the 1-norm of inv(A) computed in this routine. */ /* WORK (workspace) COMPLEX*16 array, dimension (2*N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --ipiv; --work; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < max(1,*n)) { *info = -4; } else if (*anorm < 0.) { *info = -6; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHECON", &i__1); return 0; } /* Quick return if possible */ *rcond = 0.; if (*n == 0) { *rcond = 1.; return 0; } else if (*anorm <= 0.) { return 0; } /* Check that the diagonal matrix D is nonsingular. */ if (upper) { /* Upper triangular storage: examine D from bottom to top */ for (i__ = *n; i__ >= 1; --i__) { i__1 = i__ + i__ * a_dim1; if (ipiv[i__] > 0 && (a[i__1].r == 0. && a[i__1].i == 0.)) { return 0; } /* L10: */ } } else { /* Lower triangular storage: examine D from top to bottom. */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + i__ * a_dim1; if (ipiv[i__] > 0 && (a[i__2].r == 0. && a[i__2].i == 0.)) { return 0; } /* L20: */ } } /* Estimate the 1-norm of the inverse. */ kase = 0; L30: zlacn2_(n, &work[*n + 1], &work[1], &ainvnm, &kase, isave); if (kase != 0) { /* Multiply by inv(L*D*L') or inv(U*D*U'). */ zhetrs_(uplo, n, &c__1, &a[a_offset], lda, &ipiv[1], &work[1], n, info); goto L30; } /* Compute the estimate of the reciprocal condition number. */ if (ainvnm != 0.) { *rcond = 1. / ainvnm / *anorm; } return 0; /* End of ZHECON */ } /* zhecon_ */
/* Subroutine */ int zherfs_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, doublecomplex *af, integer *ldaf, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Builtin functions */ double d_imag(doublecomplex *); /* Local variables */ integer i__, j, k; doublereal s, xk; integer nz; doublereal eps; integer kase; doublereal safe1, safe2; extern logical lsame_(char *, char *); integer isave[3], count; extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *); logical upper; extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *), zlacn2_( integer *, doublecomplex *, doublecomplex *, doublereal *, integer *, integer *); extern doublereal dlamch_(char *); doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *); doublereal lstres; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK computational routine (version 3.4.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2011 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldaf < max(1,*n)) { *info = -7; } else if (*ldb < max(1,*n)) { *info = -10; } else if (*ldx < max(1,*n)) { *info = -12; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHERFS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] = 0.; berr[j] = 0.; /* L10: */ } return 0; } /* NZ = maximum number of nonzero elements in each row of A, plus 1 */ nz = *n + 1; eps = dlamch_("Epsilon"); safmin = dlamch_("Safe minimum"); safe1 = nz * safmin; safe2 = safe1 / eps; /* Do for each right hand side */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { count = 1; lstres = 3.; L20: /* Loop until stopping criterion is satisfied. */ /* Compute residual R = B - A * X */ zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); z__1.r = -1.; z__1.i = -0.; // , expr subst zhemv_(uplo, n, &z__1, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, & c_b1, &work[1], &c__1); /* Compute componentwise relative backward error from formula */ /* max(i) ( f2c_abs(R(i)) / ( f2c_abs(A)*f2c_abs(X) + f2c_abs(B) )(i) ) */ /* where f2c_abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. If the i-th component of the denominator is less */ /* than SAFE2, then SAFE1 is added to the i-th components of the */ /* numerator and denominator before dividing. */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; rwork[i__] = (d__1 = b[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&b[ i__ + j * b_dim1]), f2c_abs(d__2)); /* L30: */ } /* Compute f2c_abs(A)*f2c_abs(X) + f2c_abs(B). */ if (upper) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), f2c_abs(d__2)); i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + k * a_dim1; rwork[i__] += ((d__1 = a[i__4].r, f2c_abs(d__1)) + (d__2 = d_imag(&a[i__ + k * a_dim1]), f2c_abs(d__2))) * xk; i__4 = i__ + k * a_dim1; i__5 = i__ + j * x_dim1; s += ((d__1 = a[i__4].r, f2c_abs(d__1)) + (d__2 = d_imag(&a[ i__ + k * a_dim1]), f2c_abs(d__2))) * ((d__3 = x[i__5] .r, f2c_abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), f2c_abs(d__4))); /* L40: */ } i__3 = k + k * a_dim1; rwork[k] = rwork[k] + (d__1 = a[i__3].r, f2c_abs(d__1)) * xk + s; /* L50: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), f2c_abs(d__2)); i__3 = k + k * a_dim1; rwork[k] += (d__1 = a[i__3].r, f2c_abs(d__1)) * xk; i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = i__ + k * a_dim1; rwork[i__] += ((d__1 = a[i__4].r, f2c_abs(d__1)) + (d__2 = d_imag(&a[i__ + k * a_dim1]), f2c_abs(d__2))) * xk; i__4 = i__ + k * a_dim1; i__5 = i__ + j * x_dim1; s += ((d__1 = a[i__4].r, f2c_abs(d__1)) + (d__2 = d_imag(&a[ i__ + k * a_dim1]), f2c_abs(d__2))) * ((d__3 = x[i__5] .r, f2c_abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), f2c_abs(d__4))); /* L60: */ } rwork[k] += s; /* L70: */ } } s = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { /* Computing MAX */ i__3 = i__; d__3 = s; d__4 = ((d__1 = work[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&work[i__]), f2c_abs(d__2))) / rwork[i__]; // , expr subst s = max(d__3,d__4); } else { /* Computing MAX */ i__3 = i__; d__3 = s; d__4 = ((d__1 = work[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&work[i__]), f2c_abs(d__2)) + safe1) / (rwork[i__] + safe1); // , expr subst s = max(d__3,d__4); } /* L80: */ } berr[j] = s; /* Test stopping criterion. Continue iterating if */ /* 1) The residual BERR(J) is larger than machine epsilon, and */ /* 2) BERR(J) decreased by at least a factor of 2 during the */ /* last iteration, and */ /* 3) At most ITMAX iterations tried. */ if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { /* Update solution and try again. */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[1], n, info); zaxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1); lstres = berr[j]; ++count; goto L20; } /* Bound error from formula */ /* norm(X - XTRUE) / norm(X) .le. FERR = */ /* norm( f2c_abs(inv(A))* */ /* ( f2c_abs(R) + NZ*EPS*( f2c_abs(A)*f2c_abs(X)+f2c_abs(B) ))) / norm(X) */ /* where */ /* norm(Z) is the magnitude of the largest component of Z */ /* inv(A) is the inverse of A */ /* f2c_abs(Z) is the componentwise absolute value of the matrix or */ /* vector Z */ /* NZ is the maximum number of nonzeros in any row of A, plus 1 */ /* EPS is machine epsilon */ /* The i-th component of f2c_abs(R)+NZ*EPS*(f2c_abs(A)*f2c_abs(X)+f2c_abs(B)) */ /* is incremented by SAFE1 if the i-th component of */ /* f2c_abs(A)*f2c_abs(X) + f2c_abs(B) is less than SAFE2. */ /* Use ZLACN2 to estimate the infinity-norm of the matrix */ /* inv(A) * diag(W), */ /* where W = f2c_abs(R) + NZ*EPS*( f2c_abs(A)*f2c_abs(X)+f2c_abs(B) ))) */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&work[i__]), f2c_abs(d__2)) + nz * eps * rwork[i__] ; } else { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&work[i__]), f2c_abs(d__2)) + nz * eps * rwork[i__] + safe1; } /* L90: */ } kase = 0; L100: zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave); if (kase != 0) { if (kase == 1) { /* Multiply by diag(W)*inv(A**H). */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r; z__1.i = rwork[i__4] * work[i__5].i; // , expr subst work[i__3].r = z__1.r; work[i__3].i = z__1.i; // , expr subst /* L110: */ } } else if (kase == 2) { /* Multiply by inv(A)*diag(W). */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r; z__1.i = rwork[i__4] * work[i__5].i; // , expr subst work[i__3].r = z__1.r; work[i__3].i = z__1.i; // , expr subst /* L120: */ } zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } goto L100; } /* Normalize error. */ lstres = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ i__3 = i__ + j * x_dim1; d__3 = lstres; d__4 = (d__1 = x[i__3].r, f2c_abs(d__1)) + (d__2 = d_imag(&x[i__ + j * x_dim1]), f2c_abs(d__2)); // , expr subst lstres = max(d__3,d__4); /* L130: */ } if (lstres != 0.) { ferr[j] /= lstres; } /* L140: */ } return 0; /* End of ZHERFS */ }
/* Subroutine */ int zchkhe_(logical *dotype, integer *nn, integer *nval, integer *nnb, integer *nbval, integer *nns, integer *nsval, doublereal *thresh, logical *tsterr, integer *nmax, doublecomplex *a, doublecomplex *afac, doublecomplex *ainv, doublecomplex *b, doublecomplex *x, doublecomplex *xact, doublecomplex *work, doublereal *rwork, integer *iwork, integer *nout) { /* Initialized data */ static integer iseedy[4] = { 1988,1989,1990,1991 }; static char uplos[1*2] = "U" "L"; /* Format strings */ static char fmt_9999[] = "(\002 UPLO = '\002,a1,\002', N =\002,i5,\002, " "NB =\002,i4,\002, type \002,i2,\002, test \002,i2,\002, ratio " "=\002,g12.5)"; static char fmt_9998[] = "(\002 UPLO = '\002,a1,\002', N =\002,i5,\002, " "NRHS=\002,i3,\002, type \002,i2,\002, test(\002,i2,\002) =\002,g" "12.5)"; static char fmt_9997[] = "(\002 UPLO = '\002,a1,\002', N =\002,i5,\002" ",\002,10x,\002 type \002,i2,\002, test(\002,i2,\002) =\002,g12.5)" ; /* System generated locals */ integer i__1, i__2, i__3, i__4, i__5; /* Builtin functions */ /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void); /* Local variables */ integer i__, j, k, n, i1, i2, nb, in, kl, ku, nt, lda, inb, ioff, mode, imat, info; char path[3], dist[1]; integer irhs, nrhs; char uplo[1], type__[1]; integer nrun; extern /* Subroutine */ int alahd_(integer *, char *); integer nfail, iseed[4]; extern doublereal dget06_(doublereal *, doublereal *); doublereal rcond; integer nimat; extern /* Subroutine */ int zhet01_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, doublereal *, doublereal *); doublereal anorm; extern /* Subroutine */ int zget04_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal * ); integer iuplo, izero, nerrs, lwork; extern /* Subroutine */ int zpot02_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *), zpot03_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublereal *), zpot05_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex * , integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublereal *); logical zerot; char xtype[1]; extern /* Subroutine */ int zlatb4_(char *, integer *, integer *, integer *, char *, integer *, integer *, doublereal *, integer *, doublereal *, char *), alaerh_(char *, char *, integer *, integer *, char *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *); doublereal rcondc; extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int alasum_(char *, integer *, integer *, integer *, integer *); doublereal cndnum; extern /* Subroutine */ int zlaipd_(integer *, doublecomplex *, integer *, integer *), zhecon_(char *, integer *, doublecomplex *, integer * , integer *, doublereal *, doublereal *, doublecomplex *, integer *); logical trfcon; extern /* Subroutine */ int xlaenv_(integer *, integer *), zerrhe_(char *, integer *), zherfs_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublecomplex *, doublereal *, integer *), zhetrf_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zhetri_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *), zlarhs_(char *, char *, char *, char *, integer *, integer *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, integer *), zlatms_(integer *, integer *, char *, integer *, char *, doublereal *, integer *, doublereal *, doublereal *, integer *, integer *, char *, doublecomplex *, integer *, doublecomplex *, integer *); doublereal result[8]; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); /* Fortran I/O blocks */ static cilist io___39 = { 0, 0, 0, fmt_9999, 0 }; static cilist io___42 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___44 = { 0, 0, 0, fmt_9997, 0 }; /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZCHKHE tests ZHETRF, -TRI, -TRS, -RFS, and -CON. */ /* Arguments */ /* ========= */ /* DOTYPE (input) LOGICAL array, dimension (NTYPES) */ /* The matrix types to be used for testing. Matrices of type j */ /* (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = */ /* .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. */ /* NN (input) INTEGER */ /* The number of values of N contained in the vector NVAL. */ /* NVAL (input) INTEGER array, dimension (NN) */ /* The values of the matrix dimension N. */ /* NNB (input) INTEGER */ /* The number of values of NB contained in the vector NBVAL. */ /* NBVAL (input) INTEGER array, dimension (NBVAL) */ /* The values of the blocksize NB. */ /* NNS (input) INTEGER */ /* The number of values of NRHS contained in the vector NSVAL. */ /* NSVAL (input) INTEGER array, dimension (NNS) */ /* The values of the number of right hand sides NRHS. */ /* THRESH (input) DOUBLE PRECISION */ /* The threshold value for the test ratios. A result is */ /* included in the output file if RESULT >= THRESH. To have */ /* every test ratio printed, use THRESH = 0. */ /* TSTERR (input) LOGICAL */ /* Flag that indicates whether error exits are to be tested. */ /* NMAX (input) INTEGER */ /* The maximum value permitted for N, used in dimensioning the */ /* work arrays. */ /* A (workspace) COMPLEX*16 array, dimension (NMAX*NMAX) */ /* AFAC (workspace) COMPLEX*16 array, dimension (NMAX*NMAX) */ /* AINV (workspace) COMPLEX*16 array, dimension (NMAX*NMAX) */ /* B (workspace) COMPLEX*16 array, dimension (NMAX*NSMAX) */ /* where NSMAX is the largest entry in NSVAL. */ /* X (workspace) COMPLEX*16 array, dimension (NMAX*NSMAX) */ /* XACT (workspace) COMPLEX*16 array, dimension (NMAX*NSMAX) */ /* WORK (workspace) COMPLEX*16 array, dimension */ /* (NMAX*max(3,NSMAX)) */ /* RWORK (workspace) DOUBLE PRECISION array, dimension */ /* (max(NMAX,2*NSMAX)) */ /* IWORK (workspace) INTEGER array, dimension (NMAX) */ /* NOUT (input) INTEGER */ /* The unit number for output. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Scalars in Common .. */ /* .. */ /* .. Common blocks .. */ /* .. */ /* .. Data statements .. */ /* Parameter adjustments */ --iwork; --rwork; --work; --xact; --x; --b; --ainv; --afac; --a; --nsval; --nbval; --nval; --dotype; /* Function Body */ /* .. */ /* .. Executable Statements .. */ /* Initialize constants and the random number seed. */ s_copy(path, "Zomplex precision", (ftnlen)1, (ftnlen)17); s_copy(path + 1, "HE", (ftnlen)2, (ftnlen)2); nrun = 0; nfail = 0; nerrs = 0; for (i__ = 1; i__ <= 4; ++i__) { iseed[i__ - 1] = iseedy[i__ - 1]; /* L10: */ } /* Test the error exits */ if (*tsterr) { zerrhe_(path, nout); } infoc_1.infot = 0; /* Do for each value of N in NVAL */ i__1 = *nn; for (in = 1; in <= i__1; ++in) { n = nval[in]; lda = max(n,1); *(unsigned char *)xtype = 'N'; nimat = 10; if (n <= 0) { nimat = 1; } izero = 0; i__2 = nimat; for (imat = 1; imat <= i__2; ++imat) { /* Do the tests only if DOTYPE( IMAT ) is true. */ if (! dotype[imat]) { goto L170; } /* Skip types 3, 4, 5, or 6 if the matrix size is too small. */ zerot = imat >= 3 && imat <= 6; if (zerot && n < imat - 2) { goto L170; } /* Do first for UPLO = 'U', then for UPLO = 'L' */ for (iuplo = 1; iuplo <= 2; ++iuplo) { *(unsigned char *)uplo = *(unsigned char *)&uplos[iuplo - 1]; /* Set up parameters with ZLATB4 and generate a test matrix */ /* with ZLATMS. */ zlatb4_(path, &imat, &n, &n, type__, &kl, &ku, &anorm, &mode, &cndnum, dist); s_copy(srnamc_1.srnamt, "ZLATMS", (ftnlen)6, (ftnlen)6); zlatms_(&n, &n, dist, iseed, type__, &rwork[1], &mode, & cndnum, &anorm, &kl, &ku, uplo, &a[1], &lda, &work[1], &info); /* Check error code from ZLATMS. */ if (info != 0) { alaerh_(path, "ZLATMS", &info, &c__0, uplo, &n, &n, &c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); goto L160; } /* For types 3-6, zero one or more rows and columns of */ /* the matrix to test that INFO is returned correctly. */ if (zerot) { if (imat == 3) { izero = 1; } else if (imat == 4) { izero = n; } else { izero = n / 2 + 1; } if (imat < 6) { /* Set row and column IZERO to zero. */ if (iuplo == 1) { ioff = (izero - 1) * lda; i__3 = izero - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = ioff + i__; a[i__4].r = 0., a[i__4].i = 0.; /* L20: */ } ioff += izero; i__3 = n; for (i__ = izero; i__ <= i__3; ++i__) { i__4 = ioff; a[i__4].r = 0., a[i__4].i = 0.; ioff += lda; /* L30: */ } } else { ioff = izero; i__3 = izero - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = ioff; a[i__4].r = 0., a[i__4].i = 0.; ioff += lda; /* L40: */ } ioff -= izero; i__3 = n; for (i__ = izero; i__ <= i__3; ++i__) { i__4 = ioff + i__; a[i__4].r = 0., a[i__4].i = 0.; /* L50: */ } } } else { ioff = 0; if (iuplo == 1) { /* Set the first IZERO rows and columns to zero. */ i__3 = n; for (j = 1; j <= i__3; ++j) { i2 = min(j,izero); i__4 = i2; for (i__ = 1; i__ <= i__4; ++i__) { i__5 = ioff + i__; a[i__5].r = 0., a[i__5].i = 0.; /* L60: */ } ioff += lda; /* L70: */ } } else { /* Set the last IZERO rows and columns to zero. */ i__3 = n; for (j = 1; j <= i__3; ++j) { i1 = max(j,izero); i__4 = n; for (i__ = i1; i__ <= i__4; ++i__) { i__5 = ioff + i__; a[i__5].r = 0., a[i__5].i = 0.; /* L80: */ } ioff += lda; /* L90: */ } } } } else { izero = 0; } /* Set the imaginary part of the diagonals. */ i__3 = lda + 1; zlaipd_(&n, &a[1], &i__3, &c__0); /* Do for each value of NB in NBVAL */ i__3 = *nnb; for (inb = 1; inb <= i__3; ++inb) { nb = nbval[inb]; xlaenv_(&c__1, &nb); /* Compute the L*D*L' or U*D*U' factorization of the */ /* matrix. */ zlacpy_(uplo, &n, &n, &a[1], &lda, &afac[1], &lda); lwork = max(2,nb) * lda; s_copy(srnamc_1.srnamt, "ZHETRF", (ftnlen)6, (ftnlen)6); zhetrf_(uplo, &n, &afac[1], &lda, &iwork[1], &ainv[1], & lwork, &info); /* Adjust the expected value of INFO to account for */ /* pivoting. */ k = izero; if (k > 0) { L100: if (iwork[k] < 0) { if (iwork[k] != -k) { k = -iwork[k]; goto L100; } } else if (iwork[k] != k) { k = iwork[k]; goto L100; } } /* Check error code from ZHETRF. */ if (info != k) { alaerh_(path, "ZHETRF", &info, &k, uplo, &n, &n, & c_n1, &c_n1, &nb, &imat, &nfail, &nerrs, nout); } if (info != 0) { trfcon = TRUE_; } else { trfcon = FALSE_; } /* + TEST 1 */ /* Reconstruct matrix from factors and compute residual. */ zhet01_(uplo, &n, &a[1], &lda, &afac[1], &lda, &iwork[1], &ainv[1], &lda, &rwork[1], result); nt = 1; /* + TEST 2 */ /* Form the inverse and compute the residual. */ if (inb == 1 && ! trfcon) { zlacpy_(uplo, &n, &n, &afac[1], &lda, &ainv[1], &lda); s_copy(srnamc_1.srnamt, "ZHETRI", (ftnlen)6, (ftnlen) 6); zhetri_(uplo, &n, &ainv[1], &lda, &iwork[1], &work[1], &info); /* Check error code from ZHETRI. */ if (info != 0) { alaerh_(path, "ZHETRI", &info, &c_n1, uplo, &n, & n, &c_n1, &c_n1, &c_n1, &imat, &nfail, & nerrs, nout); } zpot03_(uplo, &n, &a[1], &lda, &ainv[1], &lda, &work[ 1], &lda, &rwork[1], &rcondc, &result[1]); nt = 2; } /* Print information about the tests that did not pass */ /* the threshold. */ i__4 = nt; for (k = 1; k <= i__4; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___39.ciunit = *nout; s_wsfe(&io___39); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)) ; do_fio(&c__1, (char *)&nb, (ftnlen)sizeof(integer) ); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&k, (ftnlen)sizeof(integer)) ; do_fio(&c__1, (char *)&result[k - 1], (ftnlen) sizeof(doublereal)); e_wsfe(); ++nfail; } /* L110: */ } nrun += nt; /* Skip the other tests if this is not the first block */ /* size. */ if (inb > 1) { goto L150; } /* Do only the condition estimate if INFO is not 0. */ if (trfcon) { rcondc = 0.; goto L140; } i__4 = *nns; for (irhs = 1; irhs <= i__4; ++irhs) { nrhs = nsval[irhs]; /* + TEST 3 */ /* Solve and compute residual for A * X = B. */ s_copy(srnamc_1.srnamt, "ZLARHS", (ftnlen)6, (ftnlen) 6); zlarhs_(path, xtype, uplo, " ", &n, &n, &kl, &ku, & nrhs, &a[1], &lda, &xact[1], &lda, &b[1], & lda, iseed, &info); zlacpy_("Full", &n, &nrhs, &b[1], &lda, &x[1], &lda); s_copy(srnamc_1.srnamt, "ZHETRS", (ftnlen)6, (ftnlen) 6); zhetrs_(uplo, &n, &nrhs, &afac[1], &lda, &iwork[1], & x[1], &lda, &info); /* Check error code from ZHETRS. */ if (info != 0) { alaerh_(path, "ZHETRS", &info, &c__0, uplo, &n, & n, &c_n1, &c_n1, &nrhs, &imat, &nfail, & nerrs, nout); } zlacpy_("Full", &n, &nrhs, &b[1], &lda, &work[1], & lda); zpot02_(uplo, &n, &nrhs, &a[1], &lda, &x[1], &lda, & work[1], &lda, &rwork[1], &result[2]); /* + TEST 4 */ /* Check solution from generated exact solution. */ zget04_(&n, &nrhs, &x[1], &lda, &xact[1], &lda, & rcondc, &result[3]); /* + TESTS 5, 6, and 7 */ /* Use iterative refinement to improve the solution. */ s_copy(srnamc_1.srnamt, "ZHERFS", (ftnlen)6, (ftnlen) 6); zherfs_(uplo, &n, &nrhs, &a[1], &lda, &afac[1], &lda, &iwork[1], &b[1], &lda, &x[1], &lda, &rwork[1] , &rwork[nrhs + 1], &work[1], &rwork[(nrhs << 1) + 1], &info); /* Check error code from ZHERFS. */ if (info != 0) { alaerh_(path, "ZHERFS", &info, &c__0, uplo, &n, & n, &c_n1, &c_n1, &nrhs, &imat, &nfail, & nerrs, nout); } zget04_(&n, &nrhs, &x[1], &lda, &xact[1], &lda, & rcondc, &result[4]); zpot05_(uplo, &n, &nrhs, &a[1], &lda, &b[1], &lda, &x[ 1], &lda, &xact[1], &lda, &rwork[1], &rwork[ nrhs + 1], &result[5]); /* Print information about the tests that did not pass */ /* the threshold. */ for (k = 3; k <= 7; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___42.ciunit = *nout; s_wsfe(&io___42); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&nrhs, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&k, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&result[k - 1], (ftnlen) sizeof(doublereal)); e_wsfe(); ++nfail; } /* L120: */ } nrun += 5; /* L130: */ } /* + TEST 8 */ /* Get an estimate of RCOND = 1/CNDNUM. */ L140: anorm = zlanhe_("1", uplo, &n, &a[1], &lda, &rwork[1]); s_copy(srnamc_1.srnamt, "ZHECON", (ftnlen)6, (ftnlen)6); zhecon_(uplo, &n, &afac[1], &lda, &iwork[1], &anorm, & rcond, &work[1], &info); /* Check error code from ZHECON. */ if (info != 0) { alaerh_(path, "ZHECON", &info, &c__0, uplo, &n, &n, & c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); } result[7] = dget06_(&rcond, &rcondc); /* Print information about the tests that did not pass */ /* the threshold. */ if (result[7] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___44.ciunit = *nout; s_wsfe(&io___44); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&c__8, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[7], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } ++nrun; L150: ; } L160: ; } L170: ; } /* L180: */ } /* Print a summary of the results. */ alasum_(path, nout, &nfail, &nrun, &nerrs); return 0; /* End of ZCHKHE */ } /* zchkhe_ */
/* Subroutine */ int zhesv_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1; /* Local variables */ integer nb; extern logical lsame_(char *, char *); extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern /* Subroutine */ int zhetrf_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); integer lwkopt; logical lquery; extern /* Subroutine */ int zhetrs2_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *); /* -- LAPACK driver routine (version 3.4.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2011 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --work; /* Function Body */ *info = 0; lquery = *lwork == -1; if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -8; } else if (*lwork < 1 && ! lquery) { *info = -10; } if (*info == 0) { if (*n == 0) { lwkopt = 1; } else { nb = ilaenv_(&c__1, "ZHETRF", uplo, n, &c_n1, &c_n1, &c_n1); lwkopt = *n * nb; } work[1].r = (doublereal) lwkopt; work[1].i = 0.; // , expr subst } if (*info != 0) { i__1 = -(*info); xerbla_("ZHESV ", &i__1); return 0; } else if (lquery) { return 0; } /* Compute the factorization A = U*D*U**H or A = L*D*L**H. */ zhetrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], lwork, info); if (*info == 0) { /* Solve the system A*X = B, overwriting B with X. */ if (*lwork < *n) { /* Solve with TRS ( Use Level BLAS 2) */ zhetrs_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, info); } else { /* Solve with TRS2 ( Use Level BLAS 3) */ zhetrs2_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, &work[1], info); } } work[1].r = (doublereal) lwkopt; work[1].i = 0.; // , expr subst return 0; /* End of ZHESV */ }
/* Subroutine */ int zhesvx_(char *fact, char *uplo, integer *n, integer * nrhs, doublecomplex *a, integer *lda, doublecomplex *af, integer * ldaf, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *rcond, doublereal *ferr, doublereal *berr, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2; /* Local variables */ integer nb; extern logical lsame_(char *, char *); doublereal anorm; extern doublereal dlamch_(char *); logical nofact; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int zhecon_(char *, integer *, doublecomplex *, integer *, integer *, doublereal *, doublereal *, doublecomplex *, integer *), zherfs_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublecomplex *, doublereal *, integer *), zhetrf_(char *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); integer lwkopt; logical lquery; /* -- LAPACK driver routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZHESVX uses the diagonal pivoting factorization to compute the */ /* solution to a complex system of linear equations A * X = B, */ /* where A is an N-by-N Hermitian matrix and X and B are N-by-NRHS */ /* matrices. */ /* Error bounds on the solution and a condition estimate are also */ /* provided. */ /* Description */ /* =========== */ /* The following steps are performed: */ /* 1. If FACT = 'N', the diagonal pivoting method is used to factor A. */ /* The form of the factorization is */ /* A = U * D * U**H, if UPLO = 'U', or */ /* A = L * D * L**H, if UPLO = 'L', */ /* where U (or L) is a product of permutation and unit upper (lower) */ /* triangular matrices, and D is Hermitian and block diagonal with */ /* 1-by-1 and 2-by-2 diagonal blocks. */ /* 2. If some D(i,i)=0, so that D is exactly singular, then the routine */ /* returns with INFO = i. Otherwise, the factored form of A is used */ /* to estimate the condition number of the matrix A. If the */ /* reciprocal of the condition number is less than machine precision, */ /* INFO = N+1 is returned as a warning, but the routine still goes on */ /* to solve for X and compute error bounds as described below. */ /* 3. The system of equations is solved for X using the factored form */ /* of A. */ /* 4. Iterative refinement is applied to improve the computed solution */ /* matrix and calculate error bounds and backward error estimates */ /* for it. */ /* Arguments */ /* ========= */ /* FACT (input) CHARACTER*1 */ /* Specifies whether or not the factored form of A has been */ /* supplied on entry. */ /* = 'F': On entry, AF and IPIV contain the factored form */ /* of A. A, AF and IPIV will not be modified. */ /* = 'N': The matrix A will be copied to AF and factored. */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The number of linear equations, i.e., the order of the */ /* matrix A. N >= 0. */ /* NRHS (input) INTEGER */ /* The number of right hand sides, i.e., the number of columns */ /* of the matrices B and X. NRHS >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,N) */ /* The Hermitian matrix A. If UPLO = 'U', the leading N-by-N */ /* upper triangular part of A contains the upper triangular part */ /* of the matrix A, and the strictly lower triangular part of A */ /* is not referenced. If UPLO = 'L', the leading N-by-N lower */ /* triangular part of A contains the lower triangular part of */ /* the matrix A, and the strictly upper triangular part of A is */ /* not referenced. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* AF (input or output) COMPLEX*16 array, dimension (LDAF,N) */ /* If FACT = 'F', then AF is an input argument and on entry */ /* contains the block diagonal matrix D and the multipliers used */ /* to obtain the factor U or L from the factorization */ /* A = U*D*U**H or A = L*D*L**H as computed by ZHETRF. */ /* If FACT = 'N', then AF is an output argument and on exit */ /* returns the block diagonal matrix D and the multipliers used */ /* to obtain the factor U or L from the factorization */ /* A = U*D*U**H or A = L*D*L**H. */ /* LDAF (input) INTEGER */ /* The leading dimension of the array AF. LDAF >= max(1,N). */ /* IPIV (input or output) INTEGER array, dimension (N) */ /* If FACT = 'F', then IPIV is an input argument and on entry */ /* contains details of the interchanges and the block structure */ /* of D, as determined by ZHETRF. */ /* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ /* interchanged and D(k,k) is a 1-by-1 diagonal block. */ /* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ /* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ /* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ /* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ /* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ /* If FACT = 'N', then IPIV is an output argument and on exit */ /* contains details of the interchanges and the block structure */ /* of D, as determined by ZHETRF. */ /* B (input) COMPLEX*16 array, dimension (LDB,NRHS) */ /* The N-by-NRHS right hand side matrix B. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* X (output) COMPLEX*16 array, dimension (LDX,NRHS) */ /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */ /* LDX (input) INTEGER */ /* The leading dimension of the array X. LDX >= max(1,N). */ /* RCOND (output) DOUBLE PRECISION */ /* The estimate of the reciprocal condition number of the matrix */ /* A. If RCOND is less than the machine precision (in */ /* particular, if RCOND = 0), the matrix is singular to working */ /* precision. This condition is indicated by a return code of */ /* INFO > 0. */ /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The estimated forward error bound for each solution vector */ /* X(j) (the j-th column of the solution matrix X). */ /* If XTRUE is the true solution corresponding to X(j), FERR(j) */ /* is an estimated upper bound for the magnitude of the largest */ /* element in (X(j) - XTRUE) divided by the magnitude of the */ /* largest element in X(j). The estimate is as reliable as */ /* the estimate for RCOND, and is almost always a slight */ /* overestimate of the true error. */ /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The componentwise relative backward error of each solution */ /* vector X(j) (i.e., the smallest relative change in */ /* any element of A or B that makes X(j) an exact solution). */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The length of WORK. LWORK >= max(1,2*N), and for best */ /* performance, when FACT = 'N', LWORK >= max(1,2*N,N*NB), where */ /* NB is the optimal blocksize for ZHETRF. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: if INFO = i, and i is */ /* <= N: D(i,i) is exactly zero. The factorization */ /* has been completed but the factor D is exactly */ /* singular, so the solution and error bounds could */ /* not be computed. RCOND = 0 is returned. */ /* = N+1: D 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. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; nofact = lsame_(fact, "N"); lquery = *lwork == -1; if (! nofact && ! lsame_(fact, "F")) { *info = -1; } else if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*nrhs < 0) { *info = -4; } else if (*lda < max(1,*n)) { *info = -6; } else if (*ldaf < max(1,*n)) { *info = -8; } else if (*ldb < max(1,*n)) { *info = -11; } else if (*ldx < max(1,*n)) { *info = -13; } else /* if(complicated condition) */ { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; if (*lwork < max(i__1,i__2) && ! lquery) { *info = -18; } } if (*info == 0) { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; lwkopt = max(i__1,i__2); if (nofact) { nb = ilaenv_(&c__1, "ZHETRF", uplo, n, &c_n1, &c_n1, &c_n1); /* Computing MAX */ i__1 = lwkopt, i__2 = *n * nb; lwkopt = max(i__1,i__2); } work[1].r = (doublereal) lwkopt, work[1].i = 0.; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHESVX", &i__1); return 0; } else if (lquery) { return 0; } if (nofact) { /* Compute the factorization A = U*D*U' or A = L*D*L'. */ zlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf); zhetrf_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &work[1], lwork, info); /* Return if INFO is non-zero. */ if (*info > 0) { *rcond = 0.; return 0; } } /* Compute the norm of the matrix A. */ anorm = zlanhe_("I", uplo, n, &a[a_offset], lda, &rwork[1]); /* Compute the reciprocal of the condition number of A. */ zhecon_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &anorm, rcond, &work[1], info); /* Compute the solution vectors X. */ zlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); zhetrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx, info); /* Use iterative refinement to improve the computed solutions and */ /* compute error bounds and backward error estimates for them. */ zherfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &ipiv[1], &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1] , &rwork[1], info); /* Set INFO = N+1 if the matrix is singular to working precision. */ if (*rcond < dlamch_("Epsilon")) { *info = *n + 1; } work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZHESVX */ } /* zhesvx_ */