---
title: KmlIssCgSetUserPreconditioner?I
description: "关联用户自定义预条件回调函数，如不使用自定义的预条件，该接口可以不使用。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0355.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0355.html
indexId: 99b7654e0932e7b04114f41257db3b3ef2c74619e9a5f62b19f7eea223e6df0f74
---
# 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 | 用户自定义的函数指针，指向回调函数，该回调函数进行预条件子与其第二参数间的计算。 | 输入 |


#### 返回值

| 返回值 | 类型 | 描述 |
| --- | --- | --- |
| KMLSS\_NO\_ERROR | int | 正常执行。 |
| KMLSS\_NULL\_ARGUMENT | int | {handle, fptr}中存在空参数。 |


#### 依赖

#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 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 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);
if (error != 0) {
printf("\nERROR in KmlIssCgSetUserPreconditionerDI: %d", error);
return 1;
}
```
