Debian Codegraph @

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

raw
1 /* ./src_f77/dsaup2.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_DSAUP2;
15
16 #define debug_1 debug_DSAUP2
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_DSAUP2;
25
26 #define timing_1 timing_DSAUP2
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: dsaup2 */
41
42 /* \Description: */
43 /* Intermediate level interface called by dsaupd. */
44
45 /* \Usage: */
46 /* call dsaup2 */
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 dsaupd. */
54 /* MODE, ISHIFT, MXITER: see the definition of IPARAM in dsaupd. */
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 Double precision 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 Double precision (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 dsaup2 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 Double precision array of length NEV+NP. (OUTPUT) */
96 /* RITZ(1:NEV) contains the computed Ritz values of OP. */
97
98 /* BOUNDS Double precision array of length NEV+NP. (OUTPUT) */
99 /* BOUNDS(1:NEV) contain the error bounds corresponding to RITZ. */
100
101 /* Q Double precision (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 Double precision 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 Double precision 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 dsaupd. */
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 /* dgetv0 ARPACK initial vector generation routine. */
180 /* dsaitr ARPACK Lanczos factorization routine. */
181 /* dsapps ARPACK application of implicit shifts routine. */
182 /* dsconv ARPACK convergence of Ritz values routine. */
183 /* dseigt ARPACK compute Ritz values and error bounds routine. */
184 /* dsgets ARPACK reorder Ritz values and error bounds routine. */
185 /* dsortr ARPACK sorting routine. */
186 /* ivout ARPACK utility routine that prints integers. */
187 /* second ARPACK utility routine for timing. */
188 /* dvout ARPACK utility routine that prints vectors. */
189 /* dlamch LAPACK routine that determines machine constants. */
190 /* dcopy Level 1 BLAS that copies one vector to another. */
191 /* ddot Level 1 BLAS that computes the scalar product of two vectors. */
192 /* dnrm2 Level 1 BLAS that computes the norm of a vector. */
193 /* dscal Level 1 BLAS that scales a vector. */
194 /* dswap 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 dsaup2_(integer *ido, char *bmat, integer *n, char *
216 which, integer *nev, integer *np, doublereal *tol, doublereal *resid,
217 integer *mode, integer *iupd, integer *ishift, integer *mxiter,
218 doublereal *v, integer *ldv, doublereal *h__, integer *ldh,
219 doublereal *ritz, doublereal *bounds, doublereal *q, integer *ldq,
220 doublereal *workl, integer *ipntr, doublereal *workd, integer *info,
221 ftnlen bmat_len, ftnlen which_len)
222 {
223 /* System generated locals */
224 integer h_dim1, h_offset, q_dim1, q_offset, v_dim1, v_offset, i__1, i__2,
225 i__3;
226 doublereal d__1, d__2, d__3;
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 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
239 integer *);
240 static doublereal eps23;
241 static integer ierr, iter;
242 static doublereal temp;
243 static integer nevd2;
244 extern doublereal dnrm2_(integer *, doublereal *, integer *);
245 static logical getv0;
246 static integer nevm2;
247 static logical cnorm;
248 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
249 doublereal *, integer *), dswap_(integer *, doublereal *, integer
250 *, doublereal *, integer *);
251 static integer nconv;
252 static logical initv;
253 static doublereal rnorm;
254 extern /* Subroutine */ int dvout_(integer *, integer *, doublereal *,
255 integer *, char *, ftnlen), ivout_(integer *, integer *, integer *
256 , integer *, char *, ftnlen), dgetv0_(integer *, char *, integer *
257 , logical *, integer *, integer *, doublereal *, integer *,
258 doublereal *, doublereal *, integer *, doublereal *, integer *,
259 ftnlen);
260 extern doublereal dlamch_(char *, ftnlen);
261 static integer nevbef;
262 extern /* Subroutine */ int second_(real *);
263 static logical update;
264 static char wprime[2];
265 static logical ushift;
266 static integer kplusp, msglvl, nptemp;
267 extern /* Subroutine */ int dsaitr_(integer *, char *, integer *, integer
268 *, integer *, integer *, doublereal *, doublereal *, doublereal *,
269 integer *, doublereal *, integer *, integer *, doublereal *,
270 integer *, ftnlen), dsconv_(integer *, doublereal *, doublereal *,
271 doublereal *, integer *), dseigt_(doublereal *, integer *,
272 doublereal *, integer *, doublereal *, doublereal *, doublereal *,
273 integer *), dsgets_(integer *, char *, integer *, integer *,
274 doublereal *, doublereal *, doublereal *, ftnlen), dsapps_(
275 integer *, integer *, integer *, doublereal *, doublereal *,
276 integer *, doublereal *, integer *, doublereal *, doublereal *,
277 integer *, doublereal *), dsortr_(char *, logical *, integer *,
278 doublereal *, doublereal *, ftnlen);
279
280
281 /* %----------------------------------------------------% */
282 /* | Include files for debugging and timing information | */
283 /* %----------------------------------------------------% */
284
285
286 /* \SCCS Information: @(#) */
287 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
288
289 /* %---------------------------------% */
290 /* | See debug.doc for documentation | */
291 /* %---------------------------------% */
292
293 /* %------------------% */
294 /* | Scalar Arguments | */
295 /* %------------------% */
296
297 /* %--------------------------------% */
298 /* | See stat.doc for documentation | */
299 /* %--------------------------------% */
300
301 /* \SCCS Information: @(#) */
302 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
303
304
305
306 /* %-----------------% */
307 /* | Array Arguments | */
308 /* %-----------------% */
309
310
311 /* %------------% */
312 /* | Parameters | */
313 /* %------------% */
314
315
316 /* %---------------% */
317 /* | Local Scalars | */
318 /* %---------------% */
319
320
321 /* %----------------------% */
322 /* | External Subroutines | */
323 /* %----------------------% */
324
325
326 /* %--------------------% */
327 /* | External Functions | */
328 /* %--------------------% */
329
330
331 /* %---------------------% */
332 /* | Intrinsic Functions | */
333 /* %---------------------% */
334
335
336 /* %-----------------------% */
337 /* | Executable Statements | */
338 /* %-----------------------% */
339
340 /* Parameter adjustments */
341 --workd;
342 --resid;
343 --workl;
344 --bounds;
345 --ritz;
346 v_dim1 = *ldv;
347 v_offset = 1 + v_dim1;
348 v -= v_offset;
349 h_dim1 = *ldh;
350 h_offset = 1 + h_dim1;
351 h__ -= h_offset;
352 q_dim1 = *ldq;
353 q_offset = 1 + q_dim1;
354 q -= q_offset;
355 --ipntr;
356
357 /* Function Body */
358 if (*ido == 0) {
359
360 /* %-------------------------------% */
361 /* | Initialize timing statistics | */
362 /* | & message level for debugging | */
363 /* %-------------------------------% */
364
365 second_(&t0);
366 msglvl = debug_1.msaup2;
367
368 /* %---------------------------------% */
369 /* | Set machine dependent constant. | */
370 /* %---------------------------------% */
371
372 eps23 = dlamch_("Epsilon-Machine", (ftnlen)15);
373 eps23 = pow_dd(&eps23, &c_b3);
374
375 /* %-------------------------------------% */
376 /* | nev0 and np0 are integer variables | */
377 /* | hold the initial values of NEV & NP | */
378 /* %-------------------------------------% */
379
380 nev0 = *nev;
381 np0 = *np;
382
383 /* %-------------------------------------% */
384 /* | kplusp is the bound on the largest | */
385 /* | Lanczos factorization built. | */
386 /* | nconv is the current number of | */
387 /* | "converged" eigenvlues. | */
388 /* | iter is the counter on the current | */
389 /* | iteration step. | */
390 /* %-------------------------------------% */
391
392 kplusp = nev0 + np0;
393 nconv = 0;
394 iter = 0;
395
396 /* %--------------------------------------------% */
397 /* | Set flags for computing the first NEV steps | */
398 /* | of the Lanczos factorization. | */
399 /* %--------------------------------------------% */
400
401 getv0 = TRUE_;
402 update = FALSE_;
403 ushift = FALSE_;
404 cnorm = FALSE_;
405
406 if (*info != 0) {
407
408 /* %--------------------------------------------% */
409 /* | User provides the initial residual vector. | */
410 /* %--------------------------------------------% */
411
412 initv = TRUE_;
413 *info = 0;
414 } else {
415 initv = FALSE_;
416 }
417 }
418
419 /* %---------------------------------------------% */
420 /* | Get a possibly random starting vector and | */
421 /* | force it into the range of the operator OP. | */
422 /* %---------------------------------------------% */
423
424 /* L10: */
425
426 if (getv0) {
427 dgetv0_(ido, bmat, &c__1, &initv, n, &c__1, &v[v_offset], ldv, &resid[
428 1], &rnorm, &ipntr[1], &workd[1], info, (ftnlen)1);
429
430 if (*ido != 99) {
431 goto L9000;
432 }
433
434 if (rnorm == 0.) {
435
436 /* %-----------------------------------------% */
437 /* | The initial vector is zero. Error exit. | */
438 /* %-----------------------------------------% */
439
440 *info = -9;
441 goto L1200;
442 }
443 getv0 = FALSE_;
444 *ido = 0;
445 }
446
447 /* %------------------------------------------------------------% */
448 /* | Back from reverse communication: continue with update step | */
449 /* %------------------------------------------------------------% */
450
451 if (update) {
452 goto L20;
453 }
454
455 /* %-------------------------------------------% */
456 /* | Back from computing user specified shifts | */
457 /* %-------------------------------------------% */
458
459 if (ushift) {
460 goto L50;
461 }
462
463 /* %-------------------------------------% */
464 /* | Back from computing residual norm | */
465 /* | at the end of the current iteration | */
466 /* %-------------------------------------% */
467
468 if (cnorm) {
469 goto L100;
470 }
471
472 /* %----------------------------------------------------------% */
473 /* | Compute the first NEV steps of the Lanczos factorization | */
474 /* %----------------------------------------------------------% */
475
476 dsaitr_(ido, bmat, n, &c__0, &nev0, mode, &resid[1], &rnorm, &v[v_offset],
477 ldv, &h__[h_offset], ldh, &ipntr[1], &workd[1], info, (ftnlen)1);
478
479 /* %---------------------------------------------------% */
480 /* | ido .ne. 99 implies use of reverse communication | */
481 /* | to compute operations involving OP and possibly B | */
482 /* %---------------------------------------------------% */
483
484 if (*ido != 99) {
485 goto L9000;
486 }
487
488 if (*info > 0) {
489
490 /* %-----------------------------------------------------% */
491 /* | dsaitr was unable to build an Lanczos factorization | */
492 /* | of length NEV0. INFO is returned with the size of | */
493 /* | the factorization built. Exit main loop. | */
494 /* %-----------------------------------------------------% */
495
496 *np = *info;
497 *mxiter = iter;
498 *info = -9999;
499 goto L1200;
500 }
501
502 /* %--------------------------------------------------------------% */
503 /* | | */
504 /* | M A I N LANCZOS I T E R A T I O N L O O P | */
505 /* | Each iteration implicitly restarts the Lanczos | */
506 /* | factorization in place. | */
507 /* | | */
508 /* %--------------------------------------------------------------% */
509
510 L1000:
511
512 ++iter;
513
514 if (msglvl > 0) {
515 ivout_(&debug_1.logfil, &c__1, &iter, &debug_1.ndigit, "_saup2: ****"
516 " Start of major iteration number ****", (ftnlen)49);
517 }
518 if (msglvl > 1) {
519 ivout_(&debug_1.logfil, &c__1, nev, &debug_1.ndigit, "_saup2: The le"
520 "ngth of the current Lanczos factorization", (ftnlen)55);
521 ivout_(&debug_1.logfil, &c__1, np, &debug_1.ndigit, "_saup2: Extend "
522 "the Lanczos factorization by", (ftnlen)43);
523 }
524
525 /* %------------------------------------------------------------% */
526 /* | Compute NP additional steps of the Lanczos factorization. | */
527 /* %------------------------------------------------------------% */
528
529 *ido = 0;
530 L20:
531 update = TRUE_;
532
533 dsaitr_(ido, bmat, n, nev, np, mode, &resid[1], &rnorm, &v[v_offset], ldv,
534 &h__[h_offset], ldh, &ipntr[1], &workd[1], info, (ftnlen)1);
535
536 /* %---------------------------------------------------% */
537 /* | ido .ne. 99 implies use of reverse communication | */
538 /* | to compute operations involving OP and possibly B | */
539 /* %---------------------------------------------------% */
540
541 if (*ido != 99) {
542 goto L9000;
543 }
544
545 if (*info > 0) {
546
547 /* %-----------------------------------------------------% */
548 /* | dsaitr was unable to build an Lanczos factorization | */
549 /* | of length NEV0+NP0. INFO is returned with the size | */
550 /* | of the factorization built. Exit main loop. | */
551 /* %-----------------------------------------------------% */
552
553 *np = *info;
554 *mxiter = iter;
555 *info = -9999;
556 goto L1200;
557 }
558 update = FALSE_;
559
560 if (msglvl > 1) {
561 dvout_(&debug_1.logfil, &c__1, &rnorm, &debug_1.ndigit, "_saup2: Cur"
562 "rent B-norm of residual for factorization", (ftnlen)52);
563 }
564
565 /* %--------------------------------------------------------% */
566 /* | Compute the eigenvalues and corresponding error bounds | */
567 /* | of the current symmetric tridiagonal matrix. | */
568 /* %--------------------------------------------------------% */
569
570 dseigt_(&rnorm, &kplusp, &h__[h_offset], ldh, &ritz[1], &bounds[1], &
571 workl[1], &ierr);
572
573 if (ierr != 0) {
574 *info = -8;
575 goto L1200;
576 }
577
578 /* %----------------------------------------------------% */
579 /* | Make a copy of eigenvalues and corresponding error | */
580 /* | bounds obtained from _seigt. | */
581 /* %----------------------------------------------------% */
582
583 dcopy_(&kplusp, &ritz[1], &c__1, &workl[kplusp + 1], &c__1);
584 dcopy_(&kplusp, &bounds[1], &c__1, &workl[(kplusp << 1) + 1], &c__1);
585
586 /* %---------------------------------------------------% */
587 /* | Select the wanted Ritz values and their bounds | */
588 /* | to be used in the convergence test. | */
589 /* | The selection is based on the requested number of | */
590 /* | eigenvalues instead of the current NEV and NP to | */
591 /* | prevent possible misconvergence. | */
592 /* | * Wanted Ritz values := RITZ(NP+1:NEV+NP) | */
593 /* | * Shifts := RITZ(1:NP) := WORKL(1:NP) | */
594 /* %---------------------------------------------------% */
595
596 *nev = nev0;
597 *np = np0;
598 dsgets_(ishift, which, nev, np, &ritz[1], &bounds[1], &workl[1], (ftnlen)
599 2);
600
601 /* %-------------------% */
602 /* | Convergence test. | */
603 /* %-------------------% */
604
605 dcopy_(nev, &bounds[*np + 1], &c__1, &workl[*np + 1], &c__1);
606 dsconv_(nev, &ritz[*np + 1], &workl[*np + 1], tol, &nconv);
607
608 if (msglvl > 2) {
609 kp[0] = *nev;
610 kp[1] = *np;
611 kp[2] = nconv;
612 ivout_(&debug_1.logfil, &c__3, kp, &debug_1.ndigit, "_saup2: NEV, NP"
613 ", NCONV are", (ftnlen)26);
614 dvout_(&debug_1.logfil, &kplusp, &ritz[1], &debug_1.ndigit, "_saup2:"
615 " The eigenvalues of H", (ftnlen)28);
616 dvout_(&debug_1.logfil, &kplusp, &bounds[1], &debug_1.ndigit, "_saup"
617 "2: Ritz estimates of the current NCV Ritz values", (ftnlen)53)
618 ;
619 }
620
621 /* %---------------------------------------------------------% */
622 /* | Count the number of unwanted Ritz values that have zero | */
623 /* | Ritz estimates. If any Ritz estimates are equal to zero | */
624 /* | then a leading block of H of order equal to at least | */
625 /* | the number of Ritz values with zero Ritz estimates has | */
626 /* | split off. None of these Ritz values may be removed by | */
627 /* | shifting. Decrease NP the number of shifts to apply. If | */
628 /* | no shifts may be applied, then prepare to exit | */
629 /* %---------------------------------------------------------% */
630
631 nptemp = *np;
632 i__1 = nptemp;
633 for (j = 1; j <= i__1; ++j) {
634 if (bounds[j] == 0.) {
635 --(*np);
636 ++(*nev);
637 }
638 /* L30: */
639 }
640
641 if (nconv >= nev0 || iter > *mxiter || *np == 0) {
642
643 /* %------------------------------------------------% */
644 /* | Prepare to exit. Put the converged Ritz values | */
645 /* | and corresponding bounds in RITZ(1:NCONV) and | */
646 /* | BOUNDS(1:NCONV) respectively. Then sort. Be | */
647 /* | careful when NCONV > NP since we don't want to | */
648 /* | swap overlapping locations. | */
649 /* %------------------------------------------------% */
650
651 if (s_cmp(which, "BE", (ftnlen)2, (ftnlen)2) == 0) {
652
653 /* %-----------------------------------------------------% */
654 /* | Both ends of the spectrum are requested. | */
655 /* | Sort the eigenvalues into algebraically decreasing | */
656 /* | order first then swap low end of the spectrum next | */
657 /* | to high end in appropriate locations. | */
658 /* | NOTE: when np < floor(nev/2) be careful not to swap | */
659 /* | overlapping locations. | */
660 /* %-----------------------------------------------------% */
661
662 s_copy(wprime, "SA", (ftnlen)2, (ftnlen)2);
663 dsortr_(wprime, &c_true, &kplusp, &ritz[1], &bounds[1], (ftnlen)2)
664 ;
665 nevd2 = nev0 / 2;
666 nevm2 = nev0 - nevd2;
667 if (*nev > 1) {
668 i__1 = min(nevd2,*np);
669 /* Computing MAX */
670 i__2 = kplusp - nevd2 + 1, i__3 = kplusp - *np + 1;
671 dswap_(&i__1, &ritz[nevm2 + 1], &c__1, &ritz[max(i__2,i__3)],
672 &c__1);
673 i__1 = min(nevd2,*np);
674 /* Computing MAX */
675 i__2 = kplusp - nevd2 + 1, i__3 = kplusp - *np + 1;
676 dswap_(&i__1, &bounds[nevm2 + 1], &c__1, &bounds[max(i__2,
677 i__3)], &c__1);
678 }
679
680 } else {
681
682 /* %--------------------------------------------------% */
683 /* | LM, SM, LA, SA case. | */
684 /* | Sort the eigenvalues of H into the an order that | */
685 /* | is opposite to WHICH, and apply the resulting | */
686 /* | order to BOUNDS. The eigenvalues are sorted so | */
687 /* | that the wanted part are always within the first | */
688 /* | NEV locations. | */
689 /* %--------------------------------------------------% */
690
691 if (s_cmp(which, "LM", (ftnlen)2, (ftnlen)2) == 0) {
692 s_copy(wprime, "SM", (ftnlen)2, (ftnlen)2);
693 }
694 if (s_cmp(which, "SM", (ftnlen)2, (ftnlen)2) == 0) {
695 s_copy(wprime, "LM", (ftnlen)2, (ftnlen)2);
696 }
697 if (s_cmp(which, "LA", (ftnlen)2, (ftnlen)2) == 0) {
698 s_copy(wprime, "SA", (ftnlen)2, (ftnlen)2);
699 }
700 if (s_cmp(which, "SA", (ftnlen)2, (ftnlen)2) == 0) {
701 s_copy(wprime, "LA", (ftnlen)2, (ftnlen)2);
702 }
703
704 dsortr_(wprime, &c_true, &kplusp, &ritz[1], &bounds[1], (ftnlen)2)
705 ;
706
707 }
708
709 /* %--------------------------------------------------% */
710 /* | Scale the Ritz estimate of each Ritz value | */
711 /* | by 1 / max(eps23,magnitude of the Ritz value). | */
712 /* %--------------------------------------------------% */
713
714 i__1 = nev0;
715 for (j = 1; j <= i__1; ++j) {
716 /* Computing MAX */
717 d__2 = eps23, d__3 = (d__1 = ritz[j], abs(d__1));
718 temp = max(d__2,d__3);
719 bounds[j] /= temp;
720 /* L35: */
721 }
722
723 /* %----------------------------------------------------% */
724 /* | Sort the Ritz values according to the scaled Ritz | */
725 /* | esitmates. This will push all the converged ones | */
726 /* | towards the front of ritzr, ritzi, bounds | */
727 /* | (in the case when NCONV < NEV.) | */
728 /* %----------------------------------------------------% */
729
730 s_copy(wprime, "LA", (ftnlen)2, (ftnlen)2);
731 dsortr_(wprime, &c_true, &nev0, &bounds[1], &ritz[1], (ftnlen)2);
732
733 /* %----------------------------------------------% */
734 /* | Scale the Ritz estimate back to its original | */
735 /* | value. | */
736 /* %----------------------------------------------% */
737
738 i__1 = nev0;
739 for (j = 1; j <= i__1; ++j) {
740 /* Computing MAX */
741 d__2 = eps23, d__3 = (d__1 = ritz[j], abs(d__1));
742 temp = max(d__2,d__3);
743 bounds[j] *= temp;
744 /* L40: */
745 }
746
747 /* %--------------------------------------------------% */
748 /* | Sort the "converged" Ritz values again so that | */
749 /* | the "threshold" values and their associated Ritz | */
750 /* | estimates appear at the appropriate position in | */
751 /* | ritz and bound. | */
752 /* %--------------------------------------------------% */
753
754 if (s_cmp(which, "BE", (ftnlen)2, (ftnlen)2) == 0) {
755
756 /* %------------------------------------------------% */
757 /* | Sort the "converged" Ritz values in increasing | */
758 /* | order. The "threshold" values are in the | */
759 /* | middle. | */
760 /* %------------------------------------------------% */
761
762 s_copy(wprime, "LA", (ftnlen)2, (ftnlen)2);
763 dsortr_(wprime, &c_true, &nconv, &ritz[1], &bounds[1], (ftnlen)2);
764
765 } else {
766
767 /* %----------------------------------------------% */
768 /* | In LM, SM, LA, SA case, sort the "converged" | */
769 /* | Ritz values according to WHICH so that the | */
770 /* | "threshold" value appears at the front of | */
771 /* | ritz. | */
772 /* %----------------------------------------------% */
773 dsortr_(which, &c_true, &nconv, &ritz[1], &bounds[1], (ftnlen)2);
774
775 }
776
777 /* %------------------------------------------% */
778 /* | Use h( 1,1 ) as storage to communicate | */
779 /* | rnorm to _seupd if needed | */
780 /* %------------------------------------------% */
781
782 h__[h_dim1 + 1] = rnorm;
783
784 if (msglvl > 1) {
785 dvout_(&debug_1.logfil, &kplusp, &ritz[1], &debug_1.ndigit, "_sa"
786 "up2: Sorted Ritz values.", (ftnlen)27);
787 dvout_(&debug_1.logfil, &kplusp, &bounds[1], &debug_1.ndigit,
788 "_saup2: Sorted ritz estimates.", (ftnlen)30);
789 }
790
791 /* %------------------------------------% */
792 /* | Max iterations have been exceeded. | */
793 /* %------------------------------------% */
794
795 if (iter > *mxiter && nconv < *nev) {
796 *info = 1;
797 }
798
799 /* %---------------------% */
800 /* | No shifts to apply. | */
801 /* %---------------------% */
802
803 if (*np == 0 && nconv < nev0) {
804 *info = 2;
805 }
806
807 *np = nconv;
808 goto L1100;
809
810 } else if (nconv < *nev && *ishift == 1) {
811
812 /* %---------------------------------------------------% */
813 /* | Do not have all the requested eigenvalues yet. | */
814 /* | To prevent possible stagnation, adjust the number | */
815 /* | of Ritz values and the shifts. | */
816 /* %---------------------------------------------------% */
817
818 nevbef = *nev;
819 /* Computing MIN */
820 i__1 = nconv, i__2 = *np / 2;
821 *nev += min(i__1,i__2);
822 if (*nev == 1 && kplusp >= 6) {
823 *nev = kplusp / 2;
824 } else if (*nev == 1 && kplusp > 2) {
825 *nev = 2;
826 }
827 *np = kplusp - *nev;
828
829 /* %---------------------------------------% */
830 /* | If the size of NEV was just increased | */
831 /* | resort the eigenvalues. | */
832 /* %---------------------------------------% */
833
834 if (nevbef < *nev) {
835 dsgets_(ishift, which, nev, np, &ritz[1], &bounds[1], &workl[1], (
836 ftnlen)2);
837 }
838
839 }
840
841 if (msglvl > 0) {
842 ivout_(&debug_1.logfil, &c__1, &nconv, &debug_1.ndigit, "_saup2: no."
843 " of \"converged\" Ritz values at this iter.", (ftnlen)52);
844 if (msglvl > 1) {
845 kp[0] = *nev;
846 kp[1] = *np;
847 ivout_(&debug_1.logfil, &c__2, kp, &debug_1.ndigit, "_saup2: NEV"
848 " and NP are", (ftnlen)22);
849 dvout_(&debug_1.logfil, nev, &ritz[*np + 1], &debug_1.ndigit,
850 "_saup2: \"wanted\" Ritz values.", (ftnlen)29);
851 dvout_(&debug_1.logfil, nev, &bounds[*np + 1], &debug_1.ndigit,
852 "_saup2: Ritz estimates of the \"wanted\" values ", (
853 ftnlen)46);
854 }
855 }
856
857 if (*ishift == 0) {
858
859 /* %-----------------------------------------------------% */
860 /* | User specified shifts: reverse communication to | */
861 /* | compute the shifts. They are returned in the first | */
862 /* | NP locations of WORKL. | */
863 /* %-----------------------------------------------------% */
864
865 ushift = TRUE_;
866 *ido = 3;
867 goto L9000;
868 }
869
870 L50:
871
872 /* %------------------------------------% */
873 /* | Back from reverse communication; | */
874 /* | User specified shifts are returned | */
875 /* | in WORKL(1:*NP) | */
876 /* %------------------------------------% */
877
878 ushift = FALSE_;
879
880
881 /* %---------------------------------------------------------% */
882 /* | Move the NP shifts to the first NP locations of RITZ to | */
883 /* | free up WORKL. This is for the non-exact shift case; | */
884 /* | in the exact shift case, dsgets already handles this. | */
885 /* %---------------------------------------------------------% */
886
887 if (*ishift == 0) {
888 dcopy_(np, &workl[1], &c__1, &ritz[1], &c__1);
889 }
890
891 if (msglvl > 2) {
892 ivout_(&debug_1.logfil, &c__1, np, &debug_1.ndigit, "_saup2: The num"
893 "ber of shifts to apply ", (ftnlen)38);
894 dvout_(&debug_1.logfil, np, &workl[1], &debug_1.ndigit, "_saup2: shi"
895 "fts selected", (ftnlen)23);
896 if (*ishift == 1) {
897 dvout_(&debug_1.logfil, np, &bounds[1], &debug_1.ndigit, "_saup2"
898 ": corresponding Ritz estimates", (ftnlen)36);
899 }
900 }
901
902 /* %---------------------------------------------------------% */
903 /* | Apply the NP0 implicit shifts by QR bulge chasing. | */
904 /* | Each shift is applied to the entire tridiagonal matrix. | */
905 /* | The first 2*N locations of WORKD are used as workspace. | */
906 /* | After dsapps is done, we have a Lanczos | */
907 /* | factorization of length NEV. | */
908 /* %---------------------------------------------------------% */
909
910 dsapps_(n, nev, np, &ritz[1], &v[v_offset], ldv, &h__[h_offset], ldh, &
911 resid[1], &q[q_offset], ldq, &workd[1]);
912
913 /* %---------------------------------------------% */
914 /* | Compute the B-norm of the updated residual. | */
915 /* | Keep B*RESID in WORKD(1:N) to be used in | */
916 /* | the first step of the next call to dsaitr. | */
917 /* %---------------------------------------------% */
918
919 cnorm = TRUE_;
920 second_(&t2);
921 if (*(unsigned char *)bmat == 'G') {
922 ++timing_1.nbx;
923 dcopy_(n, &resid[1], &c__1, &workd[*n + 1], &c__1);
924 ipntr[1] = *n + 1;
925 ipntr[2] = 1;
926 *ido = 2;
927
928 /* %----------------------------------% */
929 /* | Exit in order to compute B*RESID | */
930 /* %----------------------------------% */
931
932 goto L9000;
933 } else if (*(unsigned char *)bmat == 'I') {
934 dcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
935 }
936
937 L100:
938
939 /* %----------------------------------% */
940 /* | Back from reverse communication; | */
941 /* | WORKD(1:N) := B*RESID | */
942 /* %----------------------------------% */
943
944 if (*(unsigned char *)bmat == 'G') {
945 second_(&t3);
946 timing_1.tmvbx += t3 - t2;
947 }
948
949 if (*(unsigned char *)bmat == 'G') {
950 rnorm = ddot_(n, &resid[1], &c__1, &workd[1], &c__1);
951 rnorm = sqrt((abs(rnorm)));
952 } else if (*(unsigned char *)bmat == 'I') {
953 rnorm = dnrm2_(n, &resid[1], &c__1);
954 }
955 cnorm = FALSE_;
956 /* L130: */
957
958 if (msglvl > 2) {
959 dvout_(&debug_1.logfil, &c__1, &rnorm, &debug_1.ndigit, "_saup2: B-n"
960 "orm of residual for NEV factorization", (ftnlen)48);
961 dvout_(&debug_1.logfil, nev, &h__[(h_dim1 << 1) + 1], &debug_1.ndigit,
962 "_saup2: main diagonal of compressed H matrix", (ftnlen)44);
963 i__1 = *nev - 1;
964 dvout_(&debug_1.logfil, &i__1, &h__[h_dim1 + 2], &debug_1.ndigit,
965 "_saup2: subdiagonal of compressed H matrix", (ftnlen)42);
966 }
967
968 goto L1000;
969
970 /* %---------------------------------------------------------------% */
971 /* | | */
972 /* | E N D O F M A I N I T E R A T I O N L O O P | */
973 /* | | */
974 /* %---------------------------------------------------------------% */
975
976 L1100:
977
978 *mxiter = iter;
979 *nev = nconv;
980
981 L1200:
982 *ido = 99;
983
984 /* %------------% */
985 /* | Error exit | */
986 /* %------------% */
987
988 second_(&t1);
989 timing_1.tsaup2 = t1 - t0;
990
991 L9000:
992 return 0;
993
994 /* %---------------% */
995 /* | End of dsaup2 | */
996 /* %---------------% */
997
998 } /* dsaup2_ */
999