我要评分
获取效率
正确性
完整性
易理解

KmlIssCgSetUserPreconditioner?I

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 transfers a variable defined 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

KMLSS_NO_ERROR

int

The execution is successful.

KMLSS_NULL_ARGUMENT

int

A null argument exists in {handle, fptr}.

Dependency

#include "kml_iss.h"

Example

C interface:
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;
    }