Debian Codegraph @

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

raw
1 /* ./src_f77/snaitr.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_SNAITR;
15
16 #define debug_1 debug_SNAITR
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_SNAITR;
25
26 #define timing_1 timing_SNAITR
27
28 /* Table of constant values */
29
30 static integer c__1 = 1;
31 static logical c_false = FALSE_;
32 static real c_b25 = 1.f;
33 static real c_b47 = 0.f;
34 static real c_b50 = -1.f;
35 static integer c__2 = 2;
36
37 /* ----------------------------------------------------------------------- */
38 /* \BeginDoc */
39
40 /* \Name: snaitr */
41
42 /* \Description: */
43 /* Reverse communication interface for applying NP additional steps to */
44 /* a K step nonsymmetric Arnoldi factorization. */
45
46 /* Input: OP*V_{k} - V_{k}*H = r_{k}*e_{k}^T */
47
48 /* with (V_{k}^T)*B*V_{k} = I, (V_{k}^T)*B*r_{k} = 0. */
49
50 /* Output: OP*V_{k+p} - V_{k+p}*H = r_{k+p}*e_{k+p}^T */
51
52 /* with (V_{k+p}^T)*B*V_{k+p} = I, (V_{k+p}^T)*B*r_{k+p} = 0. */
53
54 /* where OP and B are as in snaupd. The B-norm of r_{k+p} is also */
55 /* computed and returned. */
56
57 /* \Usage: */
58 /* call snaitr */
59 /* ( IDO, BMAT, N, K, NP, NB, RESID, RNORM, V, LDV, H, LDH, */
60 /* IPNTR, WORKD, INFO ) */
61
62 /* \Arguments */
63 /* IDO Integer. (INPUT/OUTPUT) */
64 /* Reverse communication flag. */
65 /* ------------------------------------------------------------- */
66 /* IDO = 0: first call to the reverse communication interface */
67 /* IDO = -1: compute Y = OP * X where */
68 /* IPNTR(1) is the pointer into WORK for X, */
69 /* IPNTR(2) is the pointer into WORK for Y. */
70 /* This is for the restart phase to force the new */
71 /* starting vector into the range of OP. */
72 /* IDO = 1: compute Y = OP * X where */
73 /* IPNTR(1) is the pointer into WORK for X, */
74 /* IPNTR(2) is the pointer into WORK for Y, */
75 /* IPNTR(3) is the pointer into WORK for B * X. */
76 /* IDO = 2: compute Y = B * X where */
77 /* IPNTR(1) is the pointer into WORK for X, */
78 /* IPNTR(2) is the pointer into WORK for Y. */
79 /* IDO = 99: done */
80 /* ------------------------------------------------------------- */
81 /* When the routine is used in the "shift-and-invert" mode, the */
82 /* vector B * Q is already available and do not need to be */
83 /* recompute in forming OP * Q. */
84
85 /* BMAT Character*1. (INPUT) */
86 /* BMAT specifies the type of the matrix B that defines the */
87 /* semi-inner product for the operator OP. See snaupd. */
88 /* B = 'I' -> standard eigenvalue problem A*x = lambda*x */
89 /* B = 'G' -> generalized eigenvalue problem A*x = lambda*M**x */
90
91 /* N Integer. (INPUT) */
92 /* Dimension of the eigenproblem. */
93
94 /* K Integer. (INPUT) */
95 /* Current size of V and H. */
96
97 /* NP Integer. (INPUT) */
98 /* Number of additional Arnoldi steps to take. */
99
100 /* NB Integer. (INPUT) */
101 /* Blocksize to be used in the recurrence. */
102 /* Only work for NB = 1 right now. The goal is to have a */
103 /* program that implement both the block and non-block method. */
104
105 /* RESID Real array of length N. (INPUT/OUTPUT) */
106 /* On INPUT: RESID contains the residual vector r_{k}. */
107 /* On OUTPUT: RESID contains the residual vector r_{k+p}. */
108
109 /* RNORM Real scalar. (INPUT/OUTPUT) */
110 /* B-norm of the starting residual on input. */
111 /* B-norm of the updated residual r_{k+p} on output. */
112
113 /* V Real N by K+NP array. (INPUT/OUTPUT) */
114 /* On INPUT: V contains the Arnoldi vectors in the first K */
115 /* columns. */
116 /* On OUTPUT: V contains the new NP Arnoldi vectors in the next */
117 /* NP columns. The first K columns are unchanged. */
118
119 /* LDV Integer. (INPUT) */
120 /* Leading dimension of V exactly as declared in the calling */
121 /* program. */
122
123 /* H Real (K+NP) by (K+NP) array. (INPUT/OUTPUT) */
124 /* H is used to store the generated upper Hessenberg matrix. */
125
126 /* LDH Integer. (INPUT) */
127 /* Leading dimension of H exactly as declared in the calling */
128 /* program. */
129
130 /* IPNTR Integer array of length 3. (OUTPUT) */
131 /* Pointer to mark the starting locations in the WORK for */
132 /* vectors used by the Arnoldi iteration. */
133 /* ------------------------------------------------------------- */
134 /* IPNTR(1): pointer to the current operand vector X. */
135 /* IPNTR(2): pointer to the current result vector Y. */
136 /* IPNTR(3): pointer to the vector B * X when used in the */
137 /* shift-and-invert mode. X is the current operand. */
138 /* ------------------------------------------------------------- */
139
140 /* WORKD Real work array of length 3*N. (REVERSE COMMUNICATION) */
141 /* Distributed array to be used in the basic Arnoldi iteration */
142 /* for reverse communication. The calling program should not */
143 /* use WORKD as temporary workspace during the iteration !!!!!! */
144 /* On input, WORKD(1:N) = B*RESID and is used to save some */
145 /* computation at the first step. */
146
147 /* INFO Integer. (OUTPUT) */
148 /* = 0: Normal exit. */
149 /* > 0: Size of the spanning invariant subspace of OP found. */
150
151 /* \EndDoc */
152
153 /* ----------------------------------------------------------------------- */
154
155 /* \BeginLib */
156
157 /* \Local variables: */
158 /* xxxxxx real */
159
160 /* \References: */
161 /* 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in */
162 /* a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), */
163 /* pp 357-385. */
164 /* 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly */
165 /* Restarted Arnoldi Iteration", Rice University Technical Report */
166 /* TR95-13, Department of Computational and Applied Mathematics. */
167
168 /* \Routines called: */
169 /* sgetv0 ARPACK routine to generate the initial vector. */
170 /* ivout ARPACK utility routine that prints integers. */
171 /* second ARPACK utility routine for timing. */
172 /* smout ARPACK utility routine that prints matrices */
173 /* svout ARPACK utility routine that prints vectors. */
174 /* slabad LAPACK routine that computes machine constants. */
175 /* slamch LAPACK routine that determines machine constants. */
176 /* slascl LAPACK routine for careful scaling of a matrix. */
177 /* slanhs LAPACK routine that computes various norms of a matrix. */
178 /* sgemv Level 2 BLAS routine for matrix vector multiplication. */
179 /* saxpy Level 1 BLAS that computes a vector triad. */
180 /* sscal Level 1 BLAS that scales a vector. */
181 /* scopy Level 1 BLAS that copies one vector to another . */
182 /* sdot Level 1 BLAS that computes the scalar product of two vectors. */
183 /* snrm2 Level 1 BLAS that computes the norm of a vector. */
184
185 /* \Author */
186 /* Danny Sorensen Phuong Vu */
187 /* Richard Lehoucq CRPC / Rice University */
188 /* Dept. of Computational & Houston, Texas */
189 /* Applied Mathematics */
190 /* Rice University */
191 /* Houston, Texas */
192
193 /* \Revision history: */
194 /* xx/xx/92: Version ' 2.4' */
195
196 /* \SCCS Information: @(#) */
197 /* FILE: naitr.F SID: 2.4 DATE OF SID: 8/27/96 RELEASE: 2 */
198
199 /* \Remarks */
200 /* The algorithm implemented is: */
201
202 /* restart = .false. */
203 /* Given V_{k} = [v_{1}, ..., v_{k}], r_{k}; */
204 /* r_{k} contains the initial residual vector even for k = 0; */
205 /* Also assume that rnorm = || B*r_{k} || and B*r_{k} are already */
206 /* computed by the calling program. */
207
208 /* betaj = rnorm ; p_{k+1} = B*r_{k} ; */
209 /* For j = k+1, ..., k+np Do */
210 /* 1) if ( betaj < tol ) stop or restart depending on j. */
211 /* ( At present tol is zero ) */
212 /* if ( restart ) generate a new starting vector. */
213 /* 2) v_{j} = r(j-1)/betaj; V_{j} = [V_{j-1}, v_{j}]; */
214 /* p_{j} = p_{j}/betaj */
215 /* 3) r_{j} = OP*v_{j} where OP is defined as in snaupd */
216 /* For shift-invert mode p_{j} = B*v_{j} is already available. */
217 /* wnorm = || OP*v_{j} || */
218 /* 4) Compute the j-th step residual vector. */
219 /* w_{j} = V_{j}^T * B * OP * v_{j} */
220 /* r_{j} = OP*v_{j} - V_{j} * w_{j} */
221 /* H(:,j) = w_{j}; */
222 /* H(j,j-1) = rnorm */
223 /* rnorm = || r_(j) || */
224 /* If (rnorm > 0.717*wnorm) accept step and go back to 1) */
225 /* 5) Re-orthogonalization step: */
226 /* s = V_{j}'*B*r_{j} */
227 /* r_{j} = r_{j} - V_{j}*s; rnorm1 = || r_{j} || */
228 /* alphaj = alphaj + s_{j}; */
229 /* 6) Iterative refinement step: */
230 /* If (rnorm1 > 0.717*rnorm) then */
231 /* rnorm = rnorm1 */
232 /* accept step and go back to 1) */
233 /* Else */
234 /* rnorm = rnorm1 */
235 /* If this is the first time in step 6), go to 5) */
236 /* Else r_{j} lies in the span of V_{j} numerically. */
237 /* Set r_{j} = 0 and rnorm = 0; go to 1) */
238 /* EndIf */
239 /* End Do */
240
241 /* \EndLib */
242
243 /* ----------------------------------------------------------------------- */
244
245 /* Subroutine */ int snaitr_(integer *ido, char *bmat, integer *n, integer *k,
246 integer *np, integer *nb, real *resid, real *rnorm, real *v, integer
247 *ldv, real *h__, integer *ldh, integer *ipntr, real *workd, integer *
248 info, ftnlen bmat_len)
249 {
250 /* Initialized data */
251
252 static logical first = TRUE_;
253
254 /* System generated locals */
255 integer h_dim1, h_offset, v_dim1, v_offset, i__1, i__2;
256 real r__1, r__2;
257
258 /* Builtin functions */
259 double sqrt(doublereal);
260
261 /* Local variables */
262 static integer i__, j;
263 static real t0, t1, t2, t3, t4, t5;
264 static integer jj, ipj, irj, ivj;
265 static real ulp, tst1;
266 static integer ierr, iter;
267 static real unfl, ovfl;
268 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
269 static integer itry;
270 static real temp1;
271 static logical orth1, orth2, step3, step4;
272 extern doublereal snrm2_(integer *, real *, integer *);
273 static real betaj;
274 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
275 static integer infol;
276 extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
277 real *, integer *, real *, integer *, real *, real *, integer *,
278 ftnlen);
279 static real xtemp[2];
280 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
281 integer *);
282 static real wnorm;
283 extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *,
284 real *, integer *), ivout_(integer *, integer *, integer *,
285 integer *, char *, ftnlen), smout_(integer *, integer *, integer *
286 , real *, integer *, integer *, char *, ftnlen), svout_(integer *,
287 integer *, real *, integer *, char *, ftnlen), sgetv0_(integer *,
288 char *, integer *, logical *, integer *, integer *, real *,
289 integer *, real *, real *, integer *, real *, integer *, ftnlen);
290 static real rnorm1;
291 extern /* Subroutine */ int slabad_(real *, real *);
292 extern doublereal slamch_(char *, ftnlen);
293 extern /* Subroutine */ int second_(real *), slascl_(char *, integer *,
294 integer *, real *, real *, integer *, integer *, real *, integer *
295 , integer *, ftnlen);
296 static logical rstart;
297 static integer msglvl;
298 static real smlnum;
299 extern doublereal slanhs_(char *, integer *, real *, integer *, real *,
300 ftnlen);
301
302
303 /* %----------------------------------------------------% */
304 /* | Include files for debugging and timing information | */
305 /* %----------------------------------------------------% */
306
307
308 /* \SCCS Information: @(#) */
309 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
310
311 /* %---------------------------------% */
312 /* | See debug.doc for documentation | */
313 /* %---------------------------------% */
314
315 /* %------------------% */
316 /* | Scalar Arguments | */
317 /* %------------------% */
318
319 /* %--------------------------------% */
320 /* | See stat.doc for documentation | */
321 /* %--------------------------------% */
322
323 /* \SCCS Information: @(#) */
324 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
325
326
327
328 /* %-----------------% */
329 /* | Array Arguments | */
330 /* %-----------------% */
331
332
333 /* %------------% */
334 /* | Parameters | */
335 /* %------------% */
336
337
338 /* %---------------% */
339 /* | Local Scalars | */
340 /* %---------------% */
341
342
343 /* %-----------------------% */
344 /* | Local Array Arguments | */
345 /* %-----------------------% */
346
347
348 /* %----------------------% */
349 /* | External Subroutines | */
350 /* %----------------------% */
351
352
353 /* %--------------------% */
354 /* | External Functions | */
355 /* %--------------------% */
356
357
358 /* %---------------------% */
359 /* | Intrinsic Functions | */
360 /* %---------------------% */
361
362
363 /* %-----------------% */
364 /* | Data statements | */
365 /* %-----------------% */
366
367 /* Parameter adjustments */
368 --workd;
369 --resid;
370 v_dim1 = *ldv;
371 v_offset = 1 + v_dim1;
372 v -= v_offset;
373 h_dim1 = *ldh;
374 h_offset = 1 + h_dim1;
375 h__ -= h_offset;
376 --ipntr;
377
378 /* Function Body */
379
380 /* %-----------------------% */
381 /* | Executable Statements | */
382 /* %-----------------------% */
383
384 if (first) {
385
386 /* %-----------------------------------------% */
387 /* | Set machine-dependent constants for the | */
388 /* | the splitting and deflation criterion. | */
389 /* | If norm(H) <= sqrt(OVFL), | */
390 /* | overflow should not occur. | */
391 /* | REFERENCE: LAPACK subroutine slahqr | */
392 /* %-----------------------------------------% */
393
394 unfl = slamch_("safe minimum", (ftnlen)12);
395 ovfl = 1.f / unfl;
396 slabad_(&unfl, &ovfl);
397 ulp = slamch_("precision", (ftnlen)9);
398 smlnum = unfl * (*n / ulp);
399 first = FALSE_;
400 }
401
402 if (*ido == 0) {
403
404 /* %-------------------------------% */
405 /* | Initialize timing statistics | */
406 /* | & message level for debugging | */
407 /* %-------------------------------% */
408
409 second_(&t0);
410 msglvl = debug_1.mnaitr;
411
412 /* %------------------------------% */
413 /* | Initial call to this routine | */
414 /* %------------------------------% */
415
416 *info = 0;
417 step3 = FALSE_;
418 step4 = FALSE_;
419 rstart = FALSE_;
420 orth1 = FALSE_;
421 orth2 = FALSE_;
422 j = *k + 1;
423 ipj = 1;
424 irj = ipj + *n;
425 ivj = irj + *n;
426 }
427
428 /* %-------------------------------------------------% */
429 /* | When in reverse communication mode one of: | */
430 /* | STEP3, STEP4, ORTH1, ORTH2, RSTART | */
431 /* | will be .true. when .... | */
432 /* | STEP3: return from computing OP*v_{j}. | */
433 /* | STEP4: return from computing B-norm of OP*v_{j} | */
434 /* | ORTH1: return from computing B-norm of r_{j+1} | */
435 /* | ORTH2: return from computing B-norm of | */
436 /* | correction to the residual vector. | */
437 /* | RSTART: return from OP computations needed by | */
438 /* | sgetv0. | */
439 /* %-------------------------------------------------% */
440
441 if (step3) {
442 goto L50;
443 }
444 if (step4) {
445 goto L60;
446 }
447 if (orth1) {
448 goto L70;
449 }
450 if (orth2) {
451 goto L90;
452 }
453 if (rstart) {
454 goto L30;
455 }
456
457 /* %-----------------------------% */
458 /* | Else this is the first step | */
459 /* %-----------------------------% */
460
461 /* %--------------------------------------------------------------% */
462 /* | | */
463 /* | A R N O L D I I T E R A T I O N L O O P | */
464 /* | | */
465 /* | Note: B*r_{j-1} is already in WORKD(1:N)=WORKD(IPJ:IPJ+N-1) | */
466 /* %--------------------------------------------------------------% */
467 L1000:
468
469 if (msglvl > 1) {
470 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_naitr: generat"
471 "ing Arnoldi vector number", (ftnlen)40);
472 svout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_naitr: B-no"
473 "rm of the current residual is", (ftnlen)41);
474 }
475
476 /* %---------------------------------------------------% */
477 /* | STEP 1: Check if the B norm of j-th residual | */
478 /* | vector is zero. Equivalent to determing whether | */
479 /* | an exact j-step Arnoldi factorization is present. | */
480 /* %---------------------------------------------------% */
481
482 betaj = *rnorm;
483 if (*rnorm > 0.f) {
484 goto L40;
485 }
486
487 /* %---------------------------------------------------% */
488 /* | Invariant subspace found, generate a new starting | */
489 /* | vector which is orthogonal to the current Arnoldi | */
490 /* | basis and continue the iteration. | */
491 /* %---------------------------------------------------% */
492
493 if (msglvl > 0) {
494 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_naitr: ****** "
495 "RESTART AT STEP ******", (ftnlen)37);
496 }
497
498 /* %---------------------------------------------% */
499 /* | ITRY is the loop variable that controls the | */
500 /* | maximum amount of times that a restart is | */
501 /* | attempted. NRSTRT is used by stat.h | */
502 /* %---------------------------------------------% */
503
504 betaj = 0.f;
505 ++timing_1.nrstrt;
506 itry = 1;
507 L20:
508 rstart = TRUE_;
509 *ido = 0;
510 L30:
511
512 /* %--------------------------------------% */
513 /* | If in reverse communication mode and | */
514 /* | RSTART = .true. flow returns here. | */
515 /* %--------------------------------------% */
516
517 sgetv0_(ido, bmat, &itry, &c_false, n, &j, &v[v_offset], ldv, &resid[1],
518 rnorm, &ipntr[1], &workd[1], &ierr, (ftnlen)1);
519 if (*ido != 99) {
520 goto L9000;
521 }
522 if (ierr < 0) {
523 ++itry;
524 if (itry <= 3) {
525 goto L20;
526 }
527
528 /* %------------------------------------------------% */
529 /* | Give up after several restart attempts. | */
530 /* | Set INFO to the size of the invariant subspace | */
531 /* | which spans OP and exit. | */
532 /* %------------------------------------------------% */
533
534 *info = j - 1;
535 second_(&t1);
536 timing_1.tnaitr += t1 - t0;
537 *ido = 99;
538 goto L9000;
539 }
540
541 L40:
542
543 /* %---------------------------------------------------------% */
544 /* | STEP 2: v_{j} = r_{j-1}/rnorm and p_{j} = p_{j}/rnorm | */
545 /* | Note that p_{j} = B*r_{j-1}. In order to avoid overflow | */
546 /* | when reciprocating a small RNORM, test against lower | */
547 /* | machine bound. | */
548 /* %---------------------------------------------------------% */
549
550 scopy_(n, &resid[1], &c__1, &v[j * v_dim1 + 1], &c__1);
551 if (*rnorm >= unfl) {
552 temp1 = 1.f / *rnorm;
553 sscal_(n, &temp1, &v[j * v_dim1 + 1], &c__1);
554 sscal_(n, &temp1, &workd[ipj], &c__1);
555 } else {
556
557 /* %-----------------------------------------% */
558 /* | To scale both v_{j} and p_{j} carefully | */
559 /* | use LAPACK routine SLASCL | */
560 /* %-----------------------------------------% */
561
562 slascl_("General", &i__, &i__, rnorm, &c_b25, n, &c__1, &v[j * v_dim1
563 + 1], n, &infol, (ftnlen)7);
564 slascl_("General", &i__, &i__, rnorm, &c_b25, n, &c__1, &workd[ipj],
565 n, &infol, (ftnlen)7);
566 }
567
568 /* %------------------------------------------------------% */
569 /* | STEP 3: r_{j} = OP*v_{j}; Note that p_{j} = B*v_{j} | */
570 /* | Note that this is not quite yet r_{j}. See STEP 4 | */
571 /* %------------------------------------------------------% */
572
573 step3 = TRUE_;
574 ++timing_1.nopx;
575 second_(&t2);
576 scopy_(n, &v[j * v_dim1 + 1], &c__1, &workd[ivj], &c__1);
577 ipntr[1] = ivj;
578 ipntr[2] = irj;
579 ipntr[3] = ipj;
580 *ido = 1;
581
582 /* %-----------------------------------% */
583 /* | Exit in order to compute OP*v_{j} | */
584 /* %-----------------------------------% */
585
586 goto L9000;
587 L50:
588
589 /* %----------------------------------% */
590 /* | Back from reverse communication; | */
591 /* | WORKD(IRJ:IRJ+N-1) := OP*v_{j} | */
592 /* | if step3 = .true. | */
593 /* %----------------------------------% */
594
595 second_(&t3);
596 timing_1.tmvopx += t3 - t2;
597 step3 = FALSE_;
598
599 /* %------------------------------------------% */
600 /* | Put another copy of OP*v_{j} into RESID. | */
601 /* %------------------------------------------% */
602
603 scopy_(n, &workd[irj], &c__1, &resid[1], &c__1);
604
605 /* %---------------------------------------% */
606 /* | STEP 4: Finish extending the Arnoldi | */
607 /* | factorization to length j. | */
608 /* %---------------------------------------% */
609
610 second_(&t2);
611 if (*(unsigned char *)bmat == 'G') {
612 ++timing_1.nbx;
613 step4 = TRUE_;
614 ipntr[1] = irj;
615 ipntr[2] = ipj;
616 *ido = 2;
617
618 /* %-------------------------------------% */
619 /* | Exit in order to compute B*OP*v_{j} | */
620 /* %-------------------------------------% */
621
622 goto L9000;
623 } else if (*(unsigned char *)bmat == 'I') {
624 scopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
625 }
626 L60:
627
628 /* %----------------------------------% */
629 /* | Back from reverse communication; | */
630 /* | WORKD(IPJ:IPJ+N-1) := B*OP*v_{j} | */
631 /* | if step4 = .true. | */
632 /* %----------------------------------% */
633
634 if (*(unsigned char *)bmat == 'G') {
635 second_(&t3);
636 timing_1.tmvbx += t3 - t2;
637 }
638
639 step4 = FALSE_;
640
641 /* %-------------------------------------% */
642 /* | The following is needed for STEP 5. | */
643 /* | Compute the B-norm of OP*v_{j}. | */
644 /* %-------------------------------------% */
645
646 if (*(unsigned char *)bmat == 'G') {
647 wnorm = sdot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
648 wnorm = sqrt((dabs(wnorm)));
649 } else if (*(unsigned char *)bmat == 'I') {
650 wnorm = snrm2_(n, &resid[1], &c__1);
651 }
652
653 /* %-----------------------------------------% */
654 /* | Compute the j-th residual corresponding | */
655 /* | to the j step factorization. | */
656 /* | Use Classical Gram Schmidt and compute: | */
657 /* | w_{j} <- V_{j}^T * B * OP * v_{j} | */
658 /* | r_{j} <- OP*v_{j} - V_{j} * w_{j} | */
659 /* %-----------------------------------------% */
660
661
662 /* %------------------------------------------% */
663 /* | Compute the j Fourier coefficients w_{j} | */
664 /* | WORKD(IPJ:IPJ+N-1) contains B*OP*v_{j}. | */
665 /* %------------------------------------------% */
666
667 sgemv_("T", n, &j, &c_b25, &v[v_offset], ldv, &workd[ipj], &c__1, &c_b47,
668 &h__[j * h_dim1 + 1], &c__1, (ftnlen)1);
669
670 /* %--------------------------------------% */
671 /* | Orthogonalize r_{j} against V_{j}. | */
672 /* | RESID contains OP*v_{j}. See STEP 3. | */
673 /* %--------------------------------------% */
674
675 sgemv_("N", n, &j, &c_b50, &v[v_offset], ldv, &h__[j * h_dim1 + 1], &c__1,
676 &c_b25, &resid[1], &c__1, (ftnlen)1);
677
678 if (j > 1) {
679 h__[j + (j - 1) * h_dim1] = betaj;
680 }
681
682 second_(&t4);
683
684 orth1 = TRUE_;
685
686 second_(&t2);
687 if (*(unsigned char *)bmat == 'G') {
688 ++timing_1.nbx;
689 scopy_(n, &resid[1], &c__1, &workd[irj], &c__1);
690 ipntr[1] = irj;
691 ipntr[2] = ipj;
692 *ido = 2;
693
694 /* %----------------------------------% */
695 /* | Exit in order to compute B*r_{j} | */
696 /* %----------------------------------% */
697
698 goto L9000;
699 } else if (*(unsigned char *)bmat == 'I') {
700 scopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
701 }
702 L70:
703
704 /* %---------------------------------------------------% */
705 /* | Back from reverse communication if ORTH1 = .true. | */
706 /* | WORKD(IPJ:IPJ+N-1) := B*r_{j}. | */
707 /* %---------------------------------------------------% */
708
709 if (*(unsigned char *)bmat == 'G') {
710 second_(&t3);
711 timing_1.tmvbx += t3 - t2;
712 }
713
714 orth1 = FALSE_;
715
716 /* %------------------------------% */
717 /* | Compute the B-norm of r_{j}. | */
718 /* %------------------------------% */
719
720 if (*(unsigned char *)bmat == 'G') {
721 *rnorm = sdot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
722 *rnorm = sqrt((dabs(*rnorm)));
723 } else if (*(unsigned char *)bmat == 'I') {
724 *rnorm = snrm2_(n, &resid[1], &c__1);
725 }
726
727 /* %-----------------------------------------------------------% */
728 /* | STEP 5: Re-orthogonalization / Iterative refinement phase | */
729 /* | Maximum NITER_ITREF tries. | */
730 /* | | */
731 /* | s = V_{j}^T * B * r_{j} | */
732 /* | r_{j} = r_{j} - V_{j}*s | */
733 /* | alphaj = alphaj + s_{j} | */
734 /* | | */
735 /* | The stopping criteria used for iterative refinement is | */
736 /* | discussed in Parlett's book SEP, page 107 and in Gragg & | */
737 /* | Reichel ACM TOMS paper; Algorithm 686, Dec. 1990. | */
738 /* | Determine if we need to correct the residual. The goal is | */
739 /* | to enforce ||v(:,1:j)^T * r_{j}|| .le. eps * || r_{j} || | */
740 /* | The following test determines whether the sine of the | */
741 /* | angle between OP*x and the computed residual is less | */
742 /* | than or equal to 0.717. | */
743 /* %-----------------------------------------------------------% */
744
745 if (*rnorm > wnorm * .717f) {
746 goto L100;
747 }
748 iter = 0;
749 ++timing_1.nrorth;
750
751 /* %---------------------------------------------------% */
752 /* | Enter the Iterative refinement phase. If further | */
753 /* | refinement is necessary, loop back here. The loop | */
754 /* | variable is ITER. Perform a step of Classical | */
755 /* | Gram-Schmidt using all the Arnoldi vectors V_{j} | */
756 /* %---------------------------------------------------% */
757
758 L80:
759
760 if (msglvl > 2) {
761 xtemp[0] = wnorm;
762 xtemp[1] = *rnorm;
763 svout_(&debug_1.logfil, &c__2, xtemp, &debug_1.ndigit, "_naitr: re-o"
764 "rthonalization; wnorm and rnorm are", (ftnlen)47);
765 svout_(&debug_1.logfil, &j, &h__[j * h_dim1 + 1], &debug_1.ndigit,
766 "_naitr: j-th column of H", (ftnlen)24);
767 }
768
769 /* %----------------------------------------------------% */
770 /* | Compute V_{j}^T * B * r_{j}. | */
771 /* | WORKD(IRJ:IRJ+J-1) = v(:,1:J)'*WORKD(IPJ:IPJ+N-1). | */
772 /* %----------------------------------------------------% */
773
774 sgemv_("T", n, &j, &c_b25, &v[v_offset], ldv, &workd[ipj], &c__1, &c_b47,
775 &workd[irj], &c__1, (ftnlen)1);
776
777 /* %---------------------------------------------% */
778 /* | Compute the correction to the residual: | */
779 /* | r_{j} = r_{j} - V_{j} * WORKD(IRJ:IRJ+J-1). | */
780 /* | The correction to H is v(:,1:J)*H(1:J,1:J) | */
781 /* | + v(:,1:J)*WORKD(IRJ:IRJ+J-1)*e'_j. | */
782 /* %---------------------------------------------% */
783
784 sgemv_("N", n, &j, &c_b50, &v[v_offset], ldv, &workd[irj], &c__1, &c_b25,
785 &resid[1], &c__1, (ftnlen)1);
786 saxpy_(&j, &c_b25, &workd[irj], &c__1, &h__[j * h_dim1 + 1], &c__1);
787
788 orth2 = TRUE_;
789 second_(&t2);
790 if (*(unsigned char *)bmat == 'G') {
791 ++timing_1.nbx;
792 scopy_(n, &resid[1], &c__1, &workd[irj], &c__1);
793 ipntr[1] = irj;
794 ipntr[2] = ipj;
795 *ido = 2;
796
797 /* %-----------------------------------% */
798 /* | Exit in order to compute B*r_{j}. | */
799 /* | r_{j} is the corrected residual. | */
800 /* %-----------------------------------% */
801
802 goto L9000;
803 } else if (*(unsigned char *)bmat == 'I') {
804 scopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
805 }
806 L90:
807
808 /* %---------------------------------------------------% */
809 /* | Back from reverse communication if ORTH2 = .true. | */
810 /* %---------------------------------------------------% */
811
812 if (*(unsigned char *)bmat == 'G') {
813 second_(&t3);
814 timing_1.tmvbx += t3 - t2;
815 }
816
817 /* %-----------------------------------------------------% */
818 /* | Compute the B-norm of the corrected residual r_{j}. | */
819 /* %-----------------------------------------------------% */
820
821 if (*(unsigned char *)bmat == 'G') {
822 rnorm1 = sdot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
823 rnorm1 = sqrt((dabs(rnorm1)));
824 } else if (*(unsigned char *)bmat == 'I') {
825 rnorm1 = snrm2_(n, &resid[1], &c__1);
826 }
827
828 if (msglvl > 0 && iter > 0) {
829 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_naitr: Iterati"
830 "ve refinement for Arnoldi residual", (ftnlen)49);
831 if (msglvl > 2) {
832 xtemp[0] = *rnorm;
833 xtemp[1] = rnorm1;
834 svout_(&debug_1.logfil, &c__2, xtemp, &debug_1.ndigit, "_naitr: "
835 "iterative refinement ; rnorm and rnorm1 are", (ftnlen)51);
836 }
837 }
838
839 /* %-----------------------------------------% */
840 /* | Determine if we need to perform another | */
841 /* | step of re-orthogonalization. | */
842 /* %-----------------------------------------% */
843
844 if (rnorm1 > *rnorm * .717f) {
845
846 /* %---------------------------------------% */
847 /* | No need for further refinement. | */
848 /* | The cosine of the angle between the | */
849 /* | corrected residual vector and the old | */
850 /* | residual vector is greater than 0.717 | */
851 /* | In other words the corrected residual | */
852 /* | and the old residual vector share an | */
853 /* | angle of less than arcCOS(0.717) | */
854 /* %---------------------------------------% */
855
856 *rnorm = rnorm1;
857
858 } else {
859
860 /* %-------------------------------------------% */
861 /* | Another step of iterative refinement step | */
862 /* | is required. NITREF is used by stat.h | */
863 /* %-------------------------------------------% */
864
865 ++timing_1.nitref;
866 *rnorm = rnorm1;
867 ++iter;
868 if (iter <= 1) {
869 goto L80;
870 }
871
872 /* %-------------------------------------------------% */
873 /* | Otherwise RESID is numerically in the span of V | */
874 /* %-------------------------------------------------% */
875
876 i__1 = *n;
877 for (jj = 1; jj <= i__1; ++jj) {
878 resid[jj] = 0.f;
879 /* L95: */
880 }
881 *rnorm = 0.f;
882 }
883
884 /* %----------------------------------------------% */
885 /* | Branch here directly if iterative refinement | */
886 /* | wasn't necessary or after at most NITER_REF | */
887 /* | steps of iterative refinement. | */
888 /* %----------------------------------------------% */
889
890 L100:
891
892 rstart = FALSE_;
893 orth2 = FALSE_;
894
895 second_(&t5);
896 timing_1.titref += t5 - t4;
897
898 /* %------------------------------------% */
899 /* | STEP 6: Update j = j+1; Continue | */
900 /* %------------------------------------% */
901
902 ++j;
903 if (j > *k + *np) {
904 second_(&t1);
905 timing_1.tnaitr += t1 - t0;
906 *ido = 99;
907 i__1 = *k + *np - 1;
908 for (i__ = max(1,*k); i__ <= i__1; ++i__) {
909
910 /* %--------------------------------------------% */
911 /* | Check for splitting and deflation. | */
912 /* | Use a standard test as in the QR algorithm | */
913 /* | REFERENCE: LAPACK subroutine slahqr | */
914 /* %--------------------------------------------% */
915
916 tst1 = (r__1 = h__[i__ + i__ * h_dim1], dabs(r__1)) + (r__2 = h__[
917 i__ + 1 + (i__ + 1) * h_dim1], dabs(r__2));
918 if (tst1 == 0.f) {
919 i__2 = *k + *np;
920 tst1 = slanhs_("1", &i__2, &h__[h_offset], ldh, &workd[*n + 1]
921 , (ftnlen)1);
922 }
923 /* Computing MAX */
924 r__2 = ulp * tst1;
925 if ((r__1 = h__[i__ + 1 + i__ * h_dim1], dabs(r__1)) <= dmax(r__2,
926 smlnum)) {
927 h__[i__ + 1 + i__ * h_dim1] = 0.f;
928 }
929 /* L110: */
930 }
931
932 if (msglvl > 2) {
933 i__1 = *k + *np;
934 i__2 = *k + *np;
935 smout_(&debug_1.logfil, &i__1, &i__2, &h__[h_offset], ldh, &
936 debug_1.ndigit, "_naitr: Final upper Hessenberg matrix H"
937 " of order K+NP", (ftnlen)53);
938 }
939
940 goto L9000;
941 }
942
943 /* %--------------------------------------------------------% */
944 /* | Loop back to extend the factorization by another step. | */
945 /* %--------------------------------------------------------% */
946
947 goto L1000;
948
949 /* %---------------------------------------------------------------% */
950 /* | | */
951 /* | E N D O F M A I N I T E R A T I O N L O O P | */
952 /* | | */
953 /* %---------------------------------------------------------------% */
954
955 L9000:
956 return 0;
957
958 /* %---------------% */
959 /* | End of snaitr | */
960 /* %---------------% */
961
962 } /* snaitr_ */
963