Debian Codegraph @

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

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