Debian Codegraph @

debian/external_deps/fetk/punc/src/pmg/src_f77/ncgdrvd.f

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file ncgdrvd.f
3 c* @author Michael Holst
4 c* @brief Driver for the nonlinear CG methods.
5 c* @version $Id: ncgdrvd.f,v 1.2 2010/08/12 05:45:35 fetk Exp $
6 c* @attention
7 c* @verbatim
8 c*
9 c* PMG -- Parallel algebraic MultiGrid
10 c* Copyright (C) 1994-- Michael Holst.
11 c*
12 c* Michael Holst <[email protected]>
13 c* University of California, San Diego
14 c* Department of Mathematics, 5739 AP&M
15 c* 9500 Gilman Drive, Dept. 0112
16 c* La Jolla, CA 92093-0112 USA
17 c* http://math.ucsd.edu/~mholst
18 c*
19 c* This file is part of PMG.
20 c*
21 c* PMG is free software; you can redistribute it and/or modify
22 c* it under the terms of the GNU General Public License as published by
23 c* the Free Software Foundation; either version 2 of the License, or
24 c* (at your option) any later version.
25 c*
26 c* PMG is distributed in the hope that it will be useful,
27 c* but WITHOUT ANY WARRANTY; without even the implied warranty of
28 c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 c* GNU General Public License for more details.
30 c*
31 c* You should have received a copy of the GNU General Public License
32 c* along with PMG; if not, write to the Free Software
33 c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 c*
35 c* Linking PMG statically or dynamically with other modules is making a
36 c* combined work based on PMG. Thus, the terms and conditions of the GNU
37 c* General Public License cover the whole combination.
38 c*
39 c* SPECIAL GPL EXCEPTION
40 c* In addition, as a special exception, the copyright holders of PMG
41 c* give you permission to combine the PMG program with free software
42 c* programs and libraries that are released under the GNU LGPL or with
43 c* code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision.
44 c* Such combined software may be linked with PMG and redistributed together
45 c* in original or modified form as mere aggregation without requirement that
46 c* the entire work be under the scope of the GNU General Public License.
47 c* This special exception permission is also extended to any software listed
48 c* in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries.
49 c*
50 c* Note that people who make modified versions of PMG are not obligated
51 c* to grant this special exception for their modified versions; it is
52 c* their choice whether to do so. The GNU General Public License gives
53 c* permission to release a modified version without this exception; this
54 c* exception also makes it possible to release a modified version which
55 c* carries forward this exception.
56 c*
57 c* @endverbatim
58 c* ///////////////////////////////////////////////////////////////////////////
59
60 subroutine ncghsdriv(iparm,rparm,iwork,rwork,u,
61 2 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
62 c* *********************************************************************
63 c* purpose:
64 c*
65 c* linear/nonlinear conjugate gradient driver (fletcher-reeves).
66 c*
67 c* author: michael holst
68 c* *********************************************************************
69 implicit none
70 c*
71 c* *** input parameters ***
72 integer iparm(*),iwork(*)
73 double precision rparm(*),rwork(*),u(*)
74 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
75 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
76 c*
77 c* *** variables returned from mgsz ***
78 integer iretot,iintot
79 c*
80 c* *** misc variables ***
81 integer nrwk,niwk,nx,ny,nz,nlev,ierror,n
82 integer k_iz,k_w0
83 integer k_ipc,k_rpc,k_ac,k_cc,k_fc
84 integer n_iz,n_ipc,n_rpc
85 c*
86 c* *** decode some parameters ***
87 nrwk = iparm(1)
88 niwk = iparm(2)
89 nx = iparm(3)
90 ny = iparm(4)
91 nz = iparm(5)
92 nlev = iparm(6)
93 n = nx * ny * nz
94 n_iz = 10*(nlev+1)
95 n_ipc = 100*(nlev+1)
96 n_rpc = 100*(nlev+1)
97 c*
98 c* *** compute required work array sizes ***
99 iintot = n_iz + n_ipc
100 iretot = n_rpc + (3*n) + (4*n)
101 c*
102 c* *** some more checks on input ***
103 if ((nrwk.lt.iretot) .or. (niwk.lt.iintot)) then
104 print*,'% NCGHSDRIV: real work space must be: ',iretot
105 print*,'% NCGHSDRIV: integer work space must be: ',iintot
106 ierror = -3
107 iparm(51) = ierror
108 return
109 endif
110 c*
111 c* *** iwork offsets ***
112 k_iz = 1
113 k_ipc = k_iz + n_iz
114 c*
115 c* *** rwork offsets ***
116 k_rpc = 1
117 k_cc = k_rpc + n_rpc
118 k_fc = k_cc + n
119 k_w0 = k_fc + n
120 k_ac = k_w0 + n
121 c* ***k_ac_after = k_ac + 4*n
122 c*
123 c* *** call the multigrid driver ***
124 call ncghsdriv2(iparm,rparm,nx,ny,nz,u,iwork(k_iz),
125 2 rwork(k_w0),
126 4 iwork(k_ipc),rwork(k_rpc),
127 5 rwork(k_ac),rwork(k_cc),rwork(k_fc),
128 8 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
129 c*
130 c* *** return and end ***
131 return
132 end
133 subroutine ncghsdriv2(iparm,rparm,nx,ny,nz,u,iz,
134 2 w0,
135 3 ipc,rpc,ac,cc,fc,
136 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
137 c* *********************************************************************
138 c* purpose:
139 c*
140 c* linear/nonlinear conjugate gradient driver (fletcher-reeves).
141 c*
142 c* author: michael holst
143 c* *********************************************************************
144 implicit none
145 c*
146 c* *** input parameters ***
147 integer iparm(*),ipc(*),iz(*)
148 double precision rparm(*),rpc(*)
149 double precision u(*),w0(*),ac(*),cc(*),fc(*)
150 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
151 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
152 c*
153 c* *** misc variables ***
154 integer mgkey,nlev,itmax,iok,iinfo,istop,ipkey,nu1,nu2
155 integer nx,ny,nz,ilev,ido,iters,ierror,ibound,mode
156 integer mgprol,mgcoar,mgsolv,mgdisc
157 double precision epsiln,epsmac,errtol,omegal,omegan
158 double precision pc_dumm
159 double precision bf,oh,tsetupf,tsetupc,tsolve
160 c*
161 c* *** decode the iparm array ***
162 nlev = iparm(6)
163 nu1 = iparm(7)
164 nu2 = iparm(8)
165 mgkey = iparm(9)
166 itmax = iparm(10)
167 istop = iparm(11)
168 iinfo = iparm(12)
169 ipkey = iparm(14)
170 mode = iparm(16)
171 mgprol = iparm(17)
172 mgcoar = iparm(18)
173 mgdisc = iparm(19)
174 mgsolv = iparm(21)
175 errtol = rparm(1)
176 omegal = rparm(9)
177 omegan = rparm(10)
178 c*
179 c* *** intitialize the iteration timer ***
180 call prtstp(0,-99,0.0d0,0.0d0,0.0d0)
181 c*
182 c* *** build the multigrid data structure in iz ***
183 call buildstr (nx,ny,nz,nlev,iz)
184 c*
185 c* *** start timer ***
186 call tstart(bf,oh)
187 c*
188 c* *** build op and rhs on fine grid ***
189 ido = 0
190 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
191 2 mgprol,mgcoar,mgsolv,mgdisc,
192 3 ipc,rpc,pc_dumm,ac,cc,fc,
193 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
194 c*
195 c* *** stop timer ***
196 call tstop(bf,oh,tsetupf)
197 print*,'% NCGHSDRIV2: fine problem setup time: ',tsetupf
198 tsetupc = 0.0d0
199 c*
200 c* ******************************************************************
201 c* *** this overwrites the rhs array provided by pde specification
202 c* ****** compute an algebraically produced rhs for the given tcf ***
203 if ((istop .eq. 4) .or. (istop .eq. 5)) then
204 if ((mode .eq. 1) .or. (mode .eq. 2)) then
205 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,tcf,fc,w0)
206 else
207 call matvec(nx,ny,nz,ipc,rpc,ac,cc,tcf,fc)
208 endif
209 endif
210 c* ******************************************************************
211 c*
212 c* *** determine machine epsilon ***
213 epsiln = epsmac(0)
214 c*
215 c* *** impose zero dirichlet boundary conditions (now in source fcn) ***
216 call fbound00(nx,ny,nz,u)
217 c*
218 c* *** MATLAB ***
219 print*,' cg = [ '
220 c*
221 c* *** start timer ***
222 call tstart(bf,oh)
223 c*
224 c* *** call specified multigrid method ***
225 if ((mode .eq. 0) .or. (mode .eq. 2)) then
226 print*,'% NCGHSDRIV2: linear mode...'
227 iok = 1
228 ilev = 1
229 call cghsgo(nx,ny,nz,u,w0,a1cf,a2cf,a3cf,ccf,fcf,
230 2 istop,itmax,iters,ierror,
231 3 iok,iinfo,epsiln,errtol,omegal,
232 4 ipc,rpc,ac,cc,fc,tcf)
233 endif
234 if ((mode .eq. 1) .or. (mode .eq. 2)) then
235 print*,'% NCGHSDRIV2: nonlinear mode...'
236 iok = 1
237 ilev = 1
238 call ncghsgo(nx,ny,nz,u,w0,a1cf,a2cf,a3cf,ccf,fcf,
239 2 istop,itmax,iters,ierror,
240 3 iok,iinfo,epsiln,errtol,omegan,
241 4 ipc,rpc,ac,cc,fc,tcf)
242 endif
243 c*
244 c* *** stop timer ***
245 call tstop(bf,oh,tsolve)
246 print*,'% NCGHSDRIV2: solve time: ',tsolve
247 c*
248 c* *** MATLAB ***
249 write(*,100) 'cg_sf',tsetupf,'cg_sc',tsetupc,
250 2 'cg_st',(tsetupf+tsetupc),'cg_so',tsolve
251 100 format(' ];',4(' ',a7,'=',1pe9.3,';'))
252 c*
253 c* *** restore boundary conditions ***
254 ibound = 1
255 call fbound(ibound,nx,ny,nz,u,gxcf,gycf,gzcf)
256 c*
257 c* *** return and end ***
258 return
259 end
260 subroutine ncghsgo(nx,ny,nz,x,r,p,ap,zk,zkp1,tmp,
261 2 istop,itmax,iters,ierror,
262 3 iok,iinfo,epsiln,errtol,omega,
263 4 ipc,rpc,ac,cc,fc,tru)
264 c* *********************************************************************
265 c* purpose:
266 c*
267 c* nonlinear conjugate gradients (fletcher-reeves).
268 c*
269 c* author: michael holst
270 c* *********************************************************************
271 implicit none
272 c*
273 c* *** other declarations ***
274 integer ipc(*),iok,iinfo
275 integer itmax,iters,ierror
276 integer istop
277 integer nx,ny,nz
278 double precision omega,errtol,epsiln
279 double precision rsden,rsnrm,orsnrm,xnrm1,xnrm2,xdot
280 double precision x(*),r(*),p(*),ap(*),zk(*),zkp1(*),tmp(*)
281 double precision rpc(*),ac(*),cc(*),fc(*),tru(*)
282 double precision alpha,rhok2,beta,rhok1
283 c*
284 cmdir 0 0
285 c*
286 c* *** do some i/o if requested ***
287 if (iinfo.ne.0) then
288 write(6,100)'% NCGHSGO: starting:',nx,ny,nz
289 100 format(a,(2x,' [',i3,',',i3,',',i3,'] '))
290 endif
291 c*
292 c* *** initial wall clock ***
293 call prtini(istop)
294 call prtstp(iok,-1,0.0d0,0.0d0,0.0d0)
295 c*
296 c* **************************************************************
297 c* *** note: if (iok.ne.0) then: use a stopping test. ***
298 c* *** else: use just the itmax to stop iteration. ***
299 c* **************************************************************
300 c* *** istop=0 most efficient (whatever it is) ***
301 c* *** istop=1 relative residual ***
302 c* *** istop=2 rms difference of successive iterates ***
303 c* *** istop=3 relative true error (provided for testing) ***
304 c* **************************************************************
305 c*
306 c* *** compute denominator for stopping criterion ***
307 if (istop .eq. 0) then
308 rsden = 1.0d0
309 elseif (istop .eq. 1) then
310 c* *** compute initial residual with zero initial guess ***
311 c* *** this is analogous to the linear case where one can ***
312 c* *** simply take norm of rhs for a zero initial guess ***
313 call azeros(nx,ny,nz,tmp)
314 call nmresid(nx,ny,nz,ipc,rpc,ac,cc,fc,tmp,r,zk)
315 rsden = xnrm1(nx,ny,nz,r)
316 elseif (istop .eq. 2) then
317 rsden = dsqrt(dble((nx-2)*(ny-2)*(nz-2)))
318 elseif (istop .eq. 3) then
319 rsden = xnrm2(nx,ny,nz,tru)
320 elseif (istop .eq. 4) then
321 rsden = xnrm2(nx,ny,nz,tru)
322 elseif (istop .eq. 5) then
323 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,tru,r,zk)
324 rsden = dsqrt(xdot(nx,ny,nz,tru,r))
325 else
326 print*,'% NCGHSGO: bad istop value... '
327 endif
328 if (rsden.eq.0.0d0) then
329 rsden = 1.0d0
330 print*,'% NCGHSGO: rhs is zero '
331 endif
332 rsnrm = rsden
333 orsnrm = rsnrm
334 call prtstp (iok,0,rsnrm,rsden,orsnrm)
335 c*
336 c* *** now compute residual with the initial guess ***
337 call nmresid(nx,ny,nz,ipc,rpc,ac,cc,fc,x,r,zk)
338 c*
339 c* *** setup for the looping ***
340 iters = 0
341 30 continue
342 c*
343 c* *** save iterate if stop test will use it on next iter ***
344 if (istop .eq. 2) call xcopy(nx,ny,nz,x,tru)
345 c*
346 c* *** form new direction vector from old one and residual ***
347 rhok2 = xdot(nx,ny,nz,r,r)
348 if (iters .eq. 0) then
349 call xcopy(nx,ny,nz,r,p)
350 else
351 beta = rhok2 / rhok1
352 call xaxpy(nx,ny,nz,((1.0d0)/beta),r,p)
353 call xscal(nx,ny,nz,beta,p)
354 endif
355 c*
356 c* *** nonlinear case: do a line search ***
357 c* *** (note: "ap,zk,zkp1" passed back from line search as desired) ***
358 call xcopy(nx,ny,nz,r,tmp)
359 call linesearch(nx,ny,nz,alpha,
360 2 ipc,rpc,ac,cc,fc,p,x,tmp,ap,zk,zkp1)
361 c*
362 c* *** save rhok2 for next iteration ***
363 rhok1 = rhok2
364 c*
365 c* *** update solution in direction p of length alpha ***
366 call xaxpy(nx,ny,nz,alpha,p,x)
367 c*
368 c* *** update residual ***
369 call xaxpy(nx,ny,nz,(-alpha),ap,r)
370 call xaxpy(nx,ny,nz,(1.0d0),zk,r)
371 call xaxpy(nx,ny,nz,(-1.0d0),zkp1,r)
372 c*
373 c* ***** *** switch to descent if necessary ***
374 c* ***** itmax_d = 10
375 c* ***** iter_d = 0
376 c* ***** alpha = -1.0d0
377 c* ***** rsnrm_tmp = xnrm1(nx,ny,nz,r)
378 c* ***** 18 continue
379 c* ***** if ((rsnrm_tmp.lt.rsnrm).or.(iter_d.gt.itmax_d)) then
380 c* ***** print*,'% finished with descent: r_o,r_n',rsnrm,rsnrm_tmp
381 c* ***** if (iter_d .gt. 0) call xcopy(nx,ny,nz,tmp4,r)
382 c* ***** goto 19
383 c* ***** endif
384 c* ***** print*,'% trying a descent: r_o,r_n',rsnrm,rsnrm_tmp
385 c* ***** call xcopy(nx,ny,nz,tmp2,tmp)
386 c* ***** call xaxpy(nx,ny,nz,alpha,tmp3,tmp)
387 c* ***** call nmresid(nx,ny,nz,ipc,rpc,ac,cc,fc,tmp,tmp4,ap)
388 c* ***** rsnrm_tmp = xnrm1(nx,ny,nz,tmp4)
389 c* ***** alpha = alpha / 2.0d0
390 c* ***** iter_d = iter_d + 1
391 c* ***** goto 18
392 c* ***** 19 continue
393 c*
394 c* *** some bookkeeping ***
395 iters = iters + 1
396 c*
397 c* *** compute/check the current stopping test ***
398 orsnrm = rsnrm
399 if (istop .eq. 0) then
400 rsnrm = xnrm1(nx,ny,nz,r)
401 elseif (istop .eq. 1) then
402 rsnrm = xnrm1(nx,ny,nz,r)
403 elseif (istop .eq. 2) then
404 call xcopy(nx,ny,nz,tru,tmp)
405 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
406 rsnrm = xnrm1(nx,ny,nz,tmp)
407 elseif (istop .eq. 3) then
408 call xcopy(nx,ny,nz,tru,tmp)
409 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
410 rsnrm = xnrm2(nx,ny,nz,tmp)
411 elseif (istop .eq. 4) then
412 call xcopy(nx,ny,nz,tru,tmp)
413 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
414 rsnrm = xnrm2(nx,ny,nz,tmp)
415 elseif (istop .eq. 5) then
416 call xcopy(nx,ny,nz,tru,tmp)
417 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
418 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,tmp,zk,zkp1)
419 rsnrm = dsqrt(xdot(nx,ny,nz,tmp,zk))
420 else
421 print*,'% NCGHSGO: bad istop value... '
422 endif
423 call prtstp (iok,iters,rsnrm,rsden,orsnrm)
424 if ((rsnrm/rsden) .le. errtol) goto 99
425 if (iters .ge. itmax) goto 99
426 goto 30
427 c*
428 c* *** return and end ***
429 99 continue
430 return
431 end
432 subroutine cghsgo(nx,ny,nz,x,r,p,ap,zk,zkp1,tmp,
433 2 istop,itmax,iters,ierror,
434 3 iok,iinfo,epsiln,errtol,omega,
435 4 ipc,rpc,ac,cc,fc,tru)
436 c* *********************************************************************
437 c* purpose:
438 c*
439 c* linear conjugate gradients (hestenes-steifel).
440 c*
441 c* author: michael holst
442 c* *********************************************************************
443 implicit none
444 c*
445 c* *** other declarations ***
446 integer ipc(*),iok,iinfo
447 integer itmax,iters,ierror
448 integer istop
449 integer nx,ny,nz
450 double precision omega,errtol,epsiln
451 double precision rsden,rsnrm,orsnrm,xnrm1,xnrm2,xdot
452 double precision x(*),r(*),p(*),ap(*),zk(*),zkp1(*),tmp(*)
453 double precision rpc(*),ac(*),cc(*),fc(*),tru(*)
454 double precision alpha,rhok2,beta,rhok1,pAp
455 c*
456 cmdir 0 0
457 c*
458 c* *** do some i/o if requested ***
459 if (iinfo.ne.0) then
460 write(6,100)'% CGHSGO: starting: ',nx,ny,nz
461 100 format(a,(2x,' [',i3,',',i3,',',i3,'] '))
462 endif
463 c*
464 c* *** initial wall clock ***
465 call prtini(istop)
466 call prtstp(iok,-1,0.0d0,0.0d0,0.0d0)
467 c*
468 c* **************************************************************
469 c* *** note: if (iok.ne.0) then: use a stopping test. ***
470 c* *** else: use just the itmax to stop iteration. ***
471 c* **************************************************************
472 c* *** istop=0 most efficient (whatever it is) ***
473 c* *** istop=1 relative residual ***
474 c* *** istop=2 rms difference of successive iterates ***
475 c* *** istop=3 relative true error (provided for testing) ***
476 c* **************************************************************
477 c*
478 c* *** compute denominator for stopping criterion ***
479 if (istop .eq. 0) then
480 rsden = 1.0d0
481 elseif (istop .eq. 1) then
482 rsden = xnrm1(nx,ny,nz,fc)
483 elseif (istop .eq. 2) then
484 rsden = dsqrt(dble((nx-2)*(ny-2)*(nz-2)))
485 elseif (istop .eq. 3) then
486 rsden = xnrm2(nx,ny,nz,tru)
487 elseif (istop .eq. 4) then
488 rsden = xnrm2(nx,ny,nz,tru)
489 elseif (istop .eq. 5) then
490 call matvec(nx,ny,nz,ipc,rpc,ac,cc,tru,r)
491 rsden = dsqrt(xdot(nx,ny,nz,tru,r))
492 else
493 print*,'% CGHSGO: bad istop value... '
494 endif
495 if (rsden.eq.0.0d0) then
496 rsden = 1.0d0
497 print*,'% CGHSGO: rhs is zero '
498 endif
499 rsnrm = rsden
500 orsnrm = rsnrm
501 call prtstp (iok,0,rsnrm,rsden,orsnrm)
502 c*
503 c* *** now compute residual with the initial guess ***
504 call mresid(nx,ny,nz,ipc,rpc,ac,cc,fc,x,r)
505 c*
506 c* *** setup for the looping ***
507 iters = 0
508 30 continue
509 c*
510 c* *** save iterate if stop test will use it on next iter ***
511 if (istop .eq. 2) call xcopy(nx,ny,nz,x,tru)
512 c*
513 c* *** form new direction vector from old one and residual ***
514 rhok2 = xdot(nx,ny,nz,r,r)
515 if (iters .eq. 0) then
516 call xcopy(nx,ny,nz,r,p)
517 else
518 beta = rhok2 / rhok1
519 call xaxpy(nx,ny,nz,((1.0d0)/beta),r,p)
520 call xscal(nx,ny,nz,beta,p)
521 endif
522 c*
523 c* *** linear case: alpha which minimizes energy norm of error ***
524 call matvec(nx,ny,nz,ipc,rpc,ac,cc,p,ap)
525 pAp = xdot(nx,ny,nz,p,ap)
526 alpha = rhok2 / pAp
527 c*
528 c* *** save rhok2 for next iteration ***
529 rhok1 = rhok2
530 c*
531 c* *** update solution in direction p of length alpha ***
532 call xaxpy(nx,ny,nz,alpha,p,x)
533 c*
534 c* *** update residual ***
535 call xaxpy(nx,ny,nz,(-alpha),ap,r)
536 c*
537 c* *** some bookkeeping ***
538 iters = iters + 1
539 c*
540 c* *** compute/check the current stopping test ***
541 orsnrm = rsnrm
542 if (istop .eq. 0) then
543 rsnrm = xnrm1(nx,ny,nz,r)
544 elseif (istop .eq. 1) then
545 rsnrm = xnrm1(nx,ny,nz,r)
546 elseif (istop .eq. 2) then
547 call xcopy(nx,ny,nz,tru,tmp)
548 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
549 rsnrm = xnrm1(nx,ny,nz,tmp)
550 elseif (istop .eq. 3) then
551 call xcopy(nx,ny,nz,tru,tmp)
552 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
553 rsnrm = xnrm2(nx,ny,nz,tmp)
554 elseif (istop .eq. 4) then
555 call xcopy(nx,ny,nz,tru,tmp)
556 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
557 rsnrm = xnrm2(nx,ny,nz,tmp)
558 elseif (istop .eq. 5) then
559 call xcopy(nx,ny,nz,tru,tmp)
560 call xaxpy(nx,ny,nz,(-1.0d0),x,tmp)
561 call matvec(nx,ny,nz,ipc,rpc,ac,cc,tmp,zk)
562 rsnrm = dsqrt(xdot(nx,ny,nz,tmp,zk))
563 else
564 print*,'% CGHSGO: bad istop value... '
565 endif
566 call prtstp (iok,iters,rsnrm,rsden,orsnrm)
567 if ((rsnrm/rsden) .le. errtol) goto 99
568 if (iters .ge. itmax) goto 99
569 goto 30
570 c*
571 c* *** return and end ***
572 99 continue
573 return
574 end