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