00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static doublecomplex c_b1 = {-1.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021
00022 int zcposv_(char *uplo, integer *n, integer *nrhs,
00023 doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00024 doublecomplex *x, integer *ldx, doublecomplex *work, complex *swork,
00025 doublereal *rwork, integer *iter, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, b_dim1, b_offset, work_dim1, work_offset,
00029 x_dim1, x_offset, i__1, i__2;
00030 doublereal d__1, d__2;
00031
00032
00033 double sqrt(doublereal), d_imag(doublecomplex *);
00034
00035
00036 integer i__;
00037 doublereal cte, eps, anrm;
00038 integer ptsa;
00039 doublereal rnrm, xnrm;
00040 integer ptsx;
00041 extern logical lsame_(char *, char *);
00042 integer iiter;
00043 extern int zhemm_(char *, char *, integer *, integer *,
00044 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
00045 integer *, doublecomplex *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *,
00046 integer *, doublecomplex *, integer *), zlag2c_(integer *,
00047 integer *, doublecomplex *, integer *, complex *, integer *,
00048 integer *), clag2z_(integer *, integer *, complex *, integer *,
00049 doublecomplex *, integer *, integer *), zlat2c_(char *, integer *,
00050 doublecomplex *, integer *, complex *, integer *, integer *);
00051 extern doublereal dlamch_(char *);
00052 extern int xerbla_(char *, integer *);
00053 extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *,
00054 integer *, doublereal *);
00055 extern integer izamax_(integer *, doublecomplex *, integer *);
00056 extern int cpotrf_(char *, integer *, complex *, integer
00057 *, integer *), zlacpy_(char *, integer *, integer *,
00058 doublecomplex *, integer *, doublecomplex *, integer *),
00059 cpotrs_(char *, integer *, integer *, complex *, integer *,
00060 complex *, integer *, integer *), zpotrf_(char *, integer
00061 *, doublecomplex *, integer *, integer *), zpotrs_(char *,
00062 integer *, integer *, doublecomplex *, integer *, doublecomplex *
00063 , integer *, integer *);
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 work_dim1 = *n;
00215 work_offset = 1 + work_dim1;
00216 work -= work_offset;
00217 a_dim1 = *lda;
00218 a_offset = 1 + a_dim1;
00219 a -= a_offset;
00220 b_dim1 = *ldb;
00221 b_offset = 1 + b_dim1;
00222 b -= b_offset;
00223 x_dim1 = *ldx;
00224 x_offset = 1 + x_dim1;
00225 x -= x_offset;
00226 --swork;
00227 --rwork;
00228
00229
00230 *info = 0;
00231 *iter = 0;
00232
00233
00234
00235 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
00236 *info = -1;
00237 } else if (*n < 0) {
00238 *info = -2;
00239 } else if (*nrhs < 0) {
00240 *info = -3;
00241 } else if (*lda < max(1,*n)) {
00242 *info = -5;
00243 } else if (*ldb < max(1,*n)) {
00244 *info = -7;
00245 } else if (*ldx < max(1,*n)) {
00246 *info = -9;
00247 }
00248 if (*info != 0) {
00249 i__1 = -(*info);
00250 xerbla_("ZCPOSV", &i__1);
00251 return 0;
00252 }
00253
00254
00255
00256 if (*n == 0) {
00257 return 0;
00258 }
00259
00260
00261
00262
00263 if (FALSE_) {
00264 *iter = -1;
00265 goto L40;
00266 }
00267
00268
00269
00270 anrm = zlanhe_("I", uplo, n, &a[a_offset], lda, &rwork[1]);
00271 eps = dlamch_("Epsilon");
00272 cte = anrm * eps * sqrt((doublereal) (*n)) * 1.;
00273
00274
00275
00276 ptsa = 1;
00277 ptsx = ptsa + *n * *n;
00278
00279
00280
00281
00282 zlag2c_(n, nrhs, &b[b_offset], ldb, &swork[ptsx], n, info);
00283
00284 if (*info != 0) {
00285 *iter = -2;
00286 goto L40;
00287 }
00288
00289
00290
00291
00292 zlat2c_(uplo, n, &a[a_offset], lda, &swork[ptsa], n, info);
00293
00294 if (*info != 0) {
00295 *iter = -2;
00296 goto L40;
00297 }
00298
00299
00300
00301 cpotrf_(uplo, n, &swork[ptsa], n, info);
00302
00303 if (*info != 0) {
00304 *iter = -3;
00305 goto L40;
00306 }
00307
00308
00309
00310 cpotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
00311
00312
00313
00314 clag2z_(n, nrhs, &swork[ptsx], n, &x[x_offset], ldx, info);
00315
00316
00317
00318 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00319
00320 zhemm_("Left", uplo, n, nrhs, &c_b1, &a[a_offset], lda, &x[x_offset], ldx,
00321 &c_b2, &work[work_offset], n);
00322
00323
00324
00325
00326 i__1 = *nrhs;
00327 for (i__ = 1; i__ <= i__1; ++i__) {
00328 i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00329 xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(n, &
00330 x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(d__2));
00331 i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00332 work_dim1;
00333 rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00334 izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00335 work_dim1]), abs(d__2));
00336 if (rnrm > xnrm * cte) {
00337 goto L10;
00338 }
00339 }
00340
00341
00342
00343
00344 *iter = 0;
00345 return 0;
00346
00347 L10:
00348
00349 for (iiter = 1; iiter <= 30; ++iiter) {
00350
00351
00352
00353
00354 zlag2c_(n, nrhs, &work[work_offset], n, &swork[ptsx], n, info);
00355
00356 if (*info != 0) {
00357 *iter = -2;
00358 goto L40;
00359 }
00360
00361
00362
00363 cpotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
00364
00365
00366
00367
00368 clag2z_(n, nrhs, &swork[ptsx], n, &work[work_offset], n, info);
00369
00370 i__1 = *nrhs;
00371 for (i__ = 1; i__ <= i__1; ++i__) {
00372 zaxpy_(n, &c_b2, &work[i__ * work_dim1 + 1], &c__1, &x[i__ *
00373 x_dim1 + 1], &c__1);
00374 }
00375
00376
00377
00378 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00379
00380 zhemm_("L", uplo, n, nrhs, &c_b1, &a[a_offset], lda, &x[x_offset],
00381 ldx, &c_b2, &work[work_offset], n);
00382
00383
00384
00385
00386 i__1 = *nrhs;
00387 for (i__ = 1; i__ <= i__1; ++i__) {
00388 i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00389 xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(
00390 n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(
00391 d__2));
00392 i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00393 work_dim1;
00394 rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00395 izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00396 work_dim1]), abs(d__2));
00397 if (rnrm > xnrm * cte) {
00398 goto L20;
00399 }
00400 }
00401
00402
00403
00404
00405 *iter = iiter;
00406
00407 return 0;
00408
00409 L20:
00410
00411
00412 ;
00413 }
00414
00415
00416
00417
00418
00419
00420 *iter = -31;
00421
00422 L40:
00423
00424
00425
00426
00427 zpotrf_(uplo, n, &a[a_offset], lda, info);
00428
00429 if (*info != 0) {
00430 return 0;
00431 }
00432
00433 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
00434 zpotrs_(uplo, n, nrhs, &a[a_offset], lda, &x[x_offset], ldx, info);
00435
00436 return 0;
00437
00438
00439
00440 }