Debian Codegraph @

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

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