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