Télécharger dgetv0.eso

Retour à la liste

Numérotation des lignes :

dgetv0
  1. C DGETV0 SOURCE FANDEUR 22/05/02 21:15:06 11359
  2. c-----------------------------------------------------------------------
  3. c\BeginDoc
  4. c
  5. c\Name: dgetv0
  6. c
  7. c\Description:
  8. c Generate a random initial residual vector for the Arnoldi process.
  9. c Force the residual vector to be in the range of the operator OP.
  10. c
  11. c\Usage:
  12. c call dgetv0
  13. c ( IDO, BMAT, ITRY, INITV, N, J, V, LDV, RESID, RNORM,
  14. c IPNTR, WORKD, IERR )
  15. c
  16. c\Arguments
  17. c IDO Integer. (INPUT/OUTPUT)
  18. c Reverse communication flag. IDO must be zero on the first
  19. c call to dgetv0.
  20. c -------------------------------------------------------------
  21. c IDO = 0: first call to the reverse communication interface
  22. c IDO = -1: compute Y = OP * X where
  23. c IPNTR(1) is the pointer into WORKD for X,
  24. c IPNTR(2) is the pointer into WORKD for Y.
  25. c This is for the initialization phase to force the
  26. c starting vector into the range of OP.
  27. c IDO = 2: compute Y = B * X where
  28. c IPNTR(1) is the pointer into WORKD for X,
  29. c IPNTR(2) is the pointer into WORKD for Y.
  30. c IDO = 99: done
  31. c -------------------------------------------------------------
  32. c
  33. c BMAT Character*1. (INPUT)
  34. c BMAT specifies the type of the matrix B in the (generalized)
  35. c eigenvalue problem A*x = lambda*B*x.
  36. c B = 'I' -> standard eigenvalue problem A*x = lambda*x
  37. c B = 'G' -> generalized eigenvalue problem A*x = lambda*B*x
  38. c
  39. c ITRY Integer. (INPUT)
  40. c ITRY counts the number of times that dgetv0 is called.
  41. c It should be set to 1 on the initial call to dgetv0.
  42. c
  43. c INITV Logical variable. (INPUT)
  44. c .TRUE. => the initial residual vector is given in RESID.
  45. c .FALSE. => generate a random initial residual vector.
  46. c
  47. c N Integer. (INPUT)
  48. c Dimension of the problem.
  49. c
  50. c J Integer. (INPUT)
  51. c Index of the residual vector to be generated, with respect to
  52. c the Arnoldi process. J > 1 in case of a "restart".
  53. c
  54. c V REAL*8 N by J array. (INPUT)
  55. c The first J-1 columns of V contain the current Arnoldi basis
  56. c if this is a "restart".
  57. c
  58. c LDV Integer. (INPUT)
  59. c Leading dimension of V exactly as declared in the calling
  60. c program.
  61. c
  62. c RESID Double precision array of length N. (INPUT/OUTPUT)
  63. c Initial residual vector to be generated. If RESID is
  64. c provided, force RESID into the range of the operator OP.
  65. c
  66. c RNORM Double precision scalar. (OUTPUT)
  67. c B-norm of the generated residual.
  68. c
  69. c IPNTR Integer array of length 3. (OUTPUT)
  70. c
  71. c WORKD Double precision work array of length 2*N. (REVERSE COMMUNICATION).
  72. c On exit, WORK(1:N) = B*RESID to be used in SSAITR.
  73. c
  74. c IERR Integer. (OUTPUT)
  75. c = 0: Normal exit.
  76. c = -1: Cannot generate a nontrivial restarted residual vector
  77. c in the range of the operator OP.
  78. c
  79. c\EndDoc
  80. c
  81. c-----------------------------------------------------------------------
  82. c
  83. c\BeginLib
  84. c
  85. c\Local variables:
  86. c xxxxxx real
  87. c
  88. c\References:
  89. c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in
  90. c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992),
  91. c pp 357-385.
  92. c 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly
  93. c Restarted Arnoldi Iteration", Rice University Technical Report
  94. c TR95-13, Department of Computational and Applied Mathematics.
  95. c
  96. c\Routines called:
  97. c arscnd ARPACK utility routine for timing. -> deleted by BP in 2020
  98. c dvout ARPACK utility routine for vector output.
  99. c dlarnv LAPACK routine for generating a random vector.
  100. c dgemv Level 2 BLAS routine for matrix vector multiplication.
  101. c dcopy Level 1 BLAS that copies one vector to another.
  102. c ddot Level 1 BLAS that computes the scalar product of two vectors.
  103. c dnrm2 Level 1 BLAS that computes the norm of a vector.
  104. c
  105. c\Author
  106. c Danny Sorensen Phuong Vu
  107. c Richard Lehoucq CRPC / Rice University
  108. c Dept. of Computational & Houston, Texas
  109. c Applied Mathematics
  110. c Rice University
  111. c Houston, Texas
  112. c
  113. c\SCCS Information: @(#)
  114. c FILE: getv0.F SID: 2.7 DATE OF SID: 04/07/99 RELEASE: 2
  115. c
  116. c\EndLib
  117. c
  118. c-----------------------------------------------------------------------
  119. c
  120. subroutine dgetv0
  121. & ( ido, bmat, itry, initv, n, j, v, ldv, resid, rnorm,
  122. & ipntr, workd, nopx,nbx, ierr )
  123. c
  124. c %----------------------------------------------------%
  125. c | Include files for debugging and timing information |
  126. c -INC TARTRAK
  127. c %----------------------------------------------------%
  128. c
  129. c
  130. c %------------------%
  131. c | Scalar Arguments |
  132. c %------------------%
  133. c
  134. c REAL*8 T0
  135. c REAL*8 T1
  136. c REAL*8 T2
  137. c REAL*8 T3
  138. character bmat*1
  139. logical initv
  140. integer ido, ierr, itry, j, ldv, n
  141. REAL*8
  142. & rnorm
  143. c
  144. c %-----------------%
  145. c | Array Arguments |
  146. c %-----------------%
  147. c
  148. integer ipntr(3)
  149. REAL*8
  150. & resid(n), v(ldv,j), workd(2*n)
  151. c
  152. c %------------%
  153. c | Parameters |
  154. c %------------%
  155. c
  156. REAL*8
  157. & one, zero
  158. parameter (one = 1.0D+0, zero = 0.0D+0)
  159. c
  160. c %------------------------%
  161. c | Local Scalars & Arrays |
  162. c %------------------------%
  163. c
  164. logical first, inits, orth
  165. integer idist, iseed(4), iter, msglvl, jj
  166. REAL*8
  167. & rnorm0
  168. save first, iseed, inits, iter, msglvl, orth, rnorm0
  169. c
  170. c %----------------------%
  171. c | External Subroutines |
  172. c %----------------------%
  173. c
  174. external dcopy, dgemv
  175. c external dlarnv, dvout, arsncd
  176. c
  177. c %--------------------%
  178. c | External Functions |
  179. c %--------------------%
  180. c
  181. REAL*8
  182. external ddot, dnrm2
  183. c
  184. c %---------------------%
  185. **c | Intrinsic Functions |
  186. **c %---------------------%
  187. **c
  188. ** intrinsic abs, sqrt
  189. **c
  190. **c %-----------------%
  191. **c | Data Statements |
  192. **c %-----------------%
  193. **c
  194. data inits /.true./
  195. **c
  196. **c %-----------------------%
  197. **c | Executable Statements |
  198. c %-----------------------%
  199. c T0 = 0.D0
  200. c T1 = 0.D0
  201. c T2 = 0.D0
  202. c T3 = 0.D0
  203. c
  204. c
  205. c %-----------------------------------%
  206. c | Initialize the seed of the LAPACK |
  207. c | random number generator |
  208. c %-----------------------------------%
  209. c
  210. if (inits) then
  211. iseed(1) = 1
  212. iseed(2) = 3
  213. iseed(3) = 5
  214. iseed(4) = 7
  215. inits = .false.
  216. end if
  217. c
  218. if (ido .eq. 0) then
  219. c
  220. c %-------------------------------%
  221. c | Initialize timing statistics |
  222. c | & message level for debugging |
  223. c %-------------------------------%
  224. c
  225. * call arscnd (t0)
  226. msglvl = mgetv0
  227. c
  228. ierr = 0
  229. iter = 0
  230. first = .FALSE.
  231. orth = .FALSE.
  232. c
  233. c %-----------------------------------------------------%
  234. c | Possibly generate a random starting vector in RESID |
  235. c | Use a LAPACK random number generator used by the |
  236. c | matrix generation routines. |
  237. c | idist = 1: uniform (0,1) distribution; |
  238. c | idist = 2: uniform (-1,1) distribution; |
  239. c | idist = 3: normal (0,1) distribution; |
  240. c %-----------------------------------------------------%
  241. c
  242. if (.not.initv) then
  243. idist = 2
  244. call dlarnv (idist, iseed, n, resid)
  245. end if
  246. c
  247. c %----------------------------------------------------------%
  248. c | Force the starting vector into the range of OP to handle |
  249. c | the generalized problem when B is possibly (singular). |
  250. c %----------------------------------------------------------%
  251. c
  252. * call arscnd (t2)
  253. if (bmat .eq. 'G') then
  254. nopx = nopx + 1
  255. ipntr(1) = 1
  256. ipntr(2) = n + 1
  257. call dcopy (n, resid, 1, workd, 1)
  258. ido = -1
  259. go to 9000
  260. end if
  261. end if
  262. c
  263. c %-----------------------------------------%
  264. c | Back from computing OP*(initial-vector) |
  265. c %-----------------------------------------%
  266. c
  267. if (first) go to 20
  268. c
  269. c %-----------------------------------------------%
  270. c | Back from computing B*(orthogonalized-vector) |
  271. c %-----------------------------------------------%
  272. c
  273. if (orth) go to 40
  274. c
  275. c if (bmat .eq. 'G') then
  276. * call arscnd (t3)
  277. c tmvopx = tmvopx + (t3 - t2)
  278. c end if
  279. c
  280. c %------------------------------------------------------%
  281. c | Starting vector is now in the range of OP; r = OP*r; |
  282. c | Compute B-norm of starting vector. |
  283. c %------------------------------------------------------%
  284. c
  285. * call arscnd (t2)
  286. first = .TRUE.
  287. if (bmat .eq. 'G') then
  288. nbx = nbx + 1
  289. call dcopy (n, workd(n+1), 1, resid, 1)
  290. ipntr(1) = n + 1
  291. ipntr(2) = 1
  292. ido = 2
  293. go to 9000
  294. else if (bmat .eq. 'I') then
  295. call dcopy (n, resid, 1, workd, 1)
  296. end if
  297. c
  298. 20 continue
  299. c
  300. c if (bmat .eq. 'G') then
  301. * call arscnd (t3)
  302. c tmvbx = tmvbx + (t3 - t2)
  303. c end if
  304. c
  305. first = .FALSE.
  306. if (bmat .eq. 'G') then
  307. rnorm0 = ddot (n, resid, 1, workd, 1)
  308. rnorm0 = sqrt(abs(rnorm0))
  309. else if (bmat .eq. 'I') then
  310. rnorm0 = dnrm2(n, resid, 1)
  311. end if
  312. rnorm = rnorm0
  313. c
  314. c %---------------------------------------------%
  315. c | Exit if this is the very first Arnoldi step |
  316. c %---------------------------------------------%
  317. c
  318. if (j .eq. 1) go to 50
  319. c
  320. c %----------------------------------------------------------------
  321. c | Otherwise need to B-orthogonalize the starting vector against |
  322. c | the current Arnoldi basis using Gram-Schmidt with iter. ref. |
  323. c | This is the case where an invariant subspace is encountered |
  324. c | in the middle of the Arnoldi factorization. |
  325. c | |
  326. c | s = V^{T}*B*r; r = r - V*s; |
  327. c | |
  328. c | Stopping criteria used for iter. ref. is discussed in |
  329. c | Parlett's book, page 107 and in Gragg & Reichel TOMS paper. |
  330. c %---------------------------------------------------------------%
  331. c
  332. orth = .TRUE.
  333. 30 continue
  334.  
  335. call dgemv ('T', n, j-1, one, v, ldv, workd, 1,
  336. & zero, workd(n+1), 1)
  337. call dgemv ('N', n, j-1, (-one), v, ldv, workd(n+1), 1,
  338. & one, resid, 1)
  339. c
  340. c %----------------------------------------------------------%
  341. c | Compute the B-norm of the orthogonalized starting vector |
  342. c %----------------------------------------------------------%
  343. c
  344. * call arscnd (t2)
  345. if (bmat .eq. 'G') then
  346. nbx = nbx + 1
  347. call dcopy (n, resid, 1, workd(n+1), 1)
  348. ipntr(1) = n + 1
  349. ipntr(2) = 1
  350. ido = 2
  351. go to 9000
  352. else if (bmat .eq. 'I') then
  353. call dcopy (n, resid, 1, workd, 1)
  354. end if
  355. c
  356. 40 continue
  357. c
  358. c if (bmat .eq. 'G') then
  359. * call arscnd (t3)
  360. c tmvbx = tmvbx + (t3 - t2)
  361. c end if
  362. c
  363. if (bmat .eq. 'G') then
  364. rnorm = ddot (n, resid, 1, workd, 1)
  365. rnorm = sqrt(abs(rnorm))
  366. else if (bmat .eq. 'I') then
  367. rnorm = dnrm2(n, resid, 1)
  368. end if
  369. c
  370. c %--------------------------------------%
  371. c | Check for further orthogonalization. |
  372. c %--------------------------------------%
  373. c
  374. c if (msglvl .gt. 2) then
  375. c call dvout ( 1, rnorm0, ndigit,
  376. c & '_getv0: re-orthonalization ; rnorm0 is')
  377. c call dvout ( 1, rnorm, ndigit,
  378. c & '_getv0: re-orthonalization ; rnorm is')
  379. c end if
  380. c
  381. if (rnorm .gt. 0.717*rnorm0) go to 50
  382. c
  383. iter = iter + 1
  384. if (iter .le. 5) then
  385. c
  386. c %-----------------------------------%
  387. c | Perform iterative refinement step |
  388. c %-----------------------------------%
  389. c
  390. rnorm0 = rnorm
  391. go to 30
  392. else
  393. c
  394. c %------------------------------------%
  395. c | Iterative refinement step "failed" |
  396. c %------------------------------------%
  397. c
  398. do 45 jj = 1, n
  399. resid(jj) = zero
  400. 45 continue
  401. rnorm = zero
  402. ierr = -1
  403. end if
  404. c
  405. 50 continue
  406.  
  407. c if (msglvl .gt. 0) then
  408. c call dvout ( 1, rnorm, ndigit,
  409. c & '_getv0: B-norm of initial - restarted starting vector')
  410. c end if
  411. c if (msglvl .gt. 3) then
  412. c call dvout ( n, resid, ndigit,
  413. c & '_getv0: initial - restarted starting vector')
  414. c end if
  415. ido = 99
  416. c
  417. * call arscnd (t1)
  418. c tgetv0 = tgetv0 + (t1 - t0)
  419. c
  420. 9000 continue
  421. return
  422. c
  423. c %---------------%
  424. c | End of dgetv0 |
  425. c %---------------%
  426. c
  427. end
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales