---
title: 示例
description: "C Interface："
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0767.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0767.html
indexId: 00468467e4c645a75deceb27502562a46c5a29c8e60a7da5d184d15cd476c7ab76
---
# 示例

C Interface：
```
#include "kml_solver.h"
KmlSolverMatrix *handle;
int ierr;
int n = 8;
int ia[9] = {0, 3, 7, 10, 14, 17, 21, 23, 26};
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};
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};
KmlSolverMatrixStore store;
store
.indexType = KMLSS_INDEX_INT32;
store
.valueType = KMLSS_VALUE_FP64;
store
.nRow = n;
store
.nCol = n;
store
.format = KMLSS_MATRIX_STORE_CSR;
store.csr.rowOffset = ia;
store.csr.colIndex = ja;
store.csr.value = a;
KmlSolverMatrixOption opt;
opt.fieldMask = KMLSS_MATRIX_OPTION_TYPE;
opt.type = KMLSS_MATRIX_GEN;
ierr = KmlSolverMatrixCreate(&handle, &store, &opt);
if (ierr != KMLSS_NO_ERROR) {
printf("\nERROR in KmlSolverMatrixCreate: %d", ierr);
return 1;
}
double b[26] = {2.0, 2.0, 3.0, 1.0, 3.0, 5.0, -7.0, 9.0, 2.0, 1.0, 2.0, 2.0, 4.0, -3.0, 3.0, 7.0, 3.0, -8.0, 6.0, 2.0, 3.0, -7.0, 2.0, 9.0, 2.0, 6.0};
ierr = KmlSolverMatrixSetValue(handle, b);
if (ierr != KMLSS_NO_ERROR) {
printf("\nERROR in KmlSolverMatrixSetValue: %d", ierr);
return 1;
}
ierr = KmlSolverMatrixDestroy(&handle);
if (ierr != KMLSS_NO_ERROR) {
printf("\nERROR in KmlSolverMatrixDestroy: %d", ierr);
return 1;
}
```
