Debian Codegraph @

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

raw
1 /* ./src_f77/znaup2.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_ZNAUP2;
15
16 #define debug_1 debug_ZNAUP2
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_ZNAUP2;
25
26 #define timing_1 timing_ZNAUP2
27
28 /* Table of constant values */
29
30 static doublereal c_b5 = .66666666666666663;
31 static integer c__1 = 1;
32 static integer c__0 = 0;
33 static integer c__3 = 3;
34 static logical c_true = TRUE_;
35 static integer c__2 = 2;
36
37 /* \BeginDoc */
38
39 /* \Name: znaup2 */
40
41 /* \Description: */
42 /* Intermediate level interface called by znaupd . */
43
44 /* \Usage: */
45 /* call znaup2 */
46 /* ( IDO, BMAT, N, WHICH, NEV, NP, TOL, RESID, MODE, IUPD, */
47 /* ISHIFT, MXITER, V, LDV, H, LDH, RITZ, BOUNDS, */
48 /* Q, LDQ, WORKL, IPNTR, WORKD, RWORK, INFO ) */
49
50 /* \Arguments */
51
52 /* IDO, BMAT, N, WHICH, NEV, TOL, RESID: same as defined in znaupd . */
53 /* MODE, ISHIFT, MXITER: see the definition of IPARAM in znaupd . */
54
55 /* NP Integer. (INPUT/OUTPUT) */
56 /* Contains the number of implicit shifts to apply during */
57 /* each Arnoldi iteration. */
58 /* If ISHIFT=1, NP is adjusted dynamically at each iteration */
59 /* to accelerate convergence and prevent stagnation. */
60 /* This is also roughly equal to the number of matrix-vector */
61 /* products (involving the operator OP) per Arnoldi iteration. */
62 /* The logic for adjusting is contained within the current */
63 /* subroutine. */
64 /* If ISHIFT=0, NP is the number of shifts the user needs */
65 /* to provide via reverse comunication. 0 < NP < NCV-NEV. */
66 /* NP may be less than NCV-NEV since a leading block of the current */
67 /* upper Hessenberg matrix has split off and contains "unwanted" */
68 /* Ritz values. */
69 /* Upon termination of the IRA iteration, NP contains the number */
70 /* of "converged" wanted Ritz values. */
71
72 /* IUPD Integer. (INPUT) */
73 /* IUPD .EQ. 0: use explicit restart instead implicit update. */
74 /* IUPD .NE. 0: use implicit update. */
75
76 /* V Complex*16 N by (NEV+NP) array. (INPUT/OUTPUT) */
77 /* The Arnoldi basis vectors are returned in the first NEV */
78 /* columns of V. */
79
80 /* LDV Integer. (INPUT) */
81 /* Leading dimension of V exactly as declared in the calling */
82 /* program. */
83
84 /* H Complex*16 (NEV+NP) by (NEV+NP) array. (OUTPUT) */
85 /* H is used to store the generated upper Hessenberg matrix */
86
87 /* LDH Integer. (INPUT) */
88 /* Leading dimension of H exactly as declared in the calling */
89 /* program. */
90
91 /* RITZ Complex*16 array of length NEV+NP. (OUTPUT) */
92 /* RITZ(1:NEV) contains the computed Ritz values of OP. */
93
94 /* BOUNDS Complex*16 array of length NEV+NP. (OUTPUT) */
95 /* BOUNDS(1:NEV) contain the error bounds corresponding to */
96 /* the computed Ritz values. */
97
98 /* Q Complex*16 (NEV+NP) by (NEV+NP) array. (WORKSPACE) */
99 /* Private (replicated) work array used to accumulate the */
100 /* rotation in the shift application step. */
101
102 /* LDQ Integer. (INPUT) */
103 /* Leading dimension of Q exactly as declared in the calling */
104 /* program. */
105
106 /* WORKL Complex*16 work array of length at least */
107 /* (NEV+NP)**2 + 3*(NEV+NP). (WORKSPACE) */
108 /* Private (replicated) array on each PE or array allocated on */
109 /* the front end. It is used in shifts calculation, shifts */
110 /* application and convergence checking. */
111
112
113 /* IPNTR Integer array of length 3. (OUTPUT) */
114 /* Pointer to mark the starting locations in the WORKD for */
115 /* vectors used by the Arnoldi iteration. */
116 /* ------------------------------------------------------------- */
117 /* IPNTR(1): pointer to the current operand vector X. */
118 /* IPNTR(2): pointer to the current result vector Y. */
119 /* IPNTR(3): pointer to the vector B * X when used in the */
120 /* shift-and-invert mode. X is the current operand. */
121 /* ------------------------------------------------------------- */
122
123 /* WORKD Complex*16 work array of length 3*N. (WORKSPACE) */
124 /* Distributed array to be used in the basic Arnoldi iteration */
125 /* for reverse communication. The user should not use WORKD */
126 /* as temporary workspace during the iteration !!!!!!!!!! */
127 /* See Data Distribution Note in ZNAUPD . */
128
129 /* RWORK Double precision work array of length NEV+NP ( WORKSPACE) */
130 /* Private (replicated) array on each PE or array allocated on */
131 /* the front end. */
132
133 /* INFO Integer. (INPUT/OUTPUT) */
134 /* If INFO .EQ. 0, a randomly initial residual vector is used. */
135 /* If INFO .NE. 0, RESID contains the initial residual vector, */
136 /* possibly from a previous run. */
137 /* Error flag on output. */
138 /* = 0: Normal return. */
139 /* = 1: Maximum number of iterations taken. */
140 /* All possible eigenvalues of OP has been found. */
141 /* NP returns the number of converged Ritz values. */
142 /* = 2: No shifts could be applied. */
143 /* = -8: Error return from LAPACK eigenvalue calculation; */
144 /* This should never happen. */
145 /* = -9: Starting vector is zero. */
146 /* = -9999: Could not build an Arnoldi factorization. */
147 /* Size that was built in returned in NP. */
148
149 /* \EndDoc */
150
151 /* ----------------------------------------------------------------------- */
152
153 /* \BeginLib */
154
155 /* \Local variables: */
156 /* xxxxxx Complex*16 */
157
158 /* \References: */
159 /* 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in */
160 /* a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), */
161 /* pp 357-385. */
162 /* 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly */
163 /* Restarted Arnoldi Iteration", Rice University Technical Report */
164 /* TR95-13, Department of Computational and Applied Mathematics. */
165
166 /* \Routines called: */
167 /* zgetv0 ARPACK initial vector generation routine. */
168 /* znaitr ARPACK Arnoldi factorization routine. */
169 /* znapps ARPACK application of implicit shifts routine. */
170 /* zneigh ARPACK compute Ritz values and error bounds routine. */
171 /* zngets ARPACK reorder Ritz values and error bounds routine. */
172 /* zsortc ARPACK sorting routine. */
173 /* ivout ARPACK utility routine that prints integers. */
174 /* second ARPACK utility routine for timing. */
175 /* zmout ARPACK utility routine that prints matrices */
176 /* zvout ARPACK utility routine that prints vectors. */
177 /* dvout ARPACK utility routine that prints vectors. */
178 /* dlamch LAPACK routine that determines machine constants. */
179 /* dlapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully. */
180 /* zcopy Level 1 BLAS that copies one vector to another . */
181 /* zdotc Level 1 BLAS that computes the scalar product of two vectors. */
182 /* zswap Level 1 BLAS that swaps two vectors. */
183 /* dznrm2 Level 1 BLAS that computes the norm of a vector. */
184
185 /* \Author */
186 /* Danny Sorensen Phuong Vu */
187 /* Richard Lehoucq CRPC / Rice Universitya */
188 /* Chao Yang Houston, Texas */
189 /* Dept. of Computational & */
190 /* Applied Mathematics */
191 /* Rice University */
192 /* Houston, Texas */
193
194 /* \SCCS Information: @(#) */
195 /* FILE: naup2.F SID: 2.6 DATE OF SID: 06/01/00 RELEASE: 2 */
196
197 /* \Remarks */
198 /* 1. None */
199
200 /* \EndLib */
201
202 /* ----------------------------------------------------------------------- */
203
204 /* Subroutine */ int znaup2_(integer *ido, char *bmat, integer *n, char *
205 which, integer *nev, integer *np, doublereal *tol, doublecomplex *
206 resid, integer *mode, integer *iupd, integer *ishift, integer *mxiter,
207 doublecomplex *v, integer *ldv, doublecomplex *h__, integer *ldh,
208 doublecomplex *ritz, doublecomplex *bounds, doublecomplex *q, integer
209 *ldq, doublecomplex *workl, integer *ipntr, doublecomplex *workd,
210 doublereal *rwork, integer *info, ftnlen bmat_len, ftnlen which_len)
211 {
212 /* System generated locals */
213 integer h_dim1, h_offset, q_dim1, q_offset, v_dim1, v_offset, i__1, i__2,
214 i__3;
215 doublereal d__1, d__2, d__3, d__4;
216 doublecomplex z__1;
217
218 /* Builtin functions */
219 double pow_dd(doublereal *, doublereal *), d_imag(doublecomplex *);
220 integer s_cmp(char *, char *, ftnlen, ftnlen);
221 /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
222 double sqrt(doublereal);
223
224 /* Local variables */
225 static integer i__, j;
226 static real t0, t1, t2, t3;
227 static integer kp[3], np0, nev0;
228 static doublereal eps23;
229 static integer ierr, iter;
230 static logical getv0, cnorm;
231 static integer nconv;
232 extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
233 doublecomplex *, integer *, doublecomplex *, integer *);
234 static doublereal rtemp;
235 static logical initv;
236 static doublereal rnorm;
237 extern /* Subroutine */ int dvout_(integer *, integer *, doublereal *,
238 integer *, char *, ftnlen), zcopy_(integer *, doublecomplex *,
239 integer *, doublecomplex *, integer *), ivout_(integer *, integer
240 *, integer *, integer *, char *, ftnlen), zmout_(integer *,
241 integer *, integer *, doublecomplex *, integer *, integer *, char
242 *, ftnlen), zvout_(integer *, integer *, doublecomplex *, integer
243 *, char *, ftnlen);
244 extern doublereal dlapy2_(doublereal *, doublereal *), dznrm2_(integer *,
245 doublecomplex *, integer *);
246 extern /* Subroutine */ int zgetv0_(integer *, char *, integer *, logical
247 *, integer *, integer *, doublecomplex *, integer *,
248 doublecomplex *, doublereal *, integer *, doublecomplex *,
249 integer *, ftnlen);
250 extern doublereal dlamch_(char *, ftnlen);
251 static integer nevbef;
252 extern /* Subroutine */ int second_(real *);
253 static logical update, ushift;
254 static integer kplusp, msglvl, nptemp;
255 static char wprime[2];
256 extern /* Subroutine */ int znaitr_(integer *, char *, integer *, integer
257 *, integer *, integer *, doublecomplex *, doublereal *,
258 doublecomplex *, integer *, doublecomplex *, integer *, integer *,
259 doublecomplex *, integer *, ftnlen), zneigh_(doublereal *,
260 integer *, doublecomplex *, integer *, doublecomplex *,
261 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
262 doublereal *, integer *), zngets_(integer *, char *, integer *,
263 integer *, doublecomplex *, doublecomplex *, ftnlen), znapps_(
264 integer *, integer *, integer *, doublecomplex *, doublecomplex *,
265 integer *, doublecomplex *, integer *, doublecomplex *,
266 doublecomplex *, integer *, doublecomplex *, doublecomplex *),
267 zsortc_(char *, logical *, integer *, doublecomplex *,
268 doublecomplex *, ftnlen);
269 static doublecomplex cmpnorm;
270
271
272 /* %----------------------------------------------------% */
273 /* | Include files for debugging and timing information | */
274 /* %----------------------------------------------------% */
275
276
277 /* \SCCS Information: @(#) */
278 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
279
280 /* %---------------------------------% */
281 /* | See debug.doc for documentation | */
282 /* %---------------------------------% */
283
284 /* %------------------% */
285 /* | Scalar Arguments | */
286 /* %------------------% */
287
288 /* %--------------------------------% */
289 /* | See stat.doc for documentation | */
290 /* %--------------------------------% */
291
292 /* \SCCS Information: @(#) */
293 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
294
295
296
297 /* %-----------------% */
298 /* | Array Arguments | */
299 /* %-----------------% */
300
301
302 /* %------------% */
303 /* | Parameters | */
304 /* %------------% */
305
306
307 /* %---------------% */
308 /* | Local Scalars | */
309 /* %---------------% */
310
311
312
313
314 /* %-----------------------% */
315 /* | Local array arguments | */
316 /* %-----------------------% */
317
318
319 /* %----------------------% */
320 /* | External Subroutines | */
321 /* %----------------------% */
322
323
324 /* %--------------------% */
325 /* | External functions | */
326 /* %--------------------% */
327
328
329 /* %---------------------% */
330 /* | Intrinsic Functions | */
331 /* %---------------------% */
332
333
334 /* %-----------------------% */
335 /* | Executable Statements | */
336 /* %-----------------------% */
337
338 /* Parameter adjustments */
339 --workd;
340 --resid;
341 --rwork;
342 --workl;
343 --bounds;
344 --ritz;
345 v_dim1 = *ldv;
346 v_offset = 1 + v_dim1;
347 v -= v_offset;
348 h_dim1 = *ldh;
349 h_offset = 1 + h_dim1;
350 h__ -= h_offset;
351 q_dim1 = *ldq;
352 q_offset = 1 + q_dim1;
353 q -= q_offset;
354 --ipntr;
355
356 /* Function Body */
357 if (*ido == 0) {
358
359 second_(&t0);
360
361 msglvl = debug_1.mcaup2;
362
363 nev0 = *nev;
364 np0 = *np;
365
366 /* %-------------------------------------% */
367 /* | kplusp is the bound on the largest | */
368 /* | Lanczos factorization built. | */
369 /* | nconv is the current number of | */
370 /* | "converged" eigenvalues. | */
371 /* | iter is the counter on the current | */
372 /* | iteration step. | */
373 /* %-------------------------------------% */
374
375 kplusp = *nev + *np;
376 nconv = 0;
377 iter = 0;
378
379 /* %---------------------------------% */
380 /* | Get machine dependent constant. | */
381 /* %---------------------------------% */
382
383 eps23 = dlamch_("Epsilon-Machine", (ftnlen)15);
384 eps23 = pow_dd(&eps23, &c_b5);
385
386 /* %---------------------------------------% */
387 /* | Set flags for computing the first NEV | */
388 /* | steps of the Arnoldi factorization. | */
389 /* %---------------------------------------% */
390
391 getv0 = TRUE_;
392 update = FALSE_;
393 ushift = FALSE_;
394 cnorm = FALSE_;
395
396 if (*info != 0) {
397
398 /* %--------------------------------------------% */
399 /* | User provides the initial residual vector. | */
400 /* %--------------------------------------------% */
401
402 initv = TRUE_;
403 *info = 0;
404 } else {
405 initv = FALSE_;
406 }
407 }
408
409 /* %---------------------------------------------% */
410 /* | Get a possibly random starting vector and | */
411 /* | force it into the range of the operator OP. | */
412 /* %---------------------------------------------% */
413
414 /* L10: */
415
416 if (getv0) {
417 zgetv0_(ido, bmat, &c__1, &initv, n, &c__1, &v[v_offset], ldv, &resid[
418 1], &rnorm, &ipntr[1], &workd[1], info, (ftnlen)1);
419
420 if (*ido != 99) {
421 goto L9000;
422 }
423
424 if (rnorm == 0.) {
425
426 /* %-----------------------------------------% */
427 /* | The initial vector is zero. Error exit. | */
428 /* %-----------------------------------------% */
429
430 *info = -9;
431 goto L1100;
432 }
433 getv0 = FALSE_;
434 *ido = 0;
435 }
436
437 /* %-----------------------------------% */
438 /* | Back from reverse communication : | */
439 /* | continue with update step | */
440 /* %-----------------------------------% */
441
442 if (update) {
443 goto L20;
444 }
445
446 /* %-------------------------------------------% */
447 /* | Back from computing user specified shifts | */
448 /* %-------------------------------------------% */
449
450 if (ushift) {
451 goto L50;
452 }
453
454 /* %-------------------------------------% */
455 /* | Back from computing residual norm | */
456 /* | at the end of the current iteration | */
457 /* %-------------------------------------% */
458
459 if (cnorm) {
460 goto L100;
461 }
462
463 /* %----------------------------------------------------------% */
464 /* | Compute the first NEV steps of the Arnoldi factorization | */
465 /* %----------------------------------------------------------% */
466
467 znaitr_(ido, bmat, n, &c__0, nev, mode, &resid[1], &rnorm, &v[v_offset],
468 ldv, &h__[h_offset], ldh, &ipntr[1], &workd[1], info, (ftnlen)1);
469
470 if (*ido != 99) {
471 goto L9000;
472 }
473
474 if (*info > 0) {
475 *np = *info;
476 *mxiter = iter;
477 *info = -9999;
478 goto L1200;
479 }
480
481 /* %--------------------------------------------------------------% */
482 /* | | */
483 /* | M A I N ARNOLDI I T E R A T I O N L O O P | */
484 /* | Each iteration implicitly restarts the Arnoldi | */
485 /* | factorization in place. | */
486 /* | | */
487 /* %--------------------------------------------------------------% */
488
489 L1000:
490
491 ++iter;
492
493 if (msglvl > 0) {
494 ivout_(&debug_1.logfil, &c__1, &iter, &debug_1.ndigit, "_naup2: ****"
495 " Start of major iteration number ****", (ftnlen)49);
496 }
497
498 /* %-----------------------------------------------------------% */
499 /* | Compute NP additional steps of the Arnoldi factorization. | */
500 /* | Adjust NP since NEV might have been updated by last call | */
501 /* | to the shift application routine znapps . | */
502 /* %-----------------------------------------------------------% */
503
504 *np = kplusp - *nev;
505
506 if (msglvl > 1) {
507 ivout_(&debug_1.logfil, &c__1, nev, &debug_1.ndigit, "_naup2: The le"
508 "ngth of the current Arnoldi factorization", (ftnlen)55);
509 ivout_(&debug_1.logfil, &c__1, np, &debug_1.ndigit, "_naup2: Extend "
510 "the Arnoldi factorization by", (ftnlen)43);
511 }
512
513 /* %-----------------------------------------------------------% */
514 /* | Compute NP additional steps of the Arnoldi factorization. | */
515 /* %-----------------------------------------------------------% */
516
517 *ido = 0;
518 L20:
519 update = TRUE_;
520
521 znaitr_(ido, bmat, n, nev, np, mode, &resid[1], &rnorm, &v[v_offset], ldv,
522 &h__[h_offset], ldh, &ipntr[1], &workd[1], info, (ftnlen)1);
523
524 if (*ido != 99) {
525 goto L9000;
526 }
527
528 if (*info > 0) {
529 *np = *info;
530 *mxiter = iter;
531 *info = -9999;
532 goto L1200;
533 }
534 update = FALSE_;
535
536 if (msglvl > 1) {
537 dvout_(&debug_1.logfil, &c__1, &rnorm, &debug_1.ndigit, "_naup2: Cor"
538 "responding B-norm of the residual", (ftnlen)44);
539 }
540
541 /* %--------------------------------------------------------% */
542 /* | Compute the eigenvalues and corresponding error bounds | */
543 /* | of the current upper Hessenberg matrix. | */
544 /* %--------------------------------------------------------% */
545
546 zneigh_(&rnorm, &kplusp, &h__[h_offset], ldh, &ritz[1], &bounds[1], &q[
547 q_offset], ldq, &workl[1], &rwork[1], &ierr);
548
549 if (ierr != 0) {
550 *info = -8;
551 goto L1200;
552 }
553
554 /* %---------------------------------------------------% */
555 /* | Select the wanted Ritz values and their bounds | */
556 /* | to be used in the convergence test. | */
557 /* | The wanted part of the spectrum and corresponding | */
558 /* | error bounds are in the last NEV loc. of RITZ, | */
559 /* | and BOUNDS respectively. | */
560 /* %---------------------------------------------------% */
561
562 *nev = nev0;
563 *np = np0;
564
565 /* %--------------------------------------------------% */
566 /* | Make a copy of Ritz values and the corresponding | */
567 /* | Ritz estimates obtained from zneigh . | */
568 /* %--------------------------------------------------% */
569
570 /* Computing 2nd power */
571 i__1 = kplusp;
572 zcopy_(&kplusp, &ritz[1], &c__1, &workl[i__1 * i__1 + 1], &c__1);
573 /* Computing 2nd power */
574 i__1 = kplusp;
575 zcopy_(&kplusp, &bounds[1], &c__1, &workl[i__1 * i__1 + kplusp + 1], &
576 c__1);
577
578 /* %---------------------------------------------------% */
579 /* | Select the wanted Ritz values and their bounds | */
580 /* | to be used in the convergence test. | */
581 /* | The wanted part of the spectrum and corresponding | */
582 /* | bounds are in the last NEV loc. of RITZ | */
583 /* | BOUNDS respectively. | */
584 /* %---------------------------------------------------% */
585
586 zngets_(ishift, which, nev, np, &ritz[1], &bounds[1], (ftnlen)2);
587
588 /* %------------------------------------------------------------% */
589 /* | Convergence test: currently we use the following criteria. | */
590 /* | The relative accuracy of a Ritz value is considered | */
591 /* | acceptable if: | */
592 /* | | */
593 /* | error_bounds(i) .le. tol*max(eps23, magnitude_of_ritz(i)). | */
594 /* | | */
595 /* %------------------------------------------------------------% */
596
597 nconv = 0;
598
599 i__1 = *nev;
600 for (i__ = 1; i__ <= i__1; ++i__) {
601 /* Computing MAX */
602 i__2 = *np + i__;
603 d__3 = ritz[i__2].r;
604 d__4 = d_imag(&ritz[*np + i__]);
605 d__1 = eps23, d__2 = dlapy2_(&d__3, &d__4);
606 rtemp = max(d__1,d__2);
607 i__2 = *np + i__;
608 d__1 = bounds[i__2].r;
609 d__2 = d_imag(&bounds[*np + i__]);
610 if (dlapy2_(&d__1, &d__2) <= *tol * rtemp) {
611 ++nconv;
612 }
613 /* L25: */
614 }
615
616 if (msglvl > 2) {
617 kp[0] = *nev;
618 kp[1] = *np;
619 kp[2] = nconv;
620 ivout_(&debug_1.logfil, &c__3, kp, &debug_1.ndigit, "_naup2: NEV, NP"
621 ", NCONV are", (ftnlen)26);
622 zvout_(&debug_1.logfil, &kplusp, &ritz[1], &debug_1.ndigit, "_naup2:"
623 " The eigenvalues of H", (ftnlen)28);
624 zvout_(&debug_1.logfil, &kplusp, &bounds[1], &debug_1.ndigit, "_naup"
625 "2: Ritz estimates of the current NCV Ritz values", (ftnlen)53)
626 ;
627 }
628
629 /* %---------------------------------------------------------% */
630 /* | Count the number of unwanted Ritz values that have zero | */
631 /* | Ritz estimates. If any Ritz estimates are equal to zero | */
632 /* | then a leading block of H of order equal to at least | */
633 /* | the number of Ritz values with zero Ritz estimates has | */
634 /* | split off. None of these Ritz values may be removed by | */
635 /* | shifting. Decrease NP the number of shifts to apply. If | */
636 /* | no shifts may be applied, then prepare to exit | */
637 /* %---------------------------------------------------------% */
638
639 nptemp = *np;
640 i__1 = nptemp;
641 for (j = 1; j <= i__1; ++j) {
642 i__2 = j;
643 if (bounds[i__2].r == 0. && bounds[i__2].i == 0.) {
644 --(*np);
645 ++(*nev);
646 }
647 /* L30: */
648 }
649
650 if (nconv >= nev0 || iter > *mxiter || *np == 0) {
651
652 if (msglvl > 4) {
653 /* Computing 2nd power */
654 i__1 = kplusp;
655 zvout_(&debug_1.logfil, &kplusp, &workl[i__1 * i__1 + 1], &
656 debug_1.ndigit, "_naup2: Eigenvalues computed by _neigh:",
657 (ftnlen)39);
658 /* Computing 2nd power */
659 i__1 = kplusp;
660 zvout_(&debug_1.logfil, &kplusp, &workl[i__1 * i__1 + kplusp + 1],
661 &debug_1.ndigit, "_naup2: Ritz estimates computed by _n"
662 "eigh:", (ftnlen)42);
663 }
664
665 /* %------------------------------------------------% */
666 /* | Prepare to exit. Put the converged Ritz values | */
667 /* | and corresponding bounds in RITZ(1:NCONV) and | */
668 /* | BOUNDS(1:NCONV) respectively. Then sort. Be | */
669 /* | careful when NCONV > NP | */
670 /* %------------------------------------------------% */
671
672 /* %------------------------------------------% */
673 /* | Use h( 3,1 ) as storage to communicate | */
674 /* | rnorm to zneupd if needed | */
675 /* %------------------------------------------% */
676 i__1 = h_dim1 + 3;
677 z__1.r = rnorm, z__1.i = 0.;
678 h__[i__1].r = z__1.r, h__[i__1].i = z__1.i;
679
680 /* %----------------------------------------------% */
681 /* | Sort Ritz values so that converged Ritz | */
682 /* | values appear within the first NEV locations | */
683 /* | of ritz and bounds, and the most desired one | */
684 /* | appears at the front. | */
685 /* %----------------------------------------------% */
686
687 if (s_cmp(which, "LM", (ftnlen)2, (ftnlen)2) == 0) {
688 s_copy(wprime, "SM", (ftnlen)2, (ftnlen)2);
689 }
690 if (s_cmp(which, "SM", (ftnlen)2, (ftnlen)2) == 0) {
691 s_copy(wprime, "LM", (ftnlen)2, (ftnlen)2);
692 }
693 if (s_cmp(which, "LR", (ftnlen)2, (ftnlen)2) == 0) {
694 s_copy(wprime, "SR", (ftnlen)2, (ftnlen)2);
695 }
696 if (s_cmp(which, "SR", (ftnlen)2, (ftnlen)2) == 0) {
697 s_copy(wprime, "LR", (ftnlen)2, (ftnlen)2);
698 }
699 if (s_cmp(which, "LI", (ftnlen)2, (ftnlen)2) == 0) {
700 s_copy(wprime, "SI", (ftnlen)2, (ftnlen)2);
701 }
702 if (s_cmp(which, "SI", (ftnlen)2, (ftnlen)2) == 0) {
703 s_copy(wprime, "LI", (ftnlen)2, (ftnlen)2);
704 }
705
706 zsortc_(wprime, &c_true, &kplusp, &ritz[1], &bounds[1], (ftnlen)2);
707
708 /* %--------------------------------------------------% */
709 /* | Scale the Ritz estimate of each Ritz value | */
710 /* | by 1 / max(eps23, magnitude of the Ritz value). | */
711 /* %--------------------------------------------------% */
712
713 i__1 = nev0;
714 for (j = 1; j <= i__1; ++j) {
715 /* Computing MAX */
716 i__2 = j;
717 d__3 = ritz[i__2].r;
718 d__4 = d_imag(&ritz[j]);
719 d__1 = eps23, d__2 = dlapy2_(&d__3, &d__4);
720 rtemp = max(d__1,d__2);
721 i__2 = j;
722 i__3 = j;
723 z__1.r = bounds[i__3].r / rtemp, z__1.i = bounds[i__3].i / rtemp;
724 bounds[i__2].r = z__1.r, bounds[i__2].i = z__1.i;
725 /* L35: */
726 }
727
728 /* %---------------------------------------------------% */
729 /* | Sort the Ritz values according to the scaled Ritz | */
730 /* | estimates. This will push all the converged ones | */
731 /* | towards the front of ritz, bounds (in the case | */
732 /* | when NCONV < NEV.) | */
733 /* %---------------------------------------------------% */
734
735 s_copy(wprime, "LM", (ftnlen)2, (ftnlen)2);
736 zsortc_(wprime, &c_true, &nev0, &bounds[1], &ritz[1], (ftnlen)2);
737
738 /* %----------------------------------------------% */
739 /* | Scale the Ritz estimate back to its original | */
740 /* | value. | */
741 /* %----------------------------------------------% */
742
743 i__1 = nev0;
744 for (j = 1; j <= i__1; ++j) {
745 /* Computing MAX */
746 i__2 = j;
747 d__3 = ritz[i__2].r;
748 d__4 = d_imag(&ritz[j]);
749 d__1 = eps23, d__2 = dlapy2_(&d__3, &d__4);
750 rtemp = max(d__1,d__2);
751 i__2 = j;
752 i__3 = j;
753 z__1.r = rtemp * bounds[i__3].r, z__1.i = rtemp * bounds[i__3].i;
754 bounds[i__2].r = z__1.r, bounds[i__2].i = z__1.i;
755 /* L40: */
756 }
757
758 /* %-----------------------------------------------% */
759 /* | Sort the converged Ritz values again so that | */
760 /* | the "threshold" value appears at the front of | */
761 /* | ritz and bound. | */
762 /* %-----------------------------------------------% */
763
764 zsortc_(which, &c_true, &nconv, &ritz[1], &bounds[1], (ftnlen)2);
765
766 if (msglvl > 1) {
767 zvout_(&debug_1.logfil, &kplusp, &ritz[1], &debug_1.ndigit, "_na"
768 "up2: Sorted eigenvalues", (ftnlen)26);
769 zvout_(&debug_1.logfil, &kplusp, &bounds[1], &debug_1.ndigit,
770 "_naup2: Sorted ritz estimates.", (ftnlen)30);
771 }
772
773 /* %------------------------------------% */
774 /* | Max iterations have been exceeded. | */
775 /* %------------------------------------% */
776
777 if (iter > *mxiter && nconv < nev0) {
778 *info = 1;
779 }
780
781 /* %---------------------% */
782 /* | No shifts to apply. | */
783 /* %---------------------% */
784
785 if (*np == 0 && nconv < nev0) {
786 *info = 2;
787 }
788
789 *np = nconv;
790 goto L1100;
791
792 } else if (nconv < nev0 && *ishift == 1) {
793
794 /* %-------------------------------------------------% */
795 /* | Do not have all the requested eigenvalues yet. | */
796 /* | To prevent possible stagnation, adjust the size | */
797 /* | of NEV. | */
798 /* %-------------------------------------------------% */
799
800 nevbef = *nev;
801 /* Computing MIN */
802 i__1 = nconv, i__2 = *np / 2;
803 *nev += min(i__1,i__2);
804 if (*nev == 1 && kplusp >= 6) {
805 *nev = kplusp / 2;
806 } else if (*nev == 1 && kplusp > 3) {
807 *nev = 2;
808 }
809 *np = kplusp - *nev;
810
811 /* %---------------------------------------% */
812 /* | If the size of NEV was just increased | */
813 /* | resort the eigenvalues. | */
814 /* %---------------------------------------% */
815
816 if (nevbef < *nev) {
817 zngets_(ishift, which, nev, np, &ritz[1], &bounds[1], (ftnlen)2);
818 }
819
820 }
821
822 if (msglvl > 0) {
823 ivout_(&debug_1.logfil, &c__1, &nconv, &debug_1.ndigit, "_naup2: no."
824 " of \"converged\" Ritz values at this iter.", (ftnlen)52);
825 if (msglvl > 1) {
826 kp[0] = *nev;
827 kp[1] = *np;
828 ivout_(&debug_1.logfil, &c__2, kp, &debug_1.ndigit, "_naup2: NEV"
829 " and NP are", (ftnlen)22);
830 zvout_(&debug_1.logfil, nev, &ritz[*np + 1], &debug_1.ndigit,
831 "_naup2: \"wanted\" Ritz values ", (ftnlen)29);
832 zvout_(&debug_1.logfil, nev, &bounds[*np + 1], &debug_1.ndigit,
833 "_naup2: Ritz estimates of the \"wanted\" values ", (
834 ftnlen)46);
835 }
836 }
837
838 if (*ishift == 0) {
839
840 /* %-------------------------------------------------------% */
841 /* | User specified shifts: pop back out to get the shifts | */
842 /* | and return them in the first 2*NP locations of WORKL. | */
843 /* %-------------------------------------------------------% */
844
845 ushift = TRUE_;
846 *ido = 3;
847 goto L9000;
848 }
849 L50:
850 ushift = FALSE_;
851
852 if (*ishift != 1) {
853
854 /* %----------------------------------% */
855 /* | Move the NP shifts from WORKL to | */
856 /* | RITZ, to free up WORKL | */
857 /* | for non-exact shift case. | */
858 /* %----------------------------------% */
859
860 zcopy_(np, &workl[1], &c__1, &ritz[1], &c__1);
861 }
862
863 if (msglvl > 2) {
864 ivout_(&debug_1.logfil, &c__1, np, &debug_1.ndigit, "_naup2: The num"
865 "ber of shifts to apply ", (ftnlen)38);
866 zvout_(&debug_1.logfil, np, &ritz[1], &debug_1.ndigit, "_naup2: valu"
867 "es of the shifts", (ftnlen)28);
868 if (*ishift == 1) {
869 zvout_(&debug_1.logfil, np, &bounds[1], &debug_1.ndigit, "_naup2"
870 ": Ritz estimates of the shifts", (ftnlen)36);
871 }
872 }
873
874 /* %---------------------------------------------------------% */
875 /* | Apply the NP implicit shifts by QR bulge chasing. | */
876 /* | Each shift is applied to the whole upper Hessenberg | */
877 /* | matrix H. | */
878 /* | The first 2*N locations of WORKD are used as workspace. | */
879 /* %---------------------------------------------------------% */
880
881 znapps_(n, nev, np, &ritz[1], &v[v_offset], ldv, &h__[h_offset], ldh, &
882 resid[1], &q[q_offset], ldq, &workl[1], &workd[1]);
883
884 /* %---------------------------------------------% */
885 /* | Compute the B-norm of the updated residual. | */
886 /* | Keep B*RESID in WORKD(1:N) to be used in | */
887 /* | the first step of the next call to znaitr . | */
888 /* %---------------------------------------------% */
889
890 cnorm = TRUE_;
891 second_(&t2);
892 if (*(unsigned char *)bmat == 'G') {
893 ++timing_1.nbx;
894 zcopy_(n, &resid[1], &c__1, &workd[*n + 1], &c__1);
895 ipntr[1] = *n + 1;
896 ipntr[2] = 1;
897 *ido = 2;
898
899 /* %----------------------------------% */
900 /* | Exit in order to compute B*RESID | */
901 /* %----------------------------------% */
902
903 goto L9000;
904 } else if (*(unsigned char *)bmat == 'I') {
905 zcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
906 }
907
908 L100:
909
910 /* %----------------------------------% */
911 /* | Back from reverse communication; | */
912 /* | WORKD(1:N) := B*RESID | */
913 /* %----------------------------------% */
914
915 if (*(unsigned char *)bmat == 'G') {
916 second_(&t3);
917 timing_1.tmvbx += t3 - t2;
918 }
919
920 if (*(unsigned char *)bmat == 'G') {
921 zdotc_(&z__1, n, &resid[1], &c__1, &workd[1], &c__1);
922 cmpnorm.r = z__1.r, cmpnorm.i = z__1.i;
923 d__1 = cmpnorm.r;
924 d__2 = d_imag(&cmpnorm);
925 rnorm = sqrt(dlapy2_(&d__1, &d__2));
926 } else if (*(unsigned char *)bmat == 'I') {
927 rnorm = dznrm2_(n, &resid[1], &c__1);
928 }
929 cnorm = FALSE_;
930
931 if (msglvl > 2) {
932 dvout_(&debug_1.logfil, &c__1, &rnorm, &debug_1.ndigit, "_naup2: B-n"
933 "orm of residual for compressed factorization", (ftnlen)55);
934 zmout_(&debug_1.logfil, nev, nev, &h__[h_offset], ldh, &
935 debug_1.ndigit, "_naup2: Compressed upper Hessenberg matrix H"
936 , (ftnlen)44);
937 }
938
939 goto L1000;
940
941 /* %---------------------------------------------------------------% */
942 /* | | */
943 /* | E N D O F M A I N I T E R A T I O N L O O P | */
944 /* | | */
945 /* %---------------------------------------------------------------% */
946
947 L1100:
948
949 *mxiter = iter;
950 *nev = nconv;
951
952 L1200:
953 *ido = 99;
954
955 /* %------------% */
956 /* | Error Exit | */
957 /* %------------% */
958
959 second_(&t1);
960 timing_1.tcaup2 = t1 - t0;
961
962 L9000:
963
964 /* %---------------% */
965 /* | End of znaup2 | */
966 /* %---------------% */
967
968 return 0;
969 } /* znaup2_ */
970