Debian Codegraph @

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

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