Debian Codegraph @

debian/external_deps/fetk/punc/src/arpack/zgetv0.c

raw
1 /* ./src_f77/zgetv0.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* Common Block Declarations */
9
10 struct {
11 integer logfil, ndigit, mgetv0, msaupd, msaup2, msaitr, mseigt, msapps,
12 msgets, mseupd, mnaupd, mnaup2, mnaitr, mneigh, mnapps, mngets,
13 mneupd, mcaupd, mcaup2, mcaitr, mceigh, mcapps, mcgets, mceupd;
14 } debug_ZGETV0;
15
16 #define debug_1 debug_ZGETV0
17
18 struct {
19 integer nopx, nbx, nrorth, nitref, nrstrt;
20 real tsaupd, tsaup2, tsaitr, tseigt, tsgets, tsapps, tsconv, tnaupd,
21 tnaup2, tnaitr, tneigh, tngets, tnapps, tnconv, tcaupd, tcaup2,
22 tcaitr, tceigh, tcgets, tcapps, tcconv, tmvopx, tmvbx, tgetv0,
23 titref, trvec;
24 } timing_ZGETV0;
25
26 #define timing_1 timing_ZGETV0
27
28 /* Table of constant values */
29
30 static doublecomplex c_b1 = {1.,0.};
31 static doublecomplex c_b2 = {0.,0.};
32 static integer c__1 = 1;
33
34 /* \BeginDoc */
35
36 /* \Name: zgetv0 */
37
38 /* \Description: */
39 /* Generate a random initial residual vector for the Arnoldi process. */
40 /* Force the residual vector to be in the range of the operator OP. */
41
42 /* \Usage: */
43 /* call zgetv0 */
44 /* ( IDO, BMAT, ITRY, INITV, N, J, V, LDV, RESID, RNORM, */
45 /* IPNTR, WORKD, IERR ) */
46
47 /* \Arguments */
48 /* IDO Integer. (INPUT/OUTPUT) */
49 /* Reverse communication flag. IDO must be zero on the first */
50 /* call to zgetv0. */
51 /* ------------------------------------------------------------- */
52 /* IDO = 0: first call to the reverse communication interface */
53 /* IDO = -1: compute Y = OP * X where */
54 /* IPNTR(1) is the pointer into WORKD for X, */
55 /* IPNTR(2) is the pointer into WORKD for Y. */
56 /* This is for the initialization phase to force the */
57 /* starting vector into the range of OP. */
58 /* IDO = 2: compute Y = B * X where */
59 /* IPNTR(1) is the pointer into WORKD for X, */
60 /* IPNTR(2) is the pointer into WORKD for Y. */
61 /* IDO = 99: done */
62 /* ------------------------------------------------------------- */
63
64 /* BMAT Character*1. (INPUT) */
65 /* BMAT specifies the type of the matrix B in the (generalized) */
66 /* eigenvalue problem A*x = lambda*B*x. */
67 /* B = 'I' -> standard eigenvalue problem A*x = lambda*x */
68 /* B = 'G' -> generalized eigenvalue problem A*x = lambda*B*x */
69
70 /* ITRY Integer. (INPUT) */
71 /* ITRY counts the number of times that zgetv0 is called. */
72 /* It should be set to 1 on the initial call to zgetv0. */
73
74 /* INITV Logical variable. (INPUT) */
75 /* .TRUE. => the initial residual vector is given in RESID. */
76 /* .FALSE. => generate a random initial residual vector. */
77
78 /* N Integer. (INPUT) */
79 /* Dimension of the problem. */
80
81 /* J Integer. (INPUT) */
82 /* Index of the residual vector to be generated, with respect to */
83 /* the Arnoldi process. J > 1 in case of a "restart". */
84
85 /* V Complex*16 N by J array. (INPUT) */
86 /* The first J-1 columns of V contain the current Arnoldi basis */
87 /* if this is a "restart". */
88
89 /* LDV Integer. (INPUT) */
90 /* Leading dimension of V exactly as declared in the calling */
91 /* program. */
92
93 /* RESID Complex*16 array of length N. (INPUT/OUTPUT) */
94 /* Initial residual vector to be generated. If RESID is */
95 /* provided, force RESID into the range of the operator OP. */
96
97 /* RNORM Double precision scalar. (OUTPUT) */
98 /* B-norm of the generated residual. */
99
100 /* IPNTR Integer array of length 3. (OUTPUT) */
101
102 /* WORKD Complex*16 work array of length 2*N. (REVERSE COMMUNICATION). */
103 /* On exit, WORK(1:N) = B*RESID to be used in SSAITR. */
104
105 /* IERR Integer. (OUTPUT) */
106 /* = 0: Normal exit. */
107 /* = -1: Cannot generate a nontrivial restarted residual vector */
108 /* in the range of the operator OP. */
109
110 /* \EndDoc */
111
112 /* ----------------------------------------------------------------------- */
113
114 /* \BeginLib */
115
116 /* \Local variables: */
117 /* xxxxxx Complex*16 */
118
119 /* \References: */
120 /* 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in */
121 /* a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), */
122 /* pp 357-385. */
123
124 /* \Routines called: */
125 /* second ARPACK utility routine for timing. */
126 /* zvout ARPACK utility routine that prints vectors. */
127 /* zlarnv LAPACK routine for generating a random vector. */
128 /* zgemv Level 2 BLAS routine for matrix vector multiplication. */
129 /* zcopy Level 1 BLAS that copies one vector to another. */
130 /* zdotc Level 1 BLAS that computes the scalar product of two vectors. */
131 /* dznrm2 Level 1 BLAS that computes the norm of a vector. */
132
133 /* \Author */
134 /* Danny Sorensen Phuong Vu */
135 /* Richard Lehoucq CRPC / Rice University */
136 /* Dept. of Computational & Houston, Texas */
137 /* Applied Mathematics */
138 /* Rice University */
139 /* Houston, Texas */
140
141 /* \SCCS Information: @(#) */
142 /* FILE: getv0.F SID: 2.3 DATE OF SID: 08/27/96 RELEASE: 2 */
143
144 /* \EndLib */
145
146 /* ----------------------------------------------------------------------- */
147
148 /* Subroutine */ int zgetv0_(integer *ido, char *bmat, integer *itry, logical
149 *initv, integer *n, integer *j, doublecomplex *v, integer *ldv,
150 doublecomplex *resid, doublereal *rnorm, integer *ipntr,
151 doublecomplex *workd, integer *ierr, ftnlen bmat_len)
152 {
153 /* Initialized data */
154
155 static logical inits = TRUE_;
156
157 /* System generated locals */
158 integer v_dim1, v_offset, i__1, i__2;
159 doublereal d__1, d__2;
160 doublecomplex z__1;
161
162 /* Builtin functions */
163 double d_imag(doublecomplex *), sqrt(doublereal);
164
165 /* Local variables */
166 static real t0, t1, t2, t3;
167 static integer jj, iter;
168 static logical orth;
169 static integer iseed[4], idist;
170 static doublecomplex cnorm;
171 extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
172 doublecomplex *, integer *, doublecomplex *, integer *);
173 static logical first;
174 extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
175 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
176 integer *, doublecomplex *, doublecomplex *, integer *, ftnlen),
177 dvout_(integer *, integer *, doublereal *, integer *, char *,
178 ftnlen), zcopy_(integer *, doublecomplex *, integer *,
179 doublecomplex *, integer *), zvout_(integer *, integer *,
180 doublecomplex *, integer *, char *, ftnlen);
181 extern doublereal dlapy2_(doublereal *, doublereal *), dznrm2_(integer *,
182 doublecomplex *, integer *);
183 static doublereal rnorm0;
184 extern /* Subroutine */ int second_(real *);
185 static integer msglvl;
186 extern /* Subroutine */ int zlarnv_(integer *, integer *, integer *,
187 doublecomplex *);
188
189
190 /* %----------------------------------------------------% */
191 /* | Include files for debugging and timing information | */
192 /* %----------------------------------------------------% */
193
194
195 /* \SCCS Information: @(#) */
196 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
197
198 /* %---------------------------------% */
199 /* | See debug.doc for documentation | */
200 /* %---------------------------------% */
201
202 /* %------------------% */
203 /* | Scalar Arguments | */
204 /* %------------------% */
205
206 /* %--------------------------------% */
207 /* | See stat.doc for documentation | */
208 /* %--------------------------------% */
209
210 /* \SCCS Information: @(#) */
211 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
212
213
214
215 /* %-----------------% */
216 /* | Array Arguments | */
217 /* %-----------------% */
218
219
220 /* %------------% */
221 /* | Parameters | */
222 /* %------------% */
223
224
225 /* %------------------------% */
226 /* | Local Scalars & Arrays | */
227 /* %------------------------% */
228
229
230 /* %----------------------% */
231 /* | External Subroutines | */
232 /* %----------------------% */
233
234
235 /* %--------------------% */
236 /* | External Functions | */
237 /* %--------------------% */
238
239
240 /* %-----------------% */
241 /* | Data Statements | */
242 /* %-----------------% */
243
244 /* Parameter adjustments */
245 --workd;
246 --resid;
247 v_dim1 = *ldv;
248 v_offset = 1 + v_dim1;
249 v -= v_offset;
250 --ipntr;
251
252 /* Function Body */
253
254 /* %-----------------------% */
255 /* | Executable Statements | */
256 /* %-----------------------% */
257
258
259 /* %-----------------------------------% */
260 /* | Initialize the seed of the LAPACK | */
261 /* | random number generator | */
262 /* %-----------------------------------% */
263
264 if (inits) {
265 iseed[0] = 1;
266 iseed[1] = 3;
267 iseed[2] = 5;
268 iseed[3] = 7;
269 inits = FALSE_;
270 }
271
272 if (*ido == 0) {
273
274 /* %-------------------------------% */
275 /* | Initialize timing statistics | */
276 /* | & message level for debugging | */
277 /* %-------------------------------% */
278
279 second_(&t0);
280 msglvl = debug_1.mgetv0;
281
282 *ierr = 0;
283 iter = 0;
284 first = FALSE_;
285 orth = FALSE_;
286
287 /* %-----------------------------------------------------% */
288 /* | Possibly generate a random starting vector in RESID | */
289 /* | Use a LAPACK random number generator used by the | */
290 /* | matrix generation routines. | */
291 /* | idist = 1: uniform (0,1) distribution; | */
292 /* | idist = 2: uniform (-1,1) distribution; | */
293 /* | idist = 3: normal (0,1) distribution; | */
294 /* %-----------------------------------------------------% */
295
296 if (! (*initv)) {
297 idist = 2;
298 zlarnv_(&idist, iseed, n, &resid[1]);
299 }
300
301 /* %----------------------------------------------------------% */
302 /* | Force the starting vector into the range of OP to handle | */
303 /* | the generalized problem when B is possibly (singular). | */
304 /* %----------------------------------------------------------% */
305
306 second_(&t2);
307 if (*(unsigned char *)bmat == 'G') {
308 ++timing_1.nopx;
309 ipntr[1] = 1;
310 ipntr[2] = *n + 1;
311 zcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
312 *ido = -1;
313 goto L9000;
314 }
315 }
316
317 /* %----------------------------------------% */
318 /* | Back from computing B*(initial-vector) | */
319 /* %----------------------------------------% */
320
321 if (first) {
322 goto L20;
323 }
324
325 /* %-----------------------------------------------% */
326 /* | Back from computing B*(orthogonalized-vector) | */
327 /* %-----------------------------------------------% */
328
329 if (orth) {
330 goto L40;
331 }
332
333 second_(&t3);
334 timing_1.tmvopx += t3 - t2;
335
336 /* %------------------------------------------------------% */
337 /* | Starting vector is now in the range of OP; r = OP*r; | */
338 /* | Compute B-norm of starting vector. | */
339 /* %------------------------------------------------------% */
340
341 second_(&t2);
342 first = TRUE_;
343 if (*(unsigned char *)bmat == 'G') {
344 ++timing_1.nbx;
345 zcopy_(n, &workd[*n + 1], &c__1, &resid[1], &c__1);
346 ipntr[1] = *n + 1;
347 ipntr[2] = 1;
348 *ido = 2;
349 goto L9000;
350 } else if (*(unsigned char *)bmat == 'I') {
351 zcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
352 }
353
354 L20:
355
356 if (*(unsigned char *)bmat == 'G') {
357 second_(&t3);
358 timing_1.tmvbx += t3 - t2;
359 }
360
361 first = FALSE_;
362 if (*(unsigned char *)bmat == 'G') {
363 zdotc_(&z__1, n, &resid[1], &c__1, &workd[1], &c__1);
364 cnorm.r = z__1.r, cnorm.i = z__1.i;
365 d__1 = cnorm.r;
366 d__2 = d_imag(&cnorm);
367 rnorm0 = sqrt(dlapy2_(&d__1, &d__2));
368 } else if (*(unsigned char *)bmat == 'I') {
369 rnorm0 = dznrm2_(n, &resid[1], &c__1);
370 }
371 *rnorm = rnorm0;
372
373 /* %---------------------------------------------% */
374 /* | Exit if this is the very first Arnoldi step | */
375 /* %---------------------------------------------% */
376
377 if (*j == 1) {
378 goto L50;
379 }
380
381 /* %---------------------------------------------------------------- */
382 /* | Otherwise need to B-orthogonalize the starting vector against | */
383 /* | the current Arnoldi basis using Gram-Schmidt with iter. ref. | */
384 /* | This is the case where an invariant subspace is encountered | */
385 /* | in the middle of the Arnoldi factorization. | */
386 /* | | */
387 /* | s = V^{T}*B*r; r = r - V*s; | */
388 /* | | */
389 /* | Stopping criteria used for iter. ref. is discussed in | */
390 /* | Parlett's book, page 107 and in Gragg & Reichel TOMS paper. | */
391 /* %---------------------------------------------------------------% */
392
393 orth = TRUE_;
394 L30:
395
396 i__1 = *j - 1;
397 zgemv_("C", n, &i__1, &c_b1, &v[v_offset], ldv, &workd[1], &c__1, &c_b2, &
398 workd[*n + 1], &c__1, (ftnlen)1);
399 i__1 = *j - 1;
400 z__1.r = -1., z__1.i = -0.;
401 zgemv_("N", n, &i__1, &z__1, &v[v_offset], ldv, &workd[*n + 1], &c__1, &
402 c_b1, &resid[1], &c__1, (ftnlen)1);
403
404 /* %----------------------------------------------------------% */
405 /* | Compute the B-norm of the orthogonalized starting vector | */
406 /* %----------------------------------------------------------% */
407
408 second_(&t2);
409 if (*(unsigned char *)bmat == 'G') {
410 ++timing_1.nbx;
411 zcopy_(n, &resid[1], &c__1, &workd[*n + 1], &c__1);
412 ipntr[1] = *n + 1;
413 ipntr[2] = 1;
414 *ido = 2;
415 goto L9000;
416 } else if (*(unsigned char *)bmat == 'I') {
417 zcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
418 }
419
420 L40:
421
422 if (*(unsigned char *)bmat == 'G') {
423 second_(&t3);
424 timing_1.tmvbx += t3 - t2;
425 }
426
427 if (*(unsigned char *)bmat == 'G') {
428 zdotc_(&z__1, n, &resid[1], &c__1, &workd[1], &c__1);
429 cnorm.r = z__1.r, cnorm.i = z__1.i;
430 d__1 = cnorm.r;
431 d__2 = d_imag(&cnorm);
432 *rnorm = sqrt(dlapy2_(&d__1, &d__2));
433 } else if (*(unsigned char *)bmat == 'I') {
434 *rnorm = dznrm2_(n, &resid[1], &c__1);
435 }
436
437 /* %--------------------------------------% */
438 /* | Check for further orthogonalization. | */
439 /* %--------------------------------------% */
440
441 if (msglvl > 2) {
442 dvout_(&debug_1.logfil, &c__1, &rnorm0, &debug_1.ndigit, "_getv0: re"
443 "-orthonalization ; rnorm0 is", (ftnlen)38);
444 dvout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: re-o"
445 "rthonalization ; rnorm is", (ftnlen)37);
446 }
447
448 if (*rnorm > rnorm0 * .717f) {
449 goto L50;
450 }
451
452 ++iter;
453 if (iter <= 1) {
454
455 /* %-----------------------------------% */
456 /* | Perform iterative refinement step | */
457 /* %-----------------------------------% */
458
459 rnorm0 = *rnorm;
460 goto L30;
461 } else {
462
463 /* %------------------------------------% */
464 /* | Iterative refinement step "failed" | */
465 /* %------------------------------------% */
466
467 i__1 = *n;
468 for (jj = 1; jj <= i__1; ++jj) {
469 i__2 = jj;
470 resid[i__2].r = 0., resid[i__2].i = 0.;
471 /* L45: */
472 }
473 *rnorm = 0.;
474 *ierr = -1;
475 }
476
477 L50:
478
479 if (msglvl > 0) {
480 dvout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: B-no"
481 "rm of initial / restarted starting vector", (ftnlen)53);
482 }
483 if (msglvl > 2) {
484 zvout_(&debug_1.logfil, n, &resid[1], &debug_1.ndigit, "_getv0: init"
485 "ial / restarted starting vector", (ftnlen)43);
486 }
487 *ido = 99;
488
489 second_(&t1);
490 timing_1.tgetv0 += t1 - t0;
491
492 L9000:
493 return 0;
494
495 /* %---------------% */
496 /* | End of zgetv0 | */
497 /* %---------------% */
498
499 } /* zgetv0_ */
500