Debian Codegraph @

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

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