chesv.c
Go to the documentation of this file.
00001 /* chesv.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static integer c_n1 = -1;
00020 
00021 /* Subroutine */ int chesv_(char *uplo, integer *n, integer *nrhs, complex *a, 
00022          integer *lda, integer *ipiv, complex *b, integer *ldb, complex *work, 
00023          integer *lwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, b_dim1, b_offset, i__1;
00027 
00028     /* Local variables */
00029     integer nb;
00030     extern logical lsame_(char *, char *);
00031     extern /* Subroutine */ int chetrf_(char *, integer *, complex *, integer 
00032             *, integer *, complex *, integer *, integer *), xerbla_(
00033             char *, integer *);
00034     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00035             integer *, integer *);
00036     extern /* Subroutine */ int chetrs_(char *, integer *, integer *, complex 
00037             *, integer *, integer *, complex *, integer *, integer *);
00038     integer lwkopt;
00039     logical lquery;
00040 
00041 
00042 /*  -- LAPACK driver routine (version 3.2) -- */
00043 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00044 /*     November 2006 */
00045 
00046 /*     .. Scalar Arguments .. */
00047 /*     .. */
00048 /*     .. Array Arguments .. */
00049 /*     .. */
00050 
00051 /*  Purpose */
00052 /*  ======= */
00053 
00054 /*  CHESV computes the solution to a complex system of linear equations */
00055 /*     A * X = B, */
00056 /*  where A is an N-by-N Hermitian matrix and X and B are N-by-NRHS */
00057 /*  matrices. */
00058 
00059 /*  The diagonal pivoting method is used to factor A as */
00060 /*     A = U * D * U**H,  if UPLO = 'U', or */
00061 /*     A = L * D * L**H,  if UPLO = 'L', */
00062 /*  where U (or L) is a product of permutation and unit upper (lower) */
00063 /*  triangular matrices, and D is Hermitian and block diagonal with */
00064 /*  1-by-1 and 2-by-2 diagonal blocks.  The factored form of A is then */
00065 /*  used to solve the system of equations A * X = B. */
00066 
00067 /*  Arguments */
00068 /*  ========= */
00069 
00070 /*  UPLO    (input) CHARACTER*1 */
00071 /*          = 'U':  Upper triangle of A is stored; */
00072 /*          = 'L':  Lower triangle of A is stored. */
00073 
00074 /*  N       (input) INTEGER */
00075 /*          The number of linear equations, i.e., the order of the */
00076 /*          matrix A.  N >= 0. */
00077 
00078 /*  NRHS    (input) INTEGER */
00079 /*          The number of right hand sides, i.e., the number of columns */
00080 /*          of the matrix B.  NRHS >= 0. */
00081 
00082 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00083 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading */
00084 /*          N-by-N upper triangular part of A contains the upper */
00085 /*          triangular part of the matrix A, and the strictly lower */
00086 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00087 /*          leading N-by-N lower triangular part of A contains the lower */
00088 /*          triangular part of the matrix A, and the strictly upper */
00089 /*          triangular part of A is not referenced. */
00090 
00091 /*          On exit, if INFO = 0, the block diagonal matrix D and the */
00092 /*          multipliers used to obtain the factor U or L from the */
00093 /*          factorization A = U*D*U**H or A = L*D*L**H as computed by */
00094 /*          CHETRF. */
00095 
00096 /*  LDA     (input) INTEGER */
00097 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00098 
00099 /*  IPIV    (output) INTEGER array, dimension (N) */
00100 /*          Details of the interchanges and the block structure of D, as */
00101 /*          determined by CHETRF.  If IPIV(k) > 0, then rows and columns */
00102 /*          k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 */
00103 /*          diagonal block.  If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, */
00104 /*          then rows and columns k-1 and -IPIV(k) were interchanged and */
00105 /*          D(k-1:k,k-1:k) is a 2-by-2 diagonal block.  If UPLO = 'L' and */
00106 /*          IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and */
00107 /*          -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 */
00108 /*          diagonal block. */
00109 
00110 /*  B       (input/output) COMPLEX array, dimension (LDB,NRHS) */
00111 /*          On entry, the N-by-NRHS right hand side matrix B. */
00112 /*          On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
00113 
00114 /*  LDB     (input) INTEGER */
00115 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00116 
00117 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00118 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00119 
00120 /*  LWORK   (input) INTEGER */
00121 /*          The length of WORK.  LWORK >= 1, and for best performance */
00122 /*          LWORK >= max(1,N*NB), where NB is the optimal blocksize for */
00123 /*          CHETRF. */
00124 
00125 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00126 /*          only calculates the optimal size of the WORK array, returns */
00127 /*          this value as the first entry of the WORK array, and no error */
00128 /*          message related to LWORK is issued by XERBLA. */
00129 
00130 /*  INFO    (output) INTEGER */
00131 /*          = 0: successful exit */
00132 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00133 /*          > 0: if INFO = i, D(i,i) is exactly zero.  The factorization */
00134 /*               has been completed, but the block diagonal matrix D is */
00135 /*               exactly singular, so the solution could not be computed. */
00136 
00137 /*  ===================================================================== */
00138 
00139 /*     .. Local Scalars .. */
00140 /*     .. */
00141 /*     .. External Functions .. */
00142 /*     .. */
00143 /*     .. External Subroutines .. */
00144 /*     .. */
00145 /*     .. Intrinsic Functions .. */
00146 /*     .. */
00147 /*     .. Executable Statements .. */
00148 
00149 /*     Test the input parameters. */
00150 
00151     /* Parameter adjustments */
00152     a_dim1 = *lda;
00153     a_offset = 1 + a_dim1;
00154     a -= a_offset;
00155     --ipiv;
00156     b_dim1 = *ldb;
00157     b_offset = 1 + b_dim1;
00158     b -= b_offset;
00159     --work;
00160 
00161     /* Function Body */
00162     *info = 0;
00163     lquery = *lwork == -1;
00164     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00165         *info = -1;
00166     } else if (*n < 0) {
00167         *info = -2;
00168     } else if (*nrhs < 0) {
00169         *info = -3;
00170     } else if (*lda < max(1,*n)) {
00171         *info = -5;
00172     } else if (*ldb < max(1,*n)) {
00173         *info = -8;
00174     } else if (*lwork < 1 && ! lquery) {
00175         *info = -10;
00176     }
00177 
00178     if (*info == 0) {
00179         if (*n == 0) {
00180             lwkopt = 1;
00181         } else {
00182             nb = ilaenv_(&c__1, "CHETRF", uplo, n, &c_n1, &c_n1, &c_n1);
00183             lwkopt = *n * nb;
00184         }
00185         work[1].r = (real) lwkopt, work[1].i = 0.f;
00186     }
00187 
00188     if (*info != 0) {
00189         i__1 = -(*info);
00190         xerbla_("CHESV ", &i__1);
00191         return 0;
00192     } else if (lquery) {
00193         return 0;
00194     }
00195 
00196 /*     Compute the factorization A = U*D*U' or A = L*D*L'. */
00197 
00198     chetrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], lwork, info);
00199     if (*info == 0) {
00200 
00201 /*        Solve the system A*X = B, overwriting B with X. */
00202 
00203         chetrs_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, 
00204                  info);
00205 
00206     }
00207 
00208     work[1].r = (real) lwkopt, work[1].i = 0.f;
00209 
00210     return 0;
00211 
00212 /*     End of CHESV */
00213 
00214 } /* chesv_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:28