KmlIssCgSetUserPreconditioner?I

关联用户自定义预条件回调函数,如不使用自定义的预条件,该接口可以不使用。

接口定义

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));

参数

参数名

类型

描述

输入/输出

handle

KmlSolverTask **

求解器句柄,传入之前步骤的变量。

输入/输出

ustruct

void *

指向用户数据的指针,每次调用预条件子时作为第一个参数传递。

输入

(*fptr)

int

用户自定义的函数指针,指向回调函数,该回调函数进行预条件子与其第二参数间的计算。

输入

返回值

返回值

类型

描述

NO_ERROR

int

正常执行。

KML_SOLVER_INVALID_ARGUMENT

int

无效的参数。

依赖

#include "kml_iss.h"

示例

C Interface:
    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);