# dcg

Computes the approximate solution vector.

## Syntax

dcg(n, x, b, RCI_request, ipar, dpar, tmp)

## Description

The routine dcg computes the approximate solution vector using the CG method [Young71]. , The routine dcg uses the value that was in the vector x before the first call as an initial approximation to the solution. The parameter RCI_request informs the user about the task completion and requests results of certain operations that are required by the solver.

Note that lengths of all vectors are assumed to have been defined in a previous call to the dcg_init routine.

## Input Parameters

n

  INTEGER. Contains the size of the problem, and size of arrays x and b.

x

  DOUBLE PRECISION array of size n. Contains the initial approximation to the solution vector.

b

  DOUBLE PRECISION array of size n. Contains the right-hand side vector.

tmp

  DOUBLE PRECISION array of size (n,4). Refer to the CG Common Parameters.

## Output Parameters

RCI_request

  INTEGER. Informs about result of work of the routine.

x

  DOUBLE PRECISION array of size n. Contains the updated approximation to the solution vector.

ipar

  INTEGER array of size 128. Refer to the CG Common Parameters.

dpar

  DOUBLE PRECISION array of size 128. Refer to the CG Common Parameters.

tmp

  DOUBLE PRECISION array of size `(n,4)`. Refer to the CG Common Parameters.

## Return Values

RCI_request=0

  The routine completes task normally, the solution is found and stored in the vector x. This occurs only if the stopping tests are fully automatic. For the user defined stopping tests, see the comments to the RCI_request= 2.

RCI_request=-1

  The routine is interrupted because the maximal number of iterations is reached, but the relative stopping criterion is not met - this situation occurs only if both tests are requested by the user.

RCI_request=-2

  The routine is interrupted because attempt to divide by zero occurs. This situation happens if the matrix is (almost) non-positive definite.

RCI_request=- 10

  The routine is interrupted because the residual norm is invalid. Probably, the value dpar(6) was altered outside of the routine, or the dcg_check routine was not called.

RCI_request=-11

  The routine is interrupted because it enters the infinite cycle. Probably, the values ipar(8), ipar(9), ipar(10) were altered outside of the routine, or the dcg_check routine was not called.

RCI_request= 1

  Requests the user to multiply the matrix by tmp(1:n,1), put the result in the tmp(1:n,2), and return the control back to the routine dcg.

RCI_request= 2

  Requests the user to perform the stopping tests. If they fail, the control must be returned back to the dcg routine. Otherwise, the solution is found and stored in the vector x.

RCI_request= 3

  Requests the user to apply the preconditioner to `tmp(:, 3)`, put the result in the `tmp(:, 4)`, and return the control back to the routine dcg.

Parent topic: Iterative Sparse Solvers based on Reverse Communication Interface (RCI ISS)