issomn.f 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. *DECK ISSOMN
  2. INTEGER FUNCTION ISSOMN (N, B, X, NELT, IA, JA, A, ISYM, MSOLVE,
  3. + NSAVE, ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, R, Z, P, AP,
  4. + EMAP, DZ, CSAV, RWORK, IWORK, AK, BNRM, SOLNRM)
  5. C***BEGIN PROLOGUE ISSOMN
  6. C***SUBSIDIARY
  7. C***PURPOSE Preconditioned Orthomin Stop Test.
  8. C This routine calculates the stop test for the Orthomin
  9. C iteration scheme. It returns a non-zero if the error
  10. C estimate (the type of which is determined by ITOL) is
  11. C less than the user specified tolerance TOL.
  12. C***LIBRARY SLATEC (SLAP)
  13. C***CATEGORY D2A4, D2B4
  14. C***TYPE SINGLE PRECISION (ISSOMN-S, ISDOMN-D)
  15. C***KEYWORDS ITERATIVE PRECONDITION, NON-SYMMETRIC LINEAR SYSTEM,
  16. C ORTHOMIN, SLAP, SPARSE, STOP TEST
  17. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  18. C Seager, Mark K., (LLNL)
  19. C Lawrence Livermore National Laboratory
  20. C PO BOX 808, L-60
  21. C Livermore, CA 94550 (510) 423-3141
  22. C seager@llnl.gov
  23. C***DESCRIPTION
  24. C
  25. C *Usage:
  26. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, NSAVE, ITOL, ITMAX
  27. C INTEGER ITER, IERR, IUNIT, IWORK(USER DEFINED)
  28. C REAL B(N), X(N), A(NELT), TOL, ERR, R(N), Z(N)
  29. C REAL P(N,0:NSAVE), AP(N,0:NSAVE), EMAP(N,0:NSAVE)
  30. C REAL DZ(N), CSAV(NSAVE), RWORK(USER DEFINED), AK
  31. C REAL BNRM, SOLNRM
  32. C EXTERNAL MSOLVE
  33. C
  34. C IF( ISSOMN(N, B, X, NELT, IA, JA, A, ISYM, MSOLVE, NSAVE,
  35. C $ ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, R, Z, P, AP,
  36. C $ EMAP, DZ, CSAV, RWORK, IWORK, AK, BNRM, SOLNRM)
  37. C $ .NE.0 ) THEN ITERATION CONVERGED
  38. C
  39. C *Arguments:
  40. C N :IN Integer.
  41. C Order of the matrix.
  42. C B :IN Real B(N).
  43. C Right-hand side vector.
  44. C X :IN Real X(N).
  45. C On input X is your initial guess for solution vector.
  46. C On output X is the final approximate solution.
  47. C NELT :IN Integer.
  48. C Number of Non-Zeros stored in A.
  49. C IA :IN Integer IA(NELT).
  50. C JA :IN Integer JA(NELT).
  51. C A :IN Real A(NELT).
  52. C These arrays should hold the matrix A in either the SLAP
  53. C Triad format or the SLAP Column format. See "Description"
  54. C in the SSDOMN or SSLUOM prologue.
  55. C ISYM :IN Integer.
  56. C Flag to indicate symmetric storage format.
  57. C If ISYM=0, all non-zero entries of the matrix are stored.
  58. C If ISYM=1, the matrix is symmetric, and only the upper
  59. C or lower triangle of the matrix is stored.
  60. C MSOLVE :EXT External.
  61. C Name of a routine which solves a linear system MZ = R for
  62. C Z given R with the preconditioning matrix M (M is supplied via
  63. C RWORK and IWORK arrays). The name of the MSOLVE routine must
  64. C be declared external in the calling program. The calling
  65. C sequence to MSOLVE is:
  66. C CALL MSOLVE(N, R, Z, NELT, IA, JA, A, ISYM, RWORK, IWORK)
  67. C Where N is the number of unknowns, R is the right-hand side
  68. C vector and Z is the solution upon return. NELT, IA, JA, A and
  69. C ISYM are defined as above. RWORK is a real array that can
  70. C be used to pass necessary preconditioning information and/or
  71. C workspace to MSOLVE. IWORK is an integer work array for
  72. C the same purpose as RWORK.
  73. C NSAVE :IN Integer.
  74. C Number of direction vectors to save and orthogonalize against.
  75. C ITOL :IN Integer.
  76. C Flag to indicate type of convergence criterion.
  77. C If ITOL=1, iteration stops when the 2-norm of the residual
  78. C divided by the 2-norm of the right-hand side is less than TOL.
  79. C If ITOL=2, iteration stops when the 2-norm of M-inv times the
  80. C residual divided by the 2-norm of M-inv times the right hand
  81. C side is less than TOL, where M-inv is the inverse of the
  82. C diagonal of A.
  83. C ITOL=11 is often useful for checking and comparing different
  84. C routines. For this case, the user must supply the "exact"
  85. C solution or a very accurate approximation (one with an error
  86. C much less than TOL) through a common block,
  87. C COMMON /SSLBLK/ SOLN( )
  88. C If ITOL=11, iteration stops when the 2-norm of the difference
  89. C between the iterative approximation and the user-supplied
  90. C solution divided by the 2-norm of the user-supplied solution
  91. C is less than TOL. Note that this requires the user to set up
  92. C the "COMMON /SSLBLK/ SOLN(LENGTH)" in the calling routine.
  93. C The routine with this declaration should be loaded before the
  94. C stop test so that the correct length is used by the loader.
  95. C This procedure is not standard Fortran and may not work
  96. C correctly on your system (although it has worked on every
  97. C system the authors have tried). If ITOL is not 11 then this
  98. C common block is indeed standard Fortran.
  99. C TOL :IN Real.
  100. C Convergence criterion, as described above.
  101. C ITMAX :IN Integer.
  102. C Maximum number of iterations.
  103. C ITER :IN Integer.
  104. C Current iteration count. (Must be zero on first call.)
  105. C ERR :OUT Real.
  106. C Error estimate of error in final approximate solution, as
  107. C defined by ITOL.
  108. C IERR :OUT Integer.
  109. C Error flag. IERR is set to 3 if ITOL is not one of the
  110. C acceptable values, see above.
  111. C IUNIT :IN Integer.
  112. C Unit number on which to write the error at each iteration,
  113. C if this is desired for monitoring convergence. If unit
  114. C number is 0, no writing will occur.
  115. C R :IN Real R(N).
  116. C The residual R = B-AX.
  117. C Z :WORK Real Z(N).
  118. C P :IN Real P(N,0:NSAVE).
  119. C Workspace used to hold the conjugate direction vector(s).
  120. C AP :IN Real AP(N,0:NSAVE).
  121. C Workspace used to hold the matrix A times the P vector(s).
  122. C EMAP :IN Real EMAP(N,0:NSAVE).
  123. C Workspace used to hold M-inv times the AP vector(s).
  124. C DZ :WORK Real DZ(N).
  125. C Workspace.
  126. C CSAV :DUMMY Real CSAV(NSAVE)
  127. C Reserved for future use.
  128. C RWORK :WORK Real RWORK(USER DEFINED).
  129. C Real array that can be used for workspace in MSOLVE.
  130. C IWORK :WORK Integer IWORK(USER DEFINED).
  131. C Integer array that can be used for workspace in MSOLVE.
  132. C AK :IN Real.
  133. C Current iterate Orthomin iteration parameter.
  134. C BNRM :OUT Real.
  135. C Current solution B-norm, if ITOL = 1 or 2.
  136. C SOLNRM :OUT Real.
  137. C True solution norm, if ITOL = 11.
  138. C
  139. C *Function Return Values:
  140. C 0 : Error estimate (determined by ITOL) is *NOT* less than the
  141. C specified tolerance, TOL. The iteration must continue.
  142. C 1 : Error estimate (determined by ITOL) is less than the
  143. C specified tolerance, TOL. The iteration can be considered
  144. C complete.
  145. C
  146. C *Cautions:
  147. C This routine will attempt to write to the Fortran logical output
  148. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  149. C this logical unit is attached to a file or terminal before calling
  150. C this routine with a non-zero value for IUNIT. This routine does
  151. C not check for the validity of a non-zero IUNIT unit number.
  152. C
  153. C***SEE ALSO SOMN, SSDOMN, SSLUOM
  154. C***ROUTINES CALLED R1MACH, SNRM2
  155. C***COMMON BLOCKS SSLBLK
  156. C***REVISION HISTORY (YYMMDD)
  157. C 871119 DATE WRITTEN
  158. C 881213 Previous REVISION DATE
  159. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  160. C 890922 Numerous changes to prologue to make closer to SLATEC
  161. C standard. (FNF)
  162. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  163. C 891003 Removed C***REFER TO line, per MKS.
  164. C 910411 Prologue converted to Version 4.0 format. (BAB)
  165. C 910502 Removed MSOLVE from ROUTINES CALLED list. (FNF)
  166. C 910506 Made subsidiary to SOMN. (FNF)
  167. C 920407 COMMON BLOCK renamed SSLBLK. (WRB)
  168. C 920511 Added complete declaration section. (WRB)
  169. C 920930 Corrected to not print AK when ITER=0. (FNF)
  170. C 921026 Changed 1.0E10 to R1MACH(2). (FNF)
  171. C 921113 Corrected C***CATEGORY line. (FNF)
  172. C***END PROLOGUE ISSOMN
  173. C .. Scalar Arguments ..
  174. REAL AK, BNRM, ERR, SOLNRM, TOL
  175. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, N, NELT, NSAVE
  176. C .. Array Arguments ..
  177. REAL A(NELT), AP(N,0:NSAVE), B(N), CSAV(NSAVE), DZ(N),
  178. + EMAP(N,0:NSAVE), P(N,0:NSAVE), R(N), RWORK(*), X(N), Z(N)
  179. INTEGER IA(NELT), IWORK(*), JA(NELT)
  180. C .. Subroutine Arguments ..
  181. EXTERNAL MSOLVE
  182. C .. Arrays in Common ..
  183. REAL SOLN(1)
  184. C .. Local Scalars ..
  185. INTEGER I
  186. C .. External Functions ..
  187. REAL R1MACH, SNRM2
  188. EXTERNAL R1MACH, SNRM2
  189. C .. Common blocks ..
  190. COMMON /SSLBLK/ SOLN
  191. C***FIRST EXECUTABLE STATEMENT ISSOMN
  192. ISSOMN = 0
  193. C
  194. IF( ITOL.EQ.1 ) THEN
  195. C err = ||Residual||/||RightHandSide|| (2-Norms).
  196. IF(ITER .EQ. 0) BNRM = SNRM2(N, B, 1)
  197. ERR = SNRM2(N, R, 1)/BNRM
  198. ELSE IF( ITOL.EQ.2 ) THEN
  199. C -1 -1
  200. C err = ||M Residual||/||M RightHandSide|| (2-Norms).
  201. IF(ITER .EQ. 0) THEN
  202. CALL MSOLVE(N, B, DZ, NELT, IA, JA, A, ISYM, RWORK, IWORK)
  203. BNRM = SNRM2(N, DZ, 1)
  204. ENDIF
  205. ERR = SNRM2(N, Z, 1)/BNRM
  206. ELSE IF( ITOL.EQ.11 ) THEN
  207. C err = ||x-TrueSolution||/||TrueSolution|| (2-Norms).
  208. IF(ITER .EQ. 0) SOLNRM = SNRM2(N, SOLN, 1)
  209. DO 10 I = 1, N
  210. DZ(I) = X(I) - SOLN(I)
  211. 10 CONTINUE
  212. ERR = SNRM2(N, DZ, 1)/SOLNRM
  213. ELSE
  214. C
  215. C If we get here ITOL is not one of the acceptable values.
  216. ERR = R1MACH(2)
  217. IERR = 3
  218. ENDIF
  219. C
  220. IF(IUNIT .NE. 0) THEN
  221. IF( ITER.EQ.0 ) THEN
  222. WRITE(IUNIT,1000) NSAVE, N, ITOL
  223. WRITE(IUNIT,1010) ITER, ERR
  224. ELSE
  225. WRITE(IUNIT,1010) ITER, ERR, AK
  226. ENDIF
  227. ENDIF
  228. IF(ERR .LE. TOL) ISSOMN = 1
  229. C
  230. RETURN
  231. 1000 FORMAT(' Preconditioned Orthomin(',I3,') for ',
  232. $ 'N, ITOL = ',I5, I5,
  233. $ /' ITER',' Error Estimate',' Alpha')
  234. 1010 FORMAT(1X,I4,1X,E16.7,1X,E16.7)
  235. C------------- LAST LINE OF ISSOMN FOLLOWS ----------------------------
  236. END