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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020
00021 int cporfs_(char *uplo, integer *n, integer *nrhs, complex *
00022 a, integer *lda, complex *af, integer *ldaf, complex *b, integer *ldb,
00023 complex *x, integer *ldx, real *ferr, real *berr, complex *work,
00024 real *rwork, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
00028 x_offset, i__1, i__2, i__3, i__4, i__5;
00029 real r__1, r__2, r__3, r__4;
00030 complex q__1;
00031
00032
00033 double r_imag(complex *);
00034
00035
00036 integer i__, j, k;
00037 real s, xk;
00038 integer nz;
00039 real eps;
00040 integer kase;
00041 real safe1, safe2;
00042 extern logical lsame_(char *, char *);
00043 extern int chemv_(char *, integer *, complex *, complex *
00044 , integer *, complex *, integer *, complex *, complex *, integer *
00045 );
00046 integer isave[3];
00047 extern int ccopy_(integer *, complex *, integer *,
00048 complex *, integer *), caxpy_(integer *, complex *, complex *,
00049 integer *, complex *, integer *);
00050 integer count;
00051 logical upper;
00052 extern int clacn2_(integer *, complex *, complex *, real
00053 *, integer *, integer *);
00054 extern doublereal slamch_(char *);
00055 real safmin;
00056 extern int xerbla_(char *, integer *), cpotrs_(
00057 char *, integer *, integer *, complex *, integer *, complex *,
00058 integer *, integer *);
00059 real lstres;
00060
00061
00062
00063
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 a_dim1 = *lda;
00179 a_offset = 1 + a_dim1;
00180 a -= a_offset;
00181 af_dim1 = *ldaf;
00182 af_offset = 1 + af_dim1;
00183 af -= af_offset;
00184 b_dim1 = *ldb;
00185 b_offset = 1 + b_dim1;
00186 b -= b_offset;
00187 x_dim1 = *ldx;
00188 x_offset = 1 + x_dim1;
00189 x -= x_offset;
00190 --ferr;
00191 --berr;
00192 --work;
00193 --rwork;
00194
00195
00196 *info = 0;
00197 upper = lsame_(uplo, "U");
00198 if (! upper && ! lsame_(uplo, "L")) {
00199 *info = -1;
00200 } else if (*n < 0) {
00201 *info = -2;
00202 } else if (*nrhs < 0) {
00203 *info = -3;
00204 } else if (*lda < max(1,*n)) {
00205 *info = -5;
00206 } else if (*ldaf < max(1,*n)) {
00207 *info = -7;
00208 } else if (*ldb < max(1,*n)) {
00209 *info = -9;
00210 } else if (*ldx < max(1,*n)) {
00211 *info = -11;
00212 }
00213 if (*info != 0) {
00214 i__1 = -(*info);
00215 xerbla_("CPORFS", &i__1);
00216 return 0;
00217 }
00218
00219
00220
00221 if (*n == 0 || *nrhs == 0) {
00222 i__1 = *nrhs;
00223 for (j = 1; j <= i__1; ++j) {
00224 ferr[j] = 0.f;
00225 berr[j] = 0.f;
00226
00227 }
00228 return 0;
00229 }
00230
00231
00232
00233 nz = *n + 1;
00234 eps = slamch_("Epsilon");
00235 safmin = slamch_("Safe minimum");
00236 safe1 = nz * safmin;
00237 safe2 = safe1 / eps;
00238
00239
00240
00241 i__1 = *nrhs;
00242 for (j = 1; j <= i__1; ++j) {
00243
00244 count = 1;
00245 lstres = 3.f;
00246 L20:
00247
00248
00249
00250
00251
00252 ccopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00253 q__1.r = -1.f, q__1.i = -0.f;
00254 chemv_(uplo, n, &q__1, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, &
00255 c_b1, &work[1], &c__1);
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 i__2 = *n;
00267 for (i__ = 1; i__ <= i__2; ++i__) {
00268 i__3 = i__ + j * b_dim1;
00269 rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00270 i__ + j * b_dim1]), dabs(r__2));
00271
00272 }
00273
00274
00275
00276 if (upper) {
00277 i__2 = *n;
00278 for (k = 1; k <= i__2; ++k) {
00279 s = 0.f;
00280 i__3 = k + j * x_dim1;
00281 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j
00282 * x_dim1]), dabs(r__2));
00283 i__3 = k - 1;
00284 for (i__ = 1; i__ <= i__3; ++i__) {
00285 i__4 = i__ + k * a_dim1;
00286 rwork[i__] += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 =
00287 r_imag(&a[i__ + k * a_dim1]), dabs(r__2))) * xk;
00288 i__4 = i__ + k * a_dim1;
00289 i__5 = i__ + j * x_dim1;
00290 s += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = r_imag(&a[
00291 i__ + k * a_dim1]), dabs(r__2))) * ((r__3 = x[
00292 i__5].r, dabs(r__3)) + (r__4 = r_imag(&x[i__ + j *
00293 x_dim1]), dabs(r__4)));
00294
00295 }
00296 i__3 = k + k * a_dim1;
00297 rwork[k] = rwork[k] + (r__1 = a[i__3].r, dabs(r__1)) * xk + s;
00298
00299 }
00300 } else {
00301 i__2 = *n;
00302 for (k = 1; k <= i__2; ++k) {
00303 s = 0.f;
00304 i__3 = k + j * x_dim1;
00305 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j
00306 * x_dim1]), dabs(r__2));
00307 i__3 = k + k * a_dim1;
00308 rwork[k] += (r__1 = a[i__3].r, dabs(r__1)) * xk;
00309 i__3 = *n;
00310 for (i__ = k + 1; i__ <= i__3; ++i__) {
00311 i__4 = i__ + k * a_dim1;
00312 rwork[i__] += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 =
00313 r_imag(&a[i__ + k * a_dim1]), dabs(r__2))) * xk;
00314 i__4 = i__ + k * a_dim1;
00315 i__5 = i__ + j * x_dim1;
00316 s += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = r_imag(&a[
00317 i__ + k * a_dim1]), dabs(r__2))) * ((r__3 = x[
00318 i__5].r, dabs(r__3)) + (r__4 = r_imag(&x[i__ + j *
00319 x_dim1]), dabs(r__4)));
00320
00321 }
00322 rwork[k] += s;
00323
00324 }
00325 }
00326 s = 0.f;
00327 i__2 = *n;
00328 for (i__ = 1; i__ <= i__2; ++i__) {
00329 if (rwork[i__] > safe2) {
00330
00331 i__3 = i__;
00332 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00333 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00334 s = dmax(r__3,r__4);
00335 } else {
00336
00337 i__3 = i__;
00338 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00339 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00340 + safe1);
00341 s = dmax(r__3,r__4);
00342 }
00343
00344 }
00345 berr[j] = s;
00346
00347
00348
00349
00350
00351
00352
00353 if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00354
00355
00356
00357 cpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[1], n, info);
00358 caxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00359 lstres = berr[j];
00360 ++count;
00361 goto L20;
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 i__2 = *n;
00387 for (i__ = 1; i__ <= i__2; ++i__) {
00388 if (rwork[i__] > safe2) {
00389 i__3 = i__;
00390 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00391 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00392 i__];
00393 } else {
00394 i__3 = i__;
00395 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00396 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00397 i__] + safe1;
00398 }
00399
00400 }
00401
00402 kase = 0;
00403 L100:
00404 clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00405 if (kase != 0) {
00406 if (kase == 1) {
00407
00408
00409
00410 cpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[1], n,
00411 info);
00412 i__2 = *n;
00413 for (i__ = 1; i__ <= i__2; ++i__) {
00414 i__3 = i__;
00415 i__4 = i__;
00416 i__5 = i__;
00417 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00418 * work[i__5].i;
00419 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00420
00421 }
00422 } else if (kase == 2) {
00423
00424
00425
00426 i__2 = *n;
00427 for (i__ = 1; i__ <= i__2; ++i__) {
00428 i__3 = i__;
00429 i__4 = i__;
00430 i__5 = i__;
00431 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00432 * work[i__5].i;
00433 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00434
00435 }
00436 cpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[1], n,
00437 info);
00438 }
00439 goto L100;
00440 }
00441
00442
00443
00444 lstres = 0.f;
00445 i__2 = *n;
00446 for (i__ = 1; i__ <= i__2; ++i__) {
00447
00448 i__3 = i__ + j * x_dim1;
00449 r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 =
00450 r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00451 lstres = dmax(r__3,r__4);
00452
00453 }
00454 if (lstres != 0.f) {
00455 ferr[j] /= lstres;
00456 }
00457
00458
00459 }
00460
00461 return 0;
00462
00463
00464
00465 }