Debian Codegraph @

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

raw
1 /* ./src_f77/dsaitr.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_DSAITR;
15
16 #define debug_1 debug_DSAITR
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_DSAITR;
25
26 #define timing_1 timing_DSAITR
27
28 /* Table of constant values */
29
30 static integer c__1 = 1;
31 static logical c_false = FALSE_;
32 static doublereal c_b24 = 1.;
33 static doublereal c_b49 = 0.;
34 static doublereal c_b57 = -1.;
35 static integer c__2 = 2;
36
37 /* ----------------------------------------------------------------------- */
38 /* \BeginDoc */
39
40 /* \Name: dsaitr */
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 dsaupd. The B-norm of r_{k+p} is also */
55 /* computed and returned. */
56
57 /* \Usage: */
58 /* call dsaitr */
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 dsaupd. */
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 Double precision 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 Double precision 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 Double precision 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 Double precision (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 Double precision 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 /* dgetv0 ARPACK routine to generate the initial vector. */
169 /* ivout ARPACK utility routine that prints integers. */
170 /* dmout ARPACK utility routine that prints matrices. */
171 /* dvout ARPACK utility routine that prints vectors. */
172 /* dlamch LAPACK routine that determines machine constants. */
173 /* dlascl LAPACK routine for careful scaling of a matrix. */
174 /* dgemv Level 2 BLAS routine for matrix vector multiplication. */
175 /* daxpy Level 1 BLAS that computes a vector triad. */
176 /* dscal Level 1 BLAS that scales a vector. */
177 /* dcopy Level 1 BLAS that copies one vector to another . */
178 /* ddot Level 1 BLAS that computes the scalar product of two vectors. */
179 /* dnrm2 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 dsaupd */
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 dsaitr_(integer *ido, char *bmat, integer *n, integer *k,
241 integer *np, integer *mode, doublereal *resid, doublereal *rnorm,
242 doublereal *v, integer *ldv, doublereal *h__, integer *ldh, integer *
243 ipntr, doublereal *workd, 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;
259 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
260 integer *);
261 static integer ierr, iter, itry;
262 extern doublereal dnrm2_(integer *, doublereal *, integer *);
263 static doublereal temp1;
264 static logical orth1, orth2, step3, step4;
265 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
266 integer *), dgemv_(char *, integer *, integer *, doublereal *,
267 doublereal *, integer *, doublereal *, integer *, doublereal *,
268 doublereal *, integer *, ftnlen);
269 static integer infol;
270 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
271 doublereal *, integer *);
272 static doublereal xtemp[2];
273 extern /* Subroutine */ int dvout_(integer *, integer *, doublereal *,
274 integer *, char *, ftnlen);
275 static doublereal wnorm;
276 extern /* Subroutine */ int ivout_(integer *, integer *, integer *,
277 integer *, char *, ftnlen), dgetv0_(integer *, char *, integer *,
278 logical *, integer *, integer *, doublereal *, integer *,
279 doublereal *, doublereal *, integer *, doublereal *, integer *,
280 ftnlen);
281 static doublereal rnorm1;
282 extern doublereal dlamch_(char *, ftnlen);
283 extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
284 doublereal *, doublereal *, integer *, integer *, doublereal *,
285 integer *, integer *, ftnlen), second_(real *);
286 static doublereal safmin;
287 static logical rstart;
288 static integer msglvl;
289
290
291 /* %----------------------------------------------------% */
292 /* | Include files for debugging and timing information | */
293 /* %----------------------------------------------------% */
294
295
296 /* \SCCS Information: @(#) */
297 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
298
299 /* %---------------------------------% */
300 /* | See debug.doc for documentation | */
301 /* %---------------------------------% */
302
303 /* %------------------% */
304 /* | Scalar Arguments | */
305 /* %------------------% */
306
307 /* %--------------------------------% */
308 /* | See stat.doc for documentation | */
309 /* %--------------------------------% */
310
311 /* \SCCS Information: @(#) */
312 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
313
314
315
316 /* %-----------------% */
317 /* | Array Arguments | */
318 /* %-----------------% */
319
320
321 /* %------------% */
322 /* | Parameters | */
323 /* %------------% */
324
325
326 /* %---------------% */
327 /* | Local Scalars | */
328 /* %---------------% */
329
330
331 /* %-----------------------% */
332 /* | Local Array Arguments | */
333 /* %-----------------------% */
334
335
336 /* %----------------------% */
337 /* | External Subroutines | */
338 /* %----------------------% */
339
340
341 /* %--------------------% */
342 /* | External Functions | */
343 /* %--------------------% */
344
345
346 /* %-----------------% */
347 /* | Data statements | */
348 /* %-----------------% */
349
350 /* Parameter adjustments */
351 --workd;
352 --resid;
353 v_dim1 = *ldv;
354 v_offset = 1 + v_dim1;
355 v -= v_offset;
356 h_dim1 = *ldh;
357 h_offset = 1 + h_dim1;
358 h__ -= h_offset;
359 --ipntr;
360
361 /* Function Body */
362
363 /* %-----------------------% */
364 /* | Executable Statements | */
365 /* %-----------------------% */
366
367 if (first) {
368 first = FALSE_;
369
370 /* %--------------------------------% */
371 /* | safmin = safe minimum is such | */
372 /* | that 1/sfmin does not overflow | */
373 /* %--------------------------------% */
374
375 safmin = dlamch_("safmin", (ftnlen)6);
376 }
377
378 if (*ido == 0) {
379
380 /* %-------------------------------% */
381 /* | Initialize timing statistics | */
382 /* | & message level for debugging | */
383 /* %-------------------------------% */
384
385 second_(&t0);
386 msglvl = debug_1.msaitr;
387
388 /* %------------------------------% */
389 /* | Initial call to this routine | */
390 /* %------------------------------% */
391
392 *info = 0;
393 step3 = FALSE_;
394 step4 = FALSE_;
395 rstart = FALSE_;
396 orth1 = FALSE_;
397 orth2 = FALSE_;
398
399 /* %--------------------------------% */
400 /* | Pointer to the current step of | */
401 /* | the factorization to build | */
402 /* %--------------------------------% */
403
404 j = *k + 1;
405
406 /* %------------------------------------------% */
407 /* | Pointers used for reverse communication | */
408 /* | when using WORKD. | */
409 /* %------------------------------------------% */
410
411 ipj = 1;
412 irj = ipj + *n;
413 ivj = irj + *n;
414 }
415
416 /* %-------------------------------------------------% */
417 /* | When in reverse communication mode one of: | */
418 /* | STEP3, STEP4, ORTH1, ORTH2, RSTART | */
419 /* | will be .true. | */
420 /* | STEP3: return from computing OP*v_{j}. | */
421 /* | STEP4: return from computing B-norm of OP*v_{j} | */
422 /* | ORTH1: return from computing B-norm of r_{j+1} | */
423 /* | ORTH2: return from computing B-norm of | */
424 /* | correction to the residual vector. | */
425 /* | RSTART: return from OP computations needed by | */
426 /* | dgetv0. | */
427 /* %-------------------------------------------------% */
428
429 if (step3) {
430 goto L50;
431 }
432 if (step4) {
433 goto L60;
434 }
435 if (orth1) {
436 goto L70;
437 }
438 if (orth2) {
439 goto L90;
440 }
441 if (rstart) {
442 goto L30;
443 }
444
445 /* %------------------------------% */
446 /* | Else this is the first step. | */
447 /* %------------------------------% */
448
449 /* %--------------------------------------------------------------% */
450 /* | | */
451 /* | A R N O L D I I T E R A T I O N L O O P | */
452 /* | | */
453 /* | Note: B*r_{j-1} is already in WORKD(1:N)=WORKD(IPJ:IPJ+N-1) | */
454 /* %--------------------------------------------------------------% */
455
456 L1000:
457
458 if (msglvl > 2) {
459 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_saitr: generat"
460 "ing Arnoldi vector no.", (ftnlen)37);
461 dvout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_saitr: B-no"
462 "rm of the current residual =", (ftnlen)40);
463 }
464
465 /* %---------------------------------------------------------% */
466 /* | Check for exact zero. Equivalent to determing whether a | */
467 /* | j-step Arnoldi factorization is present. | */
468 /* %---------------------------------------------------------% */
469
470 if (*rnorm > 0.) {
471 goto L40;
472 }
473
474 /* %---------------------------------------------------% */
475 /* | Invariant subspace found, generate a new starting | */
476 /* | vector which is orthogonal to the current Arnoldi | */
477 /* | basis and continue the iteration. | */
478 /* %---------------------------------------------------% */
479
480 if (msglvl > 0) {
481 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_saitr: ****** "
482 "restart at step ******", (ftnlen)37);
483 }
484
485 /* %---------------------------------------------% */
486 /* | ITRY is the loop variable that controls the | */
487 /* | maximum amount of times that a restart is | */
488 /* | attempted. NRSTRT is used by stat.h | */
489 /* %---------------------------------------------% */
490
491 ++timing_1.nrstrt;
492 itry = 1;
493 L20:
494 rstart = TRUE_;
495 *ido = 0;
496 L30:
497
498 /* %--------------------------------------% */
499 /* | If in reverse communication mode and | */
500 /* | RSTART = .true. flow returns here. | */
501 /* %--------------------------------------% */
502
503 dgetv0_(ido, bmat, &itry, &c_false, n, &j, &v[v_offset], ldv, &resid[1],
504 rnorm, &ipntr[1], &workd[1], &ierr, (ftnlen)1);
505 if (*ido != 99) {
506 goto L9000;
507 }
508 if (ierr < 0) {
509 ++itry;
510 if (itry <= 3) {
511 goto L20;
512 }
513
514 /* %------------------------------------------------% */
515 /* | Give up after several restart attempts. | */
516 /* | Set INFO to the size of the invariant subspace | */
517 /* | which spans OP and exit. | */
518 /* %------------------------------------------------% */
519
520 *info = j - 1;
521 second_(&t1);
522 timing_1.tsaitr += t1 - t0;
523 *ido = 99;
524 goto L9000;
525 }
526
527 L40:
528
529 /* %---------------------------------------------------------% */
530 /* | STEP 2: v_{j} = r_{j-1}/rnorm and p_{j} = p_{j}/rnorm | */
531 /* | Note that p_{j} = B*r_{j-1}. In order to avoid overflow | */
532 /* | when reciprocating a small RNORM, test against lower | */
533 /* | machine bound. | */
534 /* %---------------------------------------------------------% */
535
536 dcopy_(n, &resid[1], &c__1, &v[j * v_dim1 + 1], &c__1);
537 if (*rnorm >= safmin) {
538 temp1 = 1. / *rnorm;
539 dscal_(n, &temp1, &v[j * v_dim1 + 1], &c__1);
540 dscal_(n, &temp1, &workd[ipj], &c__1);
541 } else {
542
543 /* %-----------------------------------------% */
544 /* | To scale both v_{j} and p_{j} carefully | */
545 /* | use LAPACK routine SLASCL | */
546 /* %-----------------------------------------% */
547
548 dlascl_("General", &i__, &i__, rnorm, &c_b24, n, &c__1, &v[j * v_dim1
549 + 1], n, &infol, (ftnlen)7);
550 dlascl_("General", &i__, &i__, rnorm, &c_b24, n, &c__1, &workd[ipj],
551 n, &infol, (ftnlen)7);
552 }
553
554 /* %------------------------------------------------------% */
555 /* | STEP 3: r_{j} = OP*v_{j}; Note that p_{j} = B*v_{j} | */
556 /* | Note that this is not quite yet r_{j}. See STEP 4 | */
557 /* %------------------------------------------------------% */
558
559 step3 = TRUE_;
560 ++timing_1.nopx;
561 second_(&t2);
562 dcopy_(n, &v[j * v_dim1 + 1], &c__1, &workd[ivj], &c__1);
563 ipntr[1] = ivj;
564 ipntr[2] = irj;
565 ipntr[3] = ipj;
566 *ido = 1;
567
568 /* %-----------------------------------% */
569 /* | Exit in order to compute OP*v_{j} | */
570 /* %-----------------------------------% */
571
572 goto L9000;
573 L50:
574
575 /* %-----------------------------------% */
576 /* | Back from reverse communication; | */
577 /* | WORKD(IRJ:IRJ+N-1) := OP*v_{j}. | */
578 /* %-----------------------------------% */
579
580 second_(&t3);
581 timing_1.tmvopx += t3 - t2;
582
583 step3 = FALSE_;
584
585 /* %------------------------------------------% */
586 /* | Put another copy of OP*v_{j} into RESID. | */
587 /* %------------------------------------------% */
588
589 dcopy_(n, &workd[irj], &c__1, &resid[1], &c__1);
590
591 /* %-------------------------------------------% */
592 /* | STEP 4: Finish extending the symmetric | */
593 /* | Arnoldi to length j. If MODE = 2 | */
594 /* | then B*OP = B*inv(B)*A = A and | */
595 /* | we don't need to compute B*OP. | */
596 /* | NOTE: If MODE = 2 WORKD(IVJ:IVJ+N-1) is | */
597 /* | assumed to have A*v_{j}. | */
598 /* %-------------------------------------------% */
599
600 if (*mode == 2) {
601 goto L65;
602 }
603 second_(&t2);
604 if (*(unsigned char *)bmat == 'G') {
605 ++timing_1.nbx;
606 step4 = TRUE_;
607 ipntr[1] = irj;
608 ipntr[2] = ipj;
609 *ido = 2;
610
611 /* %-------------------------------------% */
612 /* | Exit in order to compute B*OP*v_{j} | */
613 /* %-------------------------------------% */
614
615 goto L9000;
616 } else if (*(unsigned char *)bmat == 'I') {
617 dcopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
618 }
619 L60:
620
621 /* %-----------------------------------% */
622 /* | Back from reverse communication; | */
623 /* | WORKD(IPJ:IPJ+N-1) := B*OP*v_{j}. | */
624 /* %-----------------------------------% */
625
626 if (*(unsigned char *)bmat == 'G') {
627 second_(&t3);
628 timing_1.tmvbx += t3 - t2;
629 }
630
631 step4 = FALSE_;
632
633 /* %-------------------------------------% */
634 /* | The following is needed for STEP 5. | */
635 /* | Compute the B-norm of OP*v_{j}. | */
636 /* %-------------------------------------% */
637
638 L65:
639 if (*mode == 2) {
640
641 /* %----------------------------------% */
642 /* | Note that the B-norm of OP*v_{j} | */
643 /* | is the inv(B)-norm of A*v_{j}. | */
644 /* %----------------------------------% */
645
646 wnorm = ddot_(n, &resid[1], &c__1, &workd[ivj], &c__1);
647 wnorm = sqrt((abs(wnorm)));
648 } else if (*(unsigned char *)bmat == 'G') {
649 wnorm = ddot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
650 wnorm = sqrt((abs(wnorm)));
651 } else if (*(unsigned char *)bmat == 'I') {
652 wnorm = dnrm2_(n, &resid[1], &c__1);
653 }
654
655 /* %-----------------------------------------% */
656 /* | Compute the j-th residual corresponding | */
657 /* | to the j step factorization. | */
658 /* | Use Classical Gram Schmidt and compute: | */
659 /* | w_{j} <- V_{j}^T * B * OP * v_{j} | */
660 /* | r_{j} <- OP*v_{j} - V_{j} * w_{j} | */
661 /* %-----------------------------------------% */
662
663
664 /* %------------------------------------------% */
665 /* | Compute the j Fourier coefficients w_{j} | */
666 /* | WORKD(IPJ:IPJ+N-1) contains B*OP*v_{j}. | */
667 /* %------------------------------------------% */
668
669 if (*mode != 2) {
670 dgemv_("T", n, &j, &c_b24, &v[v_offset], ldv, &workd[ipj], &c__1, &
671 c_b49, &workd[irj], &c__1, (ftnlen)1);
672 } else if (*mode == 2) {
673 dgemv_("T", n, &j, &c_b24, &v[v_offset], ldv, &workd[ivj], &c__1, &
674 c_b49, &workd[irj], &c__1, (ftnlen)1);
675 }
676
677 /* %--------------------------------------% */
678 /* | Orthgonalize r_{j} against V_{j}. | */
679 /* | RESID contains OP*v_{j}. See STEP 3. | */
680 /* %--------------------------------------% */
681
682 dgemv_("N", n, &j, &c_b57, &v[v_offset], ldv, &workd[irj], &c__1, &c_b24,
683 &resid[1], &c__1, (ftnlen)1);
684
685 /* %--------------------------------------% */
686 /* | Extend H to have j rows and columns. | */
687 /* %--------------------------------------% */
688
689 h__[j + (h_dim1 << 1)] = workd[irj + j - 1];
690 if (j == 1 || rstart) {
691 h__[j + h_dim1] = 0.;
692 } else {
693 h__[j + h_dim1] = *rnorm;
694 }
695 second_(&t4);
696
697 orth1 = TRUE_;
698 iter = 0;
699
700 second_(&t2);
701 if (*(unsigned char *)bmat == 'G') {
702 ++timing_1.nbx;
703 dcopy_(n, &resid[1], &c__1, &workd[irj], &c__1);
704 ipntr[1] = irj;
705 ipntr[2] = ipj;
706 *ido = 2;
707
708 /* %----------------------------------% */
709 /* | Exit in order to compute B*r_{j} | */
710 /* %----------------------------------% */
711
712 goto L9000;
713 } else if (*(unsigned char *)bmat == 'I') {
714 dcopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
715 }
716 L70:
717
718 /* %---------------------------------------------------% */
719 /* | Back from reverse communication if ORTH1 = .true. | */
720 /* | WORKD(IPJ:IPJ+N-1) := B*r_{j}. | */
721 /* %---------------------------------------------------% */
722
723 if (*(unsigned char *)bmat == 'G') {
724 second_(&t3);
725 timing_1.tmvbx += t3 - t2;
726 }
727
728 orth1 = FALSE_;
729
730 /* %------------------------------% */
731 /* | Compute the B-norm of r_{j}. | */
732 /* %------------------------------% */
733
734 if (*(unsigned char *)bmat == 'G') {
735 *rnorm = ddot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
736 *rnorm = sqrt((abs(*rnorm)));
737 } else if (*(unsigned char *)bmat == 'I') {
738 *rnorm = dnrm2_(n, &resid[1], &c__1);
739 }
740
741 /* %-----------------------------------------------------------% */
742 /* | STEP 5: Re-orthogonalization / Iterative refinement phase | */
743 /* | Maximum NITER_ITREF tries. | */
744 /* | | */
745 /* | s = V_{j}^T * B * r_{j} | */
746 /* | r_{j} = r_{j} - V_{j}*s | */
747 /* | alphaj = alphaj + s_{j} | */
748 /* | | */
749 /* | The stopping criteria used for iterative refinement is | */
750 /* | discussed in Parlett's book SEP, page 107 and in Gragg & | */
751 /* | Reichel ACM TOMS paper; Algorithm 686, Dec. 1990. | */
752 /* | Determine if we need to correct the residual. The goal is | */
753 /* | to enforce ||v(:,1:j)^T * r_{j}|| .le. eps * || r_{j} || | */
754 /* %-----------------------------------------------------------% */
755
756 if (*rnorm > wnorm * .717f) {
757 goto L100;
758 }
759 ++timing_1.nrorth;
760
761 /* %---------------------------------------------------% */
762 /* | Enter the Iterative refinement phase. If further | */
763 /* | refinement is necessary, loop back here. The loop | */
764 /* | variable is ITER. Perform a step of Classical | */
765 /* | Gram-Schmidt using all the Arnoldi vectors V_{j} | */
766 /* %---------------------------------------------------% */
767
768 L80:
769
770 if (msglvl > 2) {
771 xtemp[0] = wnorm;
772 xtemp[1] = *rnorm;
773 dvout_(&debug_1.logfil, &c__2, xtemp, &debug_1.ndigit, "_saitr: re-o"
774 "rthonalization ; wnorm and rnorm are", (ftnlen)48);
775 }
776
777 /* %----------------------------------------------------% */
778 /* | Compute V_{j}^T * B * r_{j}. | */
779 /* | WORKD(IRJ:IRJ+J-1) = v(:,1:J)'*WORKD(IPJ:IPJ+N-1). | */
780 /* %----------------------------------------------------% */
781
782 dgemv_("T", n, &j, &c_b24, &v[v_offset], ldv, &workd[ipj], &c__1, &c_b49,
783 &workd[irj], &c__1, (ftnlen)1);
784
785 /* %----------------------------------------------% */
786 /* | Compute the correction to the residual: | */
787 /* | r_{j} = r_{j} - V_{j} * WORKD(IRJ:IRJ+J-1). | */
788 /* | The correction to H is v(:,1:J)*H(1:J,1:J) + | */
789 /* | v(:,1:J)*WORKD(IRJ:IRJ+J-1)*e'_j, but only | */
790 /* | H(j,j) is updated. | */
791 /* %----------------------------------------------% */
792
793 dgemv_("N", n, &j, &c_b57, &v[v_offset], ldv, &workd[irj], &c__1, &c_b24,
794 &resid[1], &c__1, (ftnlen)1);
795
796 if (j == 1 || rstart) {
797 h__[j + h_dim1] = 0.;
798 }
799 h__[j + (h_dim1 << 1)] += workd[irj + j - 1];
800
801 orth2 = TRUE_;
802 second_(&t2);
803 if (*(unsigned char *)bmat == 'G') {
804 ++timing_1.nbx;
805 dcopy_(n, &resid[1], &c__1, &workd[irj], &c__1);
806 ipntr[1] = irj;
807 ipntr[2] = ipj;
808 *ido = 2;
809
810 /* %-----------------------------------% */
811 /* | Exit in order to compute B*r_{j}. | */
812 /* | r_{j} is the corrected residual. | */
813 /* %-----------------------------------% */
814
815 goto L9000;
816 } else if (*(unsigned char *)bmat == 'I') {
817 dcopy_(n, &resid[1], &c__1, &workd[ipj], &c__1);
818 }
819 L90:
820
821 /* %---------------------------------------------------% */
822 /* | Back from reverse communication if ORTH2 = .true. | */
823 /* %---------------------------------------------------% */
824
825 if (*(unsigned char *)bmat == 'G') {
826 second_(&t3);
827 timing_1.tmvbx += t3 - t2;
828 }
829
830 /* %-----------------------------------------------------% */
831 /* | Compute the B-norm of the corrected residual r_{j}. | */
832 /* %-----------------------------------------------------% */
833
834 if (*(unsigned char *)bmat == 'G') {
835 rnorm1 = ddot_(n, &resid[1], &c__1, &workd[ipj], &c__1);
836 rnorm1 = sqrt((abs(rnorm1)));
837 } else if (*(unsigned char *)bmat == 'I') {
838 rnorm1 = dnrm2_(n, &resid[1], &c__1);
839 }
840
841 if (msglvl > 0 && iter > 0) {
842 ivout_(&debug_1.logfil, &c__1, &j, &debug_1.ndigit, "_saitr: Iterati"
843 "ve refinement for Arnoldi residual", (ftnlen)49);
844 if (msglvl > 2) {
845 xtemp[0] = *rnorm;
846 xtemp[1] = rnorm1;
847 dvout_(&debug_1.logfil, &c__2, xtemp, &debug_1.ndigit, "_saitr: "
848 "iterative refinement ; rnorm and rnorm1 are", (ftnlen)51);
849 }
850 }
851
852 /* %-----------------------------------------% */
853 /* | Determine if we need to perform another | */
854 /* | step of re-orthogonalization. | */
855 /* %-----------------------------------------% */
856
857 if (rnorm1 > *rnorm * .717f) {
858
859 /* %--------------------------------% */
860 /* | No need for further refinement | */
861 /* %--------------------------------% */
862
863 *rnorm = rnorm1;
864
865 } else {
866
867 /* %-------------------------------------------% */
868 /* | Another step of iterative refinement step | */
869 /* | is required. NITREF is used by stat.h | */
870 /* %-------------------------------------------% */
871
872 ++timing_1.nitref;
873 *rnorm = rnorm1;
874 ++iter;
875 if (iter <= 1) {
876 goto L80;
877 }
878
879 /* %-------------------------------------------------% */
880 /* | Otherwise RESID is numerically in the span of V | */
881 /* %-------------------------------------------------% */
882
883 i__1 = *n;
884 for (jj = 1; jj <= i__1; ++jj) {
885 resid[jj] = 0.;
886 /* L95: */
887 }
888 *rnorm = 0.;
889 }
890
891 /* %----------------------------------------------% */
892 /* | Branch here directly if iterative refinement | */
893 /* | wasn't necessary or after at most NITER_REF | */
894 /* | steps of iterative refinement. | */
895 /* %----------------------------------------------% */
896
897 L100:
898
899 rstart = FALSE_;
900 orth2 = FALSE_;
901
902 second_(&t5);
903 timing_1.titref += t5 - t4;
904
905 /* %----------------------------------------------------------% */
906 /* | Make sure the last off-diagonal element is non negative | */
907 /* | If not perform a similarity transformation on H(1:j,1:j) | */
908 /* | and scale v(:,j) by -1. | */
909 /* %----------------------------------------------------------% */
910
911 if (h__[j + h_dim1] < 0.) {
912 h__[j + h_dim1] = -h__[j + h_dim1];
913 if (j < *k + *np) {
914 dscal_(n, &c_b57, &v[(j + 1) * v_dim1 + 1], &c__1);
915 } else {
916 dscal_(n, &c_b57, &resid[1], &c__1);
917 }
918 }
919
920 /* %------------------------------------% */
921 /* | STEP 6: Update j = j+1; Continue | */
922 /* %------------------------------------% */
923
924 ++j;
925 if (j > *k + *np) {
926 second_(&t1);
927 timing_1.tsaitr += t1 - t0;
928 *ido = 99;
929
930 if (msglvl > 1) {
931 i__1 = *k + *np;
932 dvout_(&debug_1.logfil, &i__1, &h__[(h_dim1 << 1) + 1], &
933 debug_1.ndigit, "_saitr: main diagonal of matrix H of st"
934 "ep K+NP.", (ftnlen)47);
935 if (*k + *np > 1) {
936 i__1 = *k + *np - 1;
937 dvout_(&debug_1.logfil, &i__1, &h__[h_dim1 + 2], &
938 debug_1.ndigit, "_saitr: sub diagonal of matrix H of"
939 " step K+NP.", (ftnlen)46);
940 }
941 }
942
943 goto L9000;
944 }
945
946 /* %--------------------------------------------------------% */
947 /* | Loop back to extend the factorization by another step. | */
948 /* %--------------------------------------------------------% */
949
950 goto L1000;
951
952 /* %---------------------------------------------------------------% */
953 /* | | */
954 /* | E N D O F M A I N I T E R A T I O N L O O P | */
955 /* | | */
956 /* %---------------------------------------------------------------% */
957
958 L9000:
959 return 0;
960
961 /* %---------------% */
962 /* | End of dsaitr | */
963 /* %---------------% */
964
965 } /* dsaitr_ */
966