Debian Codegraph @

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

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