Debian Codegraph @

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

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