KmlIssCgSetUserPreconditioner?I
Associate with user-defined preconditions for callback. This interface is not required if user-defined preconditions are not used.
Interface Definition
C interface:
int KmlIssCgSetUserPreconditionerSI(KmlSolverTask **handle, void *ustruct, int (*fptr)(void *ustruct, float *x));
int KmlIssCgSetUserPreconditionerDI(KmlSolverTask **handle, void *ustruct, int (*fptr)(void *ustruct, double *x));
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
handle |
KmlSolverTask ** |
Solver handle, which is a variable transferred previously |
Input/Output |
ustruct |
void * |
Pointer to user data. This parameter is transferred as the first parameter each time the preconditioner is called. |
Input |
(*fptr) |
int |
User-defined function pointer to the callback function. The callback function performs calculation between the preconditioner and the second parameter of the preconditioner. |
Input |
Return Value
Return Value |
Type |
Description |
|---|---|---|
NO_ERROR |
int |
The execution is successful. |
KML_SOLVER_INVALID_ARGUMENT |
int |
Invalid parameter. |
Dependencies
#include "kml_iss.h"
Examples
class pc
{
int n;
double *b;
};
int mut(void *unstruct,double *x)
{
/*
Compute the product of the precondition matrix and the vector x,
the precondition matrix is a diagonal matrix
*/
int n;
pc *a;
a = (pc *)unstruct;
n = a->n;
for(int i=0; i<n; i++){
x[i] = x[i] * a->b[i];
}
return 0;
}
KmlSolverTask *handle
int n = 8;
double a[17] = { 1.0,1.0,2.0,9.0,2.0,1.0,-3.0,3.0,2.0,9.0,-5.0,6.0,1.0,4.0,1.0,7.0,2.0 };
int ja[17] = { 0,3,4,1,2,3,5,2,7,3,6,4,5,5,7,6,7 };
int ia[9] = {0, 3, 7, 9, 11, 13, 15, 16, 17};
int ierr;
pc *unstruct = new unstr;
unstruct->b = new double [n];
for(int i=0; i<n; i++){
unstruct->b[i] = 2;
}
ierr = KmlIssCgInitDI(&handle, n, a, ja, ia);
ierr = KmlIssCgSetUserPreconditionerDI(&handle, ustruct, mut);