sorth.f 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. *DECK SORTH
  2. SUBROUTINE SORTH (VNEW, V, HES, N, LL, LDHES, KMP, SNORMW)
  3. C***BEGIN PROLOGUE SORTH
  4. C***SUBSIDIARY
  5. C***PURPOSE Internal routine for SGMRES.
  6. C***LIBRARY SLATEC (SLAP)
  7. C***CATEGORY D2A4, D2B4
  8. C***TYPE SINGLE PRECISION (SORTH-S, DORTH-D)
  9. C***KEYWORDS GENERALIZED MINIMUM RESIDUAL, ITERATIVE PRECONDITION,
  10. C NON-SYMMETRIC LINEAR SYSTEM, SLAP, SPARSE
  11. C***AUTHOR Brown, Peter, (LLNL), pnbrown@llnl.gov
  12. C Hindmarsh, Alan, (LLNL), alanh@llnl.gov
  13. C Seager, Mark K., (LLNL), seager@llnl.gov
  14. C Lawrence Livermore National Laboratory
  15. C PO Box 808, L-60
  16. C Livermore, CA 94550 (510) 423-3141
  17. C***DESCRIPTION
  18. C This routine orthogonalizes the vector VNEW against the
  19. C previous KMP vectors in the V array. It uses a modified
  20. C Gram-Schmidt orthogonalization procedure with conditional
  21. C reorthogonalization.
  22. C
  23. C *Usage:
  24. C INTEGER N, LL, LDHES, KMP
  25. C REAL VNEW(N), V(N,LL), HES(LDHES,LL), SNORMW
  26. C
  27. C CALL SORTH(VNEW, V, HES, N, LL, LDHES, KMP, SNORMW)
  28. C
  29. C *Arguments:
  30. C VNEW :INOUT Real VNEW(N)
  31. C On input, the vector of length N containing a scaled
  32. C product of the Jacobian and the vector V(*,LL).
  33. C On output, the new vector orthogonal to V(*,i0) to V(*,LL),
  34. C where i0 = max(1, LL-KMP+1).
  35. C V :IN Real V(N,LL)
  36. C The N x LL array containing the previous LL
  37. C orthogonal vectors V(*,1) to V(*,LL).
  38. C HES :INOUT Real HES(LDHES,LL)
  39. C On input, an LL x LL upper Hessenberg matrix containing,
  40. C in HES(I,K), K.lt.LL, the scaled inner products of
  41. C A*V(*,K) and V(*,i).
  42. C On return, column LL of HES is filled in with
  43. C the scaled inner products of A*V(*,LL) and V(*,i).
  44. C N :IN Integer
  45. C The order of the matrix A, and the length of VNEW.
  46. C LL :IN Integer
  47. C The current order of the matrix HES.
  48. C LDHES :IN Integer
  49. C The leading dimension of the HES array.
  50. C KMP :IN Integer
  51. C The number of previous vectors the new vector VNEW
  52. C must be made orthogonal to (KMP .le. MAXL).
  53. C SNORMW :OUT REAL
  54. C Scalar containing the l-2 norm of VNEW.
  55. C
  56. C***SEE ALSO SGMRES
  57. C***ROUTINES CALLED SAXPY, SDOT, SNRM2
  58. C***REVISION HISTORY (YYMMDD)
  59. C 871001 DATE WRITTEN
  60. C 881213 Previous REVISION DATE
  61. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  62. C 890922 Numerous changes to prologue to make closer to SLATEC
  63. C standard. (FNF)
  64. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  65. C 910411 Prologue converted to Version 4.0 format. (BAB)
  66. C 910506 Made subsidiary to SGMRES. (FNF)
  67. C 920511 Added complete declaration section. (WRB)
  68. C***END PROLOGUE SORTH
  69. C The following is for optimized compilation on LLNL/LTSS Crays.
  70. CLLL. OPTIMIZE
  71. C .. Scalar Arguments ..
  72. REAL SNORMW
  73. INTEGER KMP, LDHES, LL, N
  74. C .. Array Arguments ..
  75. REAL HES(LDHES,*), V(N,*), VNEW(*)
  76. C .. Local Scalars ..
  77. REAL ARG, SUMDSQ, TEM, VNRM
  78. INTEGER I, I0
  79. C .. External Functions ..
  80. REAL SDOT, SNRM2
  81. EXTERNAL SDOT, SNRM2
  82. C .. External Subroutines ..
  83. EXTERNAL SAXPY
  84. C .. Intrinsic Functions ..
  85. INTRINSIC MAX, SQRT
  86. C***FIRST EXECUTABLE STATEMENT SORTH
  87. C
  88. C Get norm of unaltered VNEW for later use.
  89. C
  90. VNRM = SNRM2(N, VNEW, 1)
  91. C -------------------------------------------------------------------
  92. C Perform the modified Gram-Schmidt procedure on VNEW =A*V(LL).
  93. C Scaled inner products give new column of HES.
  94. C Projections of earlier vectors are subtracted from VNEW.
  95. C -------------------------------------------------------------------
  96. I0 = MAX(1,LL-KMP+1)
  97. DO 10 I = I0,LL
  98. HES(I,LL) = SDOT(N, V(1,I), 1, VNEW, 1)
  99. TEM = -HES(I,LL)
  100. CALL SAXPY(N, TEM, V(1,I), 1, VNEW, 1)
  101. 10 CONTINUE
  102. C -------------------------------------------------------------------
  103. C Compute SNORMW = norm of VNEW. If VNEW is small compared
  104. C to its input value (in norm), then reorthogonalize VNEW to
  105. C V(*,1) through V(*,LL). Correct if relative correction
  106. C exceeds 1000*(unit roundoff). Finally, correct SNORMW using
  107. C the dot products involved.
  108. C -------------------------------------------------------------------
  109. SNORMW = SNRM2(N, VNEW, 1)
  110. IF (VNRM + 0.001E0*SNORMW .NE. VNRM) RETURN
  111. SUMDSQ = 0
  112. DO 30 I = I0,LL
  113. TEM = -SDOT(N, V(1,I), 1, VNEW, 1)
  114. IF (HES(I,LL) + 0.001E0*TEM .EQ. HES(I,LL)) GO TO 30
  115. HES(I,LL) = HES(I,LL) - TEM
  116. CALL SAXPY(N, TEM, V(1,I), 1, VNEW, 1)
  117. SUMDSQ = SUMDSQ + TEM**2
  118. 30 CONTINUE
  119. IF (SUMDSQ .EQ. 0.0E0) RETURN
  120. ARG = MAX(0.0E0,SNORMW**2 - SUMDSQ)
  121. SNORMW = SQRT(ARG)
  122. C
  123. RETURN
  124. C------------- LAST LINE OF SORTH FOLLOWS ----------------------------
  125. END