Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/v3p/netlib/arpack/dsaitr.f

raw
1 c-----------------------------------------------------------------------
2 c\BeginDoc
3 c
4 c\Name: dsaitr
5 c
6 c\Description:
7 c Reverse communication interface for applying NP additional steps to
8 c a K step symmetric Arnoldi factorization.
9 c
10 c Input: OP*V_{k} - V_{k}*H = r_{k}*e_{k}^T
11 c
12 c with (V_{k}^T)*B*V_{k} = I, (V_{k}^T)*B*r_{k} = 0.
13 c
14 c Output: OP*V_{k+p} - V_{k+p}*H = r_{k+p}*e_{k+p}^T
15 c
16 c with (V_{k+p}^T)*B*V_{k+p} = I, (V_{k+p}^T)*B*r_{k+p} = 0.
17 c
18 c where OP and B are as in dsaupd. The B-norm of r_{k+p} is also
19 c computed and returned.
20 c
21 c\Usage:
22 c call dsaitr
23 c ( IDO, BMAT, N, K, NP, MODE, RESID, RNORM, V, LDV, H, LDH,
24 c IPNTR, WORKD, INFO )
25 c
26 c\Arguments
27 c IDO Integer. (INPUT/OUTPUT)
28 c Reverse communication flag.
29 c -------------------------------------------------------------
30 c IDO = 0: first call to the reverse communication interface
31 c IDO = -1: compute Y = OP * X where
32 c IPNTR(1) is the pointer into WORK for X,
33 c IPNTR(2) is the pointer into WORK for Y.
34 c This is for the restart phase to force the new
35 c starting vector into the range of OP.
36 c IDO = 1: compute Y = OP * X where
37 c IPNTR(1) is the pointer into WORK for X,
38 c IPNTR(2) is the pointer into WORK for Y,
39 c IPNTR(3) is the pointer into WORK for B * X.
40 c IDO = 2: compute Y = B * X where
41 c IPNTR(1) is the pointer into WORK for X,
42 c IPNTR(2) is the pointer into WORK for Y.
43 c IDO = 99: done
44 c -------------------------------------------------------------
45 c When the routine is used in the "shift-and-invert" mode, the
46 c vector B * Q is already available and does not need to be
47 c recomputed in forming OP * Q.
48 c
49 c BMAT Character*1. (INPUT)
50 c BMAT specifies the type of matrix B that defines the
51 c semi-inner product for the operator OP. See dsaupd.
52 c B = 'I' -> standard eigenvalue problem A*x = lambda*x
53 c B = 'G' -> generalized eigenvalue problem A*x = lambda*M*x
54 c
55 c N Integer. (INPUT)
56 c Dimension of the eigenproblem.
57 c
58 c K Integer. (INPUT)
59 c Current order of H and the number of columns of V.
60 c
61 c NP Integer. (INPUT)
62 c Number of additional Arnoldi steps to take.
63 c
64 c MODE Integer. (INPUT)
65 c Signifies which form for "OP". If MODE=2 then
66 c a reduction in the number of B matrix vector multiplies
67 c is possible since the B-norm of OP*x is equivalent to
68 c the inv(B)-norm of A*x.
69 c
70 c RESID Double precision array of length N. (INPUT/OUTPUT)
71 c On INPUT: RESID contains the residual vector r_{k}.
72 c On OUTPUT: RESID contains the residual vector r_{k+p}.
73 c
74 c RNORM Double precision scalar. (INPUT/OUTPUT)
75 c On INPUT the B-norm of r_{k}.
76 c On OUTPUT the B-norm of the updated residual r_{k+p}.
77 c
78 c V Double precision N by K+NP array. (INPUT/OUTPUT)
79 c On INPUT: V contains the Arnoldi vectors in the first K
80 c columns.
81 c On OUTPUT: V contains the new NP Arnoldi vectors in the next
82 c NP columns. The first K columns are unchanged.
83 c
84 c LDV Integer. (INPUT)
85 c Leading dimension of V exactly as declared in the calling
86 c program.
87 c
88 c H Double precision (K+NP) by 2 array. (INPUT/OUTPUT)
89 c H is used to store the generated symmetric tridiagonal matrix
90 c with the subdiagonal in the first column starting at H(2,1)
91 c and the main diagonal in the second column.
92 c
93 c LDH Integer. (INPUT)
94 c Leading dimension of H exactly as declared in the calling
95 c program.
96 c
97 c IPNTR Integer array of length 3. (OUTPUT)
98 c Pointer to mark the starting locations in the WORK for
99 c vectors used by the Arnoldi iteration.
100 c -------------------------------------------------------------
101 c IPNTR(1): pointer to the current operand vector X.
102 c IPNTR(2): pointer to the current result vector Y.
103 c IPNTR(3): pointer to the vector B * X when used in the
104 c shift-and-invert mode. X is the current operand.
105 c -------------------------------------------------------------
106 c
107 c WORKD Double precision work array of length 3*N. (REVERSE COMMUNICATION)
108 c Distributed array to be used in the basic Arnoldi iteration
109 c for reverse communication. The calling program should not
110 c use WORKD as temporary workspace during the iteration !!!!!!
111 c On INPUT, WORKD(1:N) = B*RESID where RESID is associated
112 c with the K step Arnoldi factorization. Used to save some
113 c computation at the first step.
114 c On OUTPUT, WORKD(1:N) = B*RESID where RESID is associated
115 c with the K+NP step Arnoldi factorization.
116 c
117 c INFO Integer. (OUTPUT)
118 c = 0: Normal exit.
119 c > 0: Size of an invariant subspace of OP is found that is
120 c less than K + NP.
121 c
122 c\EndDoc
123 c
124 c-----------------------------------------------------------------------
125 c
126 c\BeginLib
127 c
128 c\Local variables:
129 c xxxxxx real
130 c
131 c\Routines called:
132 c dgetv0 ARPACK routine to generate the initial vector.
133 c ivout ARPACK utility routine that prints integers.
134 c dmout ARPACK utility routine that prints matrices.
135 c dlamch LAPACK routine that determines machine constants.
136 c dlascl LAPACK routine for careful scaling of a matrix.
137 c dgemv Level 2 BLAS routine for matrix vector multiplication.
138 c daxpy Level 1 BLAS that computes a vector triad.
139 c dscal Level 1 BLAS that scales a vector.
140 c dcopy Level 1 BLAS that copies one vector to another .
141 c ddot Level 1 BLAS that computes the scalar product of two vectors.
142 c dnrm2 Level 1 BLAS that computes the norm of a vector.
143 c
144 c\Author
145 c Danny Sorensen Phuong Vu
146 c Richard Lehoucq CRPC / Rice University
147 c Dept. of Computational & Houston, Texas
148 c Applied Mathematics
149 c Rice University
150 c Houston, Texas
151 c
152 c\Revision history:
153 c xx/xx/93: Version ' 2.4'
154 c
155 c\SCCS Information: @(#)
156 c FILE: saitr.F SID: 2.6 DATE OF SID: 8/28/96 RELEASE: 2
157 c
158 c\Remarks
159 c The algorithm implemented is:
160 c
161 c restart = .false.
162 c Given V_{k} = [v_{1}, ..., v_{k}], r_{k};
163 c r_{k} contains the initial residual vector even for k = 0;
164 c Also assume that rnorm = || B*r_{k} || and B*r_{k} are already
165 c computed by the calling program.
166 c
167 c betaj = rnorm ; p_{k+1} = B*r_{k} ;
168 c For j = k+1, ..., k+np Do
169 c 1) if ( betaj < tol ) stop or restart depending on j.
170 c if ( restart ) generate a new starting vector.
171 c 2) v_{j} = r(j-1)/betaj; V_{j} = [V_{j-1}, v_{j}];
172 c p_{j} = p_{j}/betaj
173 c 3) r_{j} = OP*v_{j} where OP is defined as in dsaupd
174 c For shift-invert mode p_{j} = B*v_{j} is already available.
175 c wnorm = || OP*v_{j} ||
176 c 4) Compute the j-th step residual vector.
177 c w_{j} = V_{j}^T * B * OP * v_{j}
178 c r_{j} = OP*v_{j} - V_{j} * w_{j}
179 c alphaj <- j-th component of w_{j}
180 c rnorm = || r_{j} ||
181 c betaj+1 = rnorm
182 c If (rnorm > 0.717*wnorm) accept step and go back to 1)
183 c 5) Re-orthogonalization step:
184 c s = V_{j}'*B*r_{j}
185 c r_{j} = r_{j} - V_{j}*s; rnorm1 = || r_{j} ||
186 c alphaj = alphaj + s_{j};
187 c 6) Iterative refinement step:
188 c If (rnorm1 > 0.717*rnorm) then
189 c rnorm = rnorm1
190 c accept step and go back to 1)
191 c Else
192 c rnorm = rnorm1
193 c If this is the first time in step 6), go to 5)
194 c Else r_{j} lies in the span of V_{j} numerically.
195 c Set r_{j} = 0 and rnorm = 0; go to 1)
196 c EndIf
197 c End Do
198 c
199 c\EndLib
200 c
201 c-----------------------------------------------------------------------
202 c
203 subroutine dsaitr
204 & (ido, bmat, n, k, np, mode, resid, rnorm, v, ldv, h, ldh,
205 & ipntr, workd, info)
206 c
207 c %----------------------------------------------------%
208 c | Include files for debugging and timing information |
209 c %----------------------------------------------------%
210 c
211 include 'debug.h'
212 include 'stat.h'
213 c
214 c %------------------%
215 c | Scalar Arguments |
216 c %------------------%
217 c
218 character bmat*1
219 integer ido, info, k, ldh, ldv, n, mode, np
220 Double precision
221 & rnorm
222 c
223 c %-----------------%
224 c | Array Arguments |
225 c %-----------------%
226 c
227 integer ipntr(3)
228 Double precision
229 & h(ldh,2), resid(n), v(ldv,k+np), workd(3*n)
230 c
231 c %------------%
232 c | Parameters |
233 c %------------%
234 c
235 Double precision
236 & one, zero
237 parameter (one = 1.0D+0, zero = 0.0D+0)
238 c
239 c %---------------%
240 c | Local Scalars |
241 c %---------------%
242 c
243 logical first, orth1, orth2, rstart, step3, step4
244 integer i, ierr, ipj, irj, ivj, iter, itry, j, msglvl,
245 & infol, jj
246 Double precision
247 & rnorm1, wnorm, safmin, temp1
248 save orth1, orth2, rstart, step3, step4,
249 & ierr, ipj, irj, ivj, iter, itry, j, msglvl,
250 & rnorm1, safmin, wnorm
251 c
252 c %-----------------------%
253 c | Local Array Arguments |
254 c %-----------------------%
255 c
256 Double precision
257 & xtemp(2)
258 c
259 c %----------------------%
260 c | External Subroutines |
261 c %----------------------%
262 c
263 external daxpy, dcopy, dscal, dgemv, dgetv0, dmout,
264 & dlascl, second
265 c
266 c %--------------------%
267 c | External Functions |
268 c %--------------------%
269 c
270 Double precision
271 & ddot, dnrm2, dlamch
272 external ddot, dnrm2, dlamch
273 c
274 c %-----------------%
275 c | Data statements |
276 c %-----------------%
277 c
278 data first / .true. /
279 c
280 c %-----------------------%
281 c | Executable Statements |
282 c %-----------------------%
283 c
284 if (first) then
285 first = .false.
286 c
287 c %--------------------------------%
288 c | safmin = safe minimum is such |
289 c | that 1/sfmin does not overflow |
290 c %--------------------------------%
291 c
292 safmin = dlamch('safmin')
293 end if
294 c
295 if (ido .eq. 0) then
296 c
297 c %-------------------------------%
298 c | Initialize timing statistics |
299 c | & message level for debugging |
300 c %-------------------------------%
301 c
302 call second (t0)
303 msglvl = msaitr
304 c
305 c %------------------------------%
306 c | Initial call to this routine |
307 c %------------------------------%
308 c
309 info = 0
310 step3 = .false.
311 step4 = .false.
312 rstart = .false.
313 orth1 = .false.
314 orth2 = .false.
315 c
316 c %--------------------------------%
317 c | Pointer to the current step of |
318 c | the factorization to build |
319 c %--------------------------------%
320 c
321 j = k + 1
322 c
323 c %------------------------------------------%
324 c | Pointers used for reverse communication |
325 c | when using WORKD. |
326 c %------------------------------------------%
327 c
328 ipj = 1
329 irj = ipj + n
330 ivj = irj + n
331 end if
332 c
333 c %-------------------------------------------------%
334 c | When in reverse communication mode one of: |
335 c | STEP3, STEP4, ORTH1, ORTH2, RSTART |
336 c | will be .true. |
337 c | STEP3: return from computing OP*v_{j}. |
338 c | STEP4: return from computing B-norm of OP*v_{j} |
339 c | ORTH1: return from computing B-norm of r_{j+1} |
340 c | ORTH2: return from computing B-norm of |
341 c | correction to the residual vector. |
342 c | RSTART: return from OP computations needed by |
343 c | dgetv0. |
344 c %-------------------------------------------------%
345 c
346 if (step3) go to 50
347 if (step4) go to 60
348 if (orth1) go to 70
349 if (orth2) go to 90
350 if (rstart) go to 30
351 c
352 c %------------------------------%
353 c | Else this is the first step. |
354 c %------------------------------%
355 c
356 c %--------------------------------------------------------------%
357 c | |
358 c | A R N O L D I I T E R A T I O N L O O P |
359 c | |
360 c | Note: B*r_{j-1} is already in WORKD(1:N)=WORKD(IPJ:IPJ+N-1) |
361 c %--------------------------------------------------------------%
362 c
363 1000 continue
364 c
365 c if (msglvl .gt. 2) then
366 c call ivout (logfil, 1, j, ndigit,
367 c & '_saitr: generating Arnoldi vector no.')
368 c call dvout (logfil, 1, rnorm, ndigit,
369 c & '_saitr: B-norm of the current residual =')
370 c end if
371 c
372 c %---------------------------------------------------------%
373 c | Check for exact zero. Equivalent to determining whether |
374 c | a j-step Arnoldi factorization is present. |
375 c %---------------------------------------------------------%
376 c
377 if (rnorm .gt. zero) go to 40
378 c
379 c %---------------------------------------------------%
380 c | Invariant subspace found, generate a new starting |
381 c | vector which is orthogonal to the current Arnoldi |
382 c | basis and continue the iteration. |
383 c %---------------------------------------------------%
384 c
385 c if (msglvl .gt. 0) then
386 c call ivout (logfil, 1, j, ndigit,
387 c & '_saitr: ****** restart at step ******')
388 c end if
389 c
390 c %---------------------------------------------%
391 c | ITRY is the loop variable that controls the |
392 c | maximum amount of times that a restart is |
393 c | attempted. NRSTRT is used by stat.h |
394 c %---------------------------------------------%
395 c
396 nrstrt = nrstrt + 1
397 itry = 1
398 20 continue
399 rstart = .true.
400 ido = 0
401 30 continue
402 c
403 c %--------------------------------------%
404 c | If in reverse communication mode and |
405 c | RSTART = .true. flow returns here. |
406 c %--------------------------------------%
407 c
408 call dgetv0 (ido, bmat, itry, .false., n, j, v, ldv,
409 & resid, rnorm, ipntr, workd, ierr)
410 if (ido .ne. 99) go to 9000
411 if (ierr .lt. 0) then
412 itry = itry + 1
413 if (itry .le. 3) go to 20
414 c
415 c %------------------------------------------------%
416 c | Give up after several restart attempts. |
417 c | Set INFO to the size of the invariant subspace |
418 c | which spans OP and exit. |
419 c %------------------------------------------------%
420 c
421 info = j - 1
422 call second (t1)
423 tsaitr = tsaitr + (t1 - t0)
424 ido = 99
425 go to 9000
426 end if
427 c
428 40 continue
429 c
430 c %---------------------------------------------------------%
431 c | STEP 2: v_{j} = r_{j-1}/rnorm and p_{j} = p_{j}/rnorm |
432 c | Note that p_{j} = B*r_{j-1}. In order to avoid overflow |
433 c | when reciprocating a small RNORM, test against lower |
434 c | machine bound. |
435 c %---------------------------------------------------------%
436 c
437 call dcopy (n, resid, 1, v(1,j), 1)
438 if (rnorm .ge. safmin) then
439 temp1 = one / rnorm
440 call dscal (n, temp1, v(1,j), 1)
441 call dscal (n, temp1, workd(ipj), 1)
442 else
443 c
444 c %-----------------------------------------%
445 c | To scale both v_{j} and p_{j} carefully |
446 c | use LAPACK routine SLASCL |
447 c %-----------------------------------------%
448 c
449 call dlascl ('General', i, i, rnorm, one, n, 1,
450 & v(1,j), n, infol)
451 call dlascl ('General', i, i, rnorm, one, n, 1,
452 & workd(ipj), n, infol)
453 end if
454 c
455 c %------------------------------------------------------%
456 c | STEP 3: r_{j} = OP*v_{j}; Note that p_{j} = B*v_{j} |
457 c | Note that this is not quite yet r_{j}. See STEP 4 |
458 c %------------------------------------------------------%
459 c
460 step3 = .true.
461 nopx = nopx + 1
462 call second (t2)
463 call dcopy (n, v(1,j), 1, workd(ivj), 1)
464 ipntr(1) = ivj
465 ipntr(2) = irj
466 ipntr(3) = ipj
467 ido = 1
468 c
469 c %-----------------------------------%
470 c | Exit in order to compute OP*v_{j} |
471 c %-----------------------------------%
472 c
473 go to 9000
474 50 continue
475 c
476 c %-----------------------------------%
477 c | Back from reverse communication; |
478 c | WORKD(IRJ:IRJ+N-1) := OP*v_{j}. |
479 c %-----------------------------------%
480 c
481 call second (t3)
482 tmvopx = tmvopx + (t3 - t2)
483 c
484 step3 = .false.
485 c
486 c %------------------------------------------%
487 c | Put another copy of OP*v_{j} into RESID. |
488 c %------------------------------------------%
489 c
490 call dcopy (n, workd(irj), 1, resid, 1)
491 c
492 c %-------------------------------------------%
493 c | STEP 4: Finish extending the symmetric |
494 c | Arnoldi to length j. If MODE = 2 |
495 c | then B*OP = B*inv(B)*A = A and |
496 c | we don't need to compute B*OP. |
497 c | NOTE: If MODE = 2 WORKD(IVJ:IVJ+N-1) is |
498 c | assumed to have A*v_{j}. |
499 c %-------------------------------------------%
500 c
501 if (mode .eq. 2) go to 65
502 call second (t2)
503 if (bmat .eq. 'G') then
504 nbx = nbx + 1
505 step4 = .true.
506 ipntr(1) = irj
507 ipntr(2) = ipj
508 ido = 2
509 c
510 c %-------------------------------------%
511 c | Exit in order to compute B*OP*v_{j} |
512 c %-------------------------------------%
513 c
514 go to 9000
515 else if (bmat .eq. 'I') then
516 call dcopy(n, resid, 1 , workd(ipj), 1)
517 end if
518 60 continue
519 c
520 c %-----------------------------------%
521 c | Back from reverse communication; |
522 c | WORKD(IPJ:IPJ+N-1) := B*OP*v_{j}. |
523 c %-----------------------------------%
524 c
525 if (bmat .eq. 'G') then
526 call second (t3)
527 tmvbx = tmvbx + (t3 - t2)
528 end if
529 c
530 step4 = .false.
531 c
532 c %-------------------------------------%
533 c | The following is needed for STEP 5. |
534 c | Compute the B-norm of OP*v_{j}. |
535 c %-------------------------------------%
536 c
537 65 continue
538 if (mode .eq. 2) then
539 c
540 c %----------------------------------%
541 c | Note that the B-norm of OP*v_{j} |
542 c | is the inv(B)-norm of A*v_{j}. |
543 c %----------------------------------%
544 c
545 wnorm = ddot (n, resid, 1, workd(ivj), 1)
546 wnorm = sqrt(abs(wnorm))
547 else if (bmat .eq. 'G') then
548 wnorm = ddot (n, resid, 1, workd(ipj), 1)
549 wnorm = sqrt(abs(wnorm))
550 else if (bmat .eq. 'I') then
551 wnorm = dnrm2(n, resid, 1)
552 end if
553 c
554 c %-----------------------------------------%
555 c | Compute the j-th residual corresponding |
556 c | to the j step factorization. |
557 c | Use Classical Gram Schmidt and compute: |
558 c | w_{j} <- V_{j}^T * B * OP * v_{j} |
559 c | r_{j} <- OP*v_{j} - V_{j} * w_{j} |
560 c %-----------------------------------------%
561 c
562 c
563 c %------------------------------------------%
564 c | Compute the j Fourier coefficients w_{j} |
565 c | WORKD(IPJ:IPJ+N-1) contains B*OP*v_{j}. |
566 c %------------------------------------------%
567 c
568 if (mode .ne. 2 ) then
569 call dgemv('T', n, j, one, v, ldv, workd(ipj), 1, zero,
570 & workd(irj), 1)
571 else if (mode .eq. 2) then
572 call dgemv('T', n, j, one, v, ldv, workd(ivj), 1, zero,
573 & workd(irj), 1)
574 end if
575 c
576 c %--------------------------------------%
577 c | Orthgonalize r_{j} against V_{j}. |
578 c | RESID contains OP*v_{j}. See STEP 3. |
579 c %--------------------------------------%
580 c
581 call dgemv('N', n, j, -one, v, ldv, workd(irj), 1, one,
582 & resid, 1)
583 c
584 c %--------------------------------------%
585 c | Extend H to have j rows and columns. |
586 c %--------------------------------------%
587 c
588 h(j,2) = workd(irj + j - 1)
589 if (j .eq. 1 .or. rstart) then
590 h(j,1) = zero
591 else
592 h(j,1) = rnorm
593 end if
594 call second (t4)
595 c
596 orth1 = .true.
597 iter = 0
598 c
599 call second (t2)
600 if (bmat .eq. 'G') then
601 nbx = nbx + 1
602 call dcopy (n, resid, 1, workd(irj), 1)
603 ipntr(1) = irj
604 ipntr(2) = ipj
605 ido = 2
606 c
607 c %----------------------------------%
608 c | Exit in order to compute B*r_{j} |
609 c %----------------------------------%
610 c
611 go to 9000
612 else if (bmat .eq. 'I') then
613 call dcopy (n, resid, 1, workd(ipj), 1)
614 end if
615 70 continue
616 c
617 c %---------------------------------------------------%
618 c | Back from reverse communication if ORTH1 = .true. |
619 c | WORKD(IPJ:IPJ+N-1) := B*r_{j}. |
620 c %---------------------------------------------------%
621 c
622 if (bmat .eq. 'G') then
623 call second (t3)
624 tmvbx = tmvbx + (t3 - t2)
625 end if
626 c
627 orth1 = .false.
628 c
629 c %------------------------------%
630 c | Compute the B-norm of r_{j}. |
631 c %------------------------------%
632 c
633 if (bmat .eq. 'G') then
634 rnorm = ddot (n, resid, 1, workd(ipj), 1)
635 rnorm = sqrt(abs(rnorm))
636 else if (bmat .eq. 'I') then
637 rnorm = dnrm2(n, resid, 1)
638 end if
639 c
640 c %-----------------------------------------------------------%
641 c | STEP 5: Re-orthogonalization / Iterative refinement phase |
642 c | Maximum NITER_ITREF tries. |
643 c | |
644 c | s = V_{j}^T * B * r_{j} |
645 c | r_{j} = r_{j} - V_{j}*s |
646 c | alphaj = alphaj + s_{j} |
647 c | |
648 c | The stopping criteria used for iterative refinement is |
649 c | discussed in Parlett's book SEP, page 107 and in Gragg & |
650 c | Reichel ACM TOMS paper; Algorithm 686, Dec. 1990. |
651 c | Determine if we need to correct the residual. The goal is |
652 c | to enforce ||v(:,1:j)^T * r_{j}|| .le. eps * || r_{j} || |
653 c %-----------------------------------------------------------%
654 c
655 if (rnorm .gt. 0.717*wnorm) go to 100
656 nrorth = nrorth + 1
657 c
658 c %---------------------------------------------------%
659 c | Enter the Iterative refinement phase. If further |
660 c | refinement is necessary, loop back here. The loop |
661 c | variable is ITER. Perform a step of Classical |
662 c | Gram-Schmidt using all the Arnoldi vectors V_{j} |
663 c %---------------------------------------------------%
664 c
665 80 continue
666 c
667 if (msglvl .gt. 2) then
668 xtemp(1) = wnorm
669 xtemp(2) = rnorm
670 c call dvout (logfil, 2, xtemp, ndigit,
671 c & '_saitr: re-orthonalization ; wnorm and rnorm are')
672 end if
673 c
674 c %----------------------------------------------------%
675 c | Compute V_{j}^T * B * r_{j}. |
676 c | WORKD(IRJ:IRJ+J-1) = v(:,1:J)'*WORKD(IPJ:IPJ+N-1). |
677 c %----------------------------------------------------%
678 c
679 call dgemv ('T', n, j, one, v, ldv, workd(ipj), 1,
680 & zero, workd(irj), 1)
681 c
682 c %----------------------------------------------%
683 c | Compute the correction to the residual: |
684 c | r_{j} = r_{j} - V_{j} * WORKD(IRJ:IRJ+J-1). |
685 c | The correction to H is v(:,1:J)*H(1:J,1:J) + |
686 c | v(:,1:J)*WORKD(IRJ:IRJ+J-1)*e'_j, but only |
687 c | H(j,j) is updated. |
688 c %----------------------------------------------%
689 c
690 call dgemv ('N', n, j, -one, v, ldv, workd(irj), 1,
691 & one, resid, 1)
692 c
693 if (j .eq. 1 .or. rstart) h(j,1) = zero
694 h(j,2) = h(j,2) + workd(irj + j - 1)
695 c
696 orth2 = .true.
697 call second (t2)
698 if (bmat .eq. 'G') then
699 nbx = nbx + 1
700 call dcopy (n, resid, 1, workd(irj), 1)
701 ipntr(1) = irj
702 ipntr(2) = ipj
703 ido = 2
704 c
705 c %-----------------------------------%
706 c | Exit in order to compute B*r_{j}. |
707 c | r_{j} is the corrected residual. |
708 c %-----------------------------------%
709 c
710 go to 9000
711 else if (bmat .eq. 'I') then
712 call dcopy (n, resid, 1, workd(ipj), 1)
713 end if
714 90 continue
715 c
716 c %---------------------------------------------------%
717 c | Back from reverse communication if ORTH2 = .true. |
718 c %---------------------------------------------------%
719 c
720 if (bmat .eq. 'G') then
721 call second (t3)
722 tmvbx = tmvbx + (t3 - t2)
723 end if
724 c
725 c %-----------------------------------------------------%
726 c | Compute the B-norm of the corrected residual r_{j}. |
727 c %-----------------------------------------------------%
728 c
729 if (bmat .eq. 'G') then
730 rnorm1 = ddot (n, resid, 1, workd(ipj), 1)
731 rnorm1 = sqrt(abs(rnorm1))
732 else if (bmat .eq. 'I') then
733 rnorm1 = dnrm2(n, resid, 1)
734 end if
735 c
736 c if (msglvl .gt. 0 .and. iter .gt. 0) then
737 c call ivout (logfil, 1, j, ndigit,
738 c & '_saitr: Iterative refinement for Arnoldi residual')
739 c if (msglvl .gt. 2) then
740 c xtemp(1) = rnorm
741 c xtemp(2) = rnorm1
742 c call dvout (logfil, 2, xtemp, ndigit,
743 c & '_saitr: iterative refinement ; rnorm and rnorm1 are')
744 c end if
745 c end if
746 c
747 c %-----------------------------------------%
748 c | Determine if we need to perform another |
749 c | step of re-orthogonalization. |
750 c %-----------------------------------------%
751 c
752 if (rnorm1 .gt. 0.717*rnorm) then
753 c
754 c %--------------------------------%
755 c | No need for further refinement |
756 c %--------------------------------%
757 c
758 rnorm = rnorm1
759 c
760 else
761 c
762 c %-------------------------------------------%
763 c | Another step of iterative refinement step |
764 c | is required. NITREF is used by stat.h |
765 c %-------------------------------------------%
766 c
767 nitref = nitref + 1
768 rnorm = rnorm1
769 iter = iter + 1
770 if (iter .le. 1) go to 80
771 c
772 c %-------------------------------------------------%
773 c | Otherwise RESID is numerically in the span of V |
774 c %-------------------------------------------------%
775 c
776 do 95 jj = 1, n
777 resid(jj) = zero
778 95 continue
779 rnorm = zero
780 end if
781 c
782 c %----------------------------------------------%
783 c | Branch here directly if iterative refinement |
784 c | wasn't necessary or after at most NITER_REF |
785 c | steps of iterative refinement. |
786 c %----------------------------------------------%
787 c
788 100 continue
789 c
790 rstart = .false.
791 orth2 = .false.
792 c
793 call second (t5)
794 titref = titref + (t5 - t4)
795 c
796 c %----------------------------------------------------------%
797 c | Make sure the last off-diagonal element is non negative |
798 c | If not perform a similarity transformation on H(1:j,1:j) |
799 c | and scale v(:,j) by -1. |
800 c %----------------------------------------------------------%
801 c
802 if (h(j,1) .lt. zero) then
803 h(j,1) = -h(j,1)
804 if ( j .lt. k+np) then
805 call dscal(n, -one, v(1,j+1), 1)
806 else
807 call dscal(n, -one, resid, 1)
808 end if
809 end if
810 c
811 c %------------------------------------%
812 c | STEP 6: Update j = j+1; Continue |
813 c %------------------------------------%
814 c
815 j = j + 1
816 if (j .gt. k+np) then
817 call second (t1)
818 tsaitr = tsaitr + (t1 - t0)
819 ido = 99
820 c
821 c if (msglvl .gt. 1) then
822 c call dvout (logfil, k+np, h(1,2), ndigit,
823 c & '_saitr: main diagonal of matrix H of step K+NP.')
824 c if (k+np .gt. 1) then
825 c call dvout (logfil, k+np-1, h(2,1), ndigit,
826 c & '_saitr: sub diagonal of matrix H of step K+NP.')
827 c end if
828 c end if
829 c
830 go to 9000
831 end if
832 c
833 c %--------------------------------------------------------%
834 c | Loop back to extend the factorization by another step. |
835 c %--------------------------------------------------------%
836 c
837 go to 1000
838 c
839 c %---------------------------------------------------------------%
840 c | |
841 c | E N D O F M A I N I T E R A T I O N L O O P |
842 c | |
843 c %---------------------------------------------------------------%
844 c
845 9000 continue
846 return
847 c
848 c %---------------%
849 c | End of dsaitr |
850 c %---------------%
851 c
852 end