module cgmeth {
  use matmult
  use cgstep_mod
  use solver_tiny_mod
contains
  # setup of conjugate gradient descent, minimize  SUM rr(i)**2
  #             nx
  # rr(i)  =   sum fff(i,j) * x(j)  -  yy(i) 
  #            j=1
  subroutine cgtest( x, yy, rr, fff, niter) {
    real, dimension (:), intent (out) :: x, rr
    real, dimension (:), intent (in)  :: yy
    real, dimension (:,:), pointer    :: fff
    integer,             intent (in)  :: niter
    call matmult_init( fff)
    call solver_tiny( m=x, d=yy, &
	Fop=matmult_lop, stepper=cgstep, &
	niter=niter, resd=rr)
    call cgstep_close ()
  }
}
