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 zcgesv_(integer *n, integer *nrhs, doublecomplex *a,
00023 integer *lda, integer *ipiv, 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, iiter;
00041 extern int zgemm_(char *, char *, integer *, integer *,
00042 integer *, doublecomplex *, doublecomplex *, integer *,
00043 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00044 integer *), zaxpy_(integer *, doublecomplex *,
00045 doublecomplex *, integer *, doublecomplex *, integer *), clag2z_(
00046 integer *, integer *, complex *, integer *, doublecomplex *,
00047 integer *, integer *), zlag2c_(integer *, integer *,
00048 doublecomplex *, integer *, complex *, integer *, integer *);
00049 extern doublereal dlamch_(char *);
00050 extern int cgetrf_(integer *, integer *, complex *,
00051 integer *, integer *, integer *), xerbla_(char *, integer *);
00052 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00053 integer *, doublereal *);
00054 extern int cgetrs_(char *, integer *, integer *, complex
00055 *, integer *, integer *, complex *, integer *, integer *);
00056 extern integer izamax_(integer *, doublecomplex *, integer *);
00057 extern int zlacpy_(char *, integer *, integer *,
00058 doublecomplex *, integer *, doublecomplex *, integer *),
00059 zgetrf_(integer *, integer *, doublecomplex *, integer *, integer
00060 *, integer *), zgetrs_(char *, integer *, integer *,
00061 doublecomplex *, integer *, integer *, doublecomplex *, integer *,
00062 integer *);
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
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 work_dim1 = *n;
00205 work_offset = 1 + work_dim1;
00206 work -= work_offset;
00207 a_dim1 = *lda;
00208 a_offset = 1 + a_dim1;
00209 a -= a_offset;
00210 --ipiv;
00211 b_dim1 = *ldb;
00212 b_offset = 1 + b_dim1;
00213 b -= b_offset;
00214 x_dim1 = *ldx;
00215 x_offset = 1 + x_dim1;
00216 x -= x_offset;
00217 --swork;
00218 --rwork;
00219
00220
00221 *info = 0;
00222 *iter = 0;
00223
00224
00225
00226 if (*n < 0) {
00227 *info = -1;
00228 } else if (*nrhs < 0) {
00229 *info = -2;
00230 } else if (*lda < max(1,*n)) {
00231 *info = -4;
00232 } else if (*ldb < max(1,*n)) {
00233 *info = -7;
00234 } else if (*ldx < max(1,*n)) {
00235 *info = -9;
00236 }
00237 if (*info != 0) {
00238 i__1 = -(*info);
00239 xerbla_("ZCGESV", &i__1);
00240 return 0;
00241 }
00242
00243
00244
00245 if (*n == 0) {
00246 return 0;
00247 }
00248
00249
00250
00251
00252 if (FALSE_) {
00253 *iter = -1;
00254 goto L40;
00255 }
00256
00257
00258
00259 anrm = zlange_("I", n, n, &a[a_offset], lda, &rwork[1]);
00260 eps = dlamch_("Epsilon");
00261 cte = anrm * eps * sqrt((doublereal) (*n)) * 1.;
00262
00263
00264
00265 ptsa = 1;
00266 ptsx = ptsa + *n * *n;
00267
00268
00269
00270
00271 zlag2c_(n, nrhs, &b[b_offset], ldb, &swork[ptsx], n, info);
00272
00273 if (*info != 0) {
00274 *iter = -2;
00275 goto L40;
00276 }
00277
00278
00279
00280
00281 zlag2c_(n, n, &a[a_offset], lda, &swork[ptsa], n, info);
00282
00283 if (*info != 0) {
00284 *iter = -2;
00285 goto L40;
00286 }
00287
00288
00289
00290 cgetrf_(n, n, &swork[ptsa], n, &ipiv[1], info);
00291
00292 if (*info != 0) {
00293 *iter = -3;
00294 goto L40;
00295 }
00296
00297
00298
00299 cgetrs_("No transpose", n, nrhs, &swork[ptsa], n, &ipiv[1], &swork[ptsx],
00300 n, info);
00301
00302
00303
00304 clag2z_(n, nrhs, &swork[ptsx], n, &x[x_offset], ldx, info);
00305
00306
00307
00308 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00309
00310 zgemm_("No Transpose", "No Transpose", n, nrhs, n, &c_b1, &a[a_offset],
00311 lda, &x[x_offset], ldx, &c_b2, &work[work_offset], n);
00312
00313
00314
00315
00316 i__1 = *nrhs;
00317 for (i__ = 1; i__ <= i__1; ++i__) {
00318 i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00319 xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(n, &
00320 x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(d__2));
00321 i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00322 work_dim1;
00323 rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00324 izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00325 work_dim1]), abs(d__2));
00326 if (rnrm > xnrm * cte) {
00327 goto L10;
00328 }
00329 }
00330
00331
00332
00333
00334 *iter = 0;
00335 return 0;
00336
00337 L10:
00338
00339 for (iiter = 1; iiter <= 30; ++iiter) {
00340
00341
00342
00343
00344 zlag2c_(n, nrhs, &work[work_offset], n, &swork[ptsx], n, info);
00345
00346 if (*info != 0) {
00347 *iter = -2;
00348 goto L40;
00349 }
00350
00351
00352
00353 cgetrs_("No transpose", n, nrhs, &swork[ptsa], n, &ipiv[1], &swork[
00354 ptsx], n, info);
00355
00356
00357
00358
00359 clag2z_(n, nrhs, &swork[ptsx], n, &work[work_offset], n, info);
00360
00361 i__1 = *nrhs;
00362 for (i__ = 1; i__ <= i__1; ++i__) {
00363 zaxpy_(n, &c_b2, &work[i__ * work_dim1 + 1], &c__1, &x[i__ *
00364 x_dim1 + 1], &c__1);
00365 }
00366
00367
00368
00369 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
00370
00371 zgemm_("No Transpose", "No Transpose", n, nrhs, n, &c_b1, &a[a_offset]
00372 , lda, &x[x_offset], ldx, &c_b2, &work[work_offset], n);
00373
00374
00375
00376
00377 i__1 = *nrhs;
00378 for (i__ = 1; i__ <= i__1; ++i__) {
00379 i__2 = izamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1;
00380 xnrm = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[izamax_(
00381 n, &x[i__ * x_dim1 + 1], &c__1) + i__ * x_dim1]), abs(
00382 d__2));
00383 i__2 = izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00384 work_dim1;
00385 rnrm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(&work[
00386 izamax_(n, &work[i__ * work_dim1 + 1], &c__1) + i__ *
00387 work_dim1]), abs(d__2));
00388 if (rnrm > xnrm * cte) {
00389 goto L20;
00390 }
00391 }
00392
00393
00394
00395
00396 *iter = iiter;
00397
00398 return 0;
00399
00400 L20:
00401
00402
00403 ;
00404 }
00405
00406
00407
00408
00409
00410
00411 *iter = -31;
00412
00413 L40:
00414
00415
00416
00417
00418 zgetrf_(n, n, &a[a_offset], lda, &ipiv[1], info);
00419
00420 if (*info != 0) {
00421 return 0;
00422 }
00423
00424 zlacpy_("All", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
00425 zgetrs_("No transpose", n, nrhs, &a[a_offset], lda, &ipiv[1], &x[x_offset]
00426 , ldx, info);
00427
00428 return 0;
00429
00430
00431
00432 }