---
title: 迁移步骤
description: "MKL提供了C接口，KML_SOLVER同样提供了C接口，但接口名及接收参数不一致，需要进行对应功能的切换。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_12_0048.html
sourcePath: /source/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_12_0048.html
indexId: 7d41f3fdf9ddc3bb29d14530c021fb171109e87d8437265f8802a3fc17378c0967
---
# 迁移步骤

#### C语言迁移步骤

MKL提供了C接口，KML_SOLVER同样提供了C接口，但接口名及接收参数不一致，需要进行对应功能的切换。

1. 初始化。
  迁移前： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 const MKL_INT n = 8; MKL_INT ia[9]; MKL_INT ja[18]; double a[18]; MKL_INT rci_request; double rhs[8] = {0.0}; double solution[8] = {0.0}; double expected_sol[8]; MKL_INT ipar[128]; double dpar[128], tmp[4 * 8] = {0.0}; sparse_matrix_t csrA; struct matrix_descr descrA; sparse_operation_t transA; ...... mkl_sparse_d_create_csr ( &csrA, SPARSE_INDEX_BASE_ONE, n, n, ia, ia+1, ja, a ); mkl_sparse_d_mv( transA, 1.0, csrA, descrA, expected_sol, 0.0, rhs); dcg_init (&n, solution, rhs, &rci_request, ipar, dpar, tmp);

  迁移后： 1 2 3 4 5 6 int n = 8; int ia[9]; int ja[17]; double a[17]; void* handle; int error = KmlIssCgInitDI(&handle, &n, a, ja, ia);

2. 求解。
  迁移前： 1 dcg (&n, solution, rhs, &rci_request, ipar, dpar, tmp);

  迁移后： 1 2 3 4 5 6 double b[8]; /* Solution vector */ double x[8]; int nrhs = 1;/* Number of right-hand sides */ int ldx=n, ldb=n;/*!Leading dimension of B and X */ int error = KmlIssCgSolveDI(&handle, &nrhs, x, &ldx, b, &ldb);

3. 获取迭代参数。
  迁移前： 1 2 MKL_INT itercount dcg_get (&n, solution, rhs, &rci_request, ipar, dpar, tmp, &itercount);

  迁移后： 1 2 3 int *data; // user data. int nd = 1; int error = KmlIssCgGetDII(&handle, ITERATION_COUNT, data, nd);

4. 清除。
  迁移前： 1 mkl_sparse_destroy(csrA);

  迁移后： 1 KmlIssCgCleanDI(&handle);

5. 头文件。
  迁移前：

  #include "mkl_rci.h"

  #include "mkl_spblas.h"

  #include "mkl_service.h"

  迁移后：

  #include "kml_iss.h"

6. 编译链接库。
  替换MKL相关的链接选项， 具体选项请参见《鲲鹏数学库 开发指南(https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_kml_16_0011.html)》中的“安装KML”章节。《Kunpeng HPCKit 24.0.0 安装指南》(https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/instg/KunpengHPCKit_install_004.html)安装KML。
