KmlIssCgSetUserPreconditioner?I
Associate with user-defined preconditioners for callback. This interface is not required if no user-defined preconditioner is used.
Interface Definition
C interfaces:
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 passed from a previous step. |
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 its second parameter. |
Input |
Return Value
Return Value |
Type |
Description |
|---|---|---|
KMLSS_NO_ERROR |
int |
The execution is successful. |
KMLSS_NULL_ARGUMENT |
int |
A null parameter exists in {handle, fptr}. |
Dependencies
#include "kml_iss.h"
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | class pc { public: 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 ierr; int n = 8; double a[26] = {1.0, 1.0, 2.0, 9.0, 2.0, 1.0, -3.0, 2.0, 3.0, 2.0, 1.0, 1.0, 9.0, -5.0, 2.0, 6.0, 1.0, -3.0, 1.0, 4.0, 1.0, -5.0, 7.0, 2.0,1.0, 2.0}; int ja[26] = {0, 3, 4, 1, 2, 3, 5, 1, 2, 7, 0, 1, 3, 6, 0, 4, 5, 1, 4, 5, 7, 3, 6, 2, 5, 7}; int ia[9] = {0, 3, 7, 10, 14, 17, 21, 23, 26}; pc *unstruct = new pc; 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, unstruct, mut); if (ierr != 0) { printf("\nERROR in KmlIssCgSetUserPreconditionerDI: %d", ierr); return 1; } |