---
title: 迁移步骤
description: "1. 迁移前（调用PARDISO）。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_12_0073.html
sourcePath: /source/zh/kunpengaccel/math-lib/devg-kml/kunpengaccel_12_0073.html
indexId: 70f2e580419945b0d9cf44afa9eee144c9da993a60da336c9ab066b25035aa2167
---
# 迁移步骤

#### C语言迁移步骤

1. 迁移前（调用PARDISO）。
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 int n = 8; int nnz = 17; int ia[9] = {0, 3, 7, 9, 11, 13, 15, 16, 17}; int ja[17] = {0, 3, 4, 1, 2, 3, 5, 2, 7, 3, 6, 4, 5, 5, 7, 6, 7}; 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 nrhs = 1; // Number of right hand sides. double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0}; double x[8]; int mtype = 2; void *pt[64]; int iparm[64]; int maxfct, mnum, phase, error, msglvl, perm; pardisoinit(pt, &mtype, iparm); iparm[34] = 1; maxfct = 1; // Maximum number of numerical factorizations. mnum = 1; // Which factorization to use. msglvl = 0; // Print statistical information in file. error = 0; // Initialize error flag. phase = 11; pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Analyze printf ("Reordering completed ... "); phase = 22; pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Factorize printf ("\nFactorization completed ... "); phase = 33; pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Solve printf("\nSolve completed ... "); printf("\nThe solution of the system is: "); for(int i = 0; i < n; i++){ printf ("\n x [%d] = % f", i, x[i]); } printf("\n"); phase = -1; // Release internal memory. pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error);

  迁移前（调用PARDISO-Cluster）。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 int n = 8; int nnz = 17; int ia[9] = {0, 3, 7, 9, 11, 13, 15, 16, 17}; int ja[17] = {0, 3, 4, 1, 2, 3, 5, 2, 7, 3, 6, 4, 5, 5, 7, 6, 7}; 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}; /* RHS and solution vectors. */ int nrhs = 1; /* Number of right hand sides. */ double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0}; double x[8]; int mtype = 2; void *pt[64]; int iparm[64]; int maxfct, mnum, phase, error, msglvl, perm; for (int i = 0; i < 64; i++) { iparm[i] = 0; pt[i] = 0; } iparm[0] = 1; iparm[1] = 2; iparm[17] = -1; iparm[18] = -1; iparm[34] = 1; maxfct = 1; // Maximum number of numerical factorizations. mnum = 1; // Which factorization to use. msglvl = 0; // Print statistical information in file. error = 0; // Initialize error flag. MPI_Init(NULL, NULL); int size, rank; MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Fint comm = MPI_Comm_c2f(MPI_COMM_WORLD); phase = 11; cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Analyze phase = 22; cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Factorize phase = 33; cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Solve if (rank == 0){ printf("The solution of the system is: "); for(int i = 0; i < n; i++){ printf ("\n x [%d] = % f", i, x[i]); } printf("\n"); } phase = -1; // Release internal memory. cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); MPI_Finalize();

  迁移后： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 int n = 8; int ia[9] = {0, 3, 7, 9, 11, 13, 15, 16, 17}; int ja[17] = {0, 3, 4, 1, 2, 3, 5, 2, 7, 3, 6, 4, 5, 5, 7, 6, 7}; 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}; MPI_Init(NULL, NULL); int size, rank; MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); KmlScasolverTask* matrix_handle = NULL; int ierr = KmlScadssSpdInitDI(&matrix_handle, n, a, ja, ia, MPI_COMM_WORLD); //Init if (ierr != 0) { printf("\nERROR in KmlScadssSpdInitDI: %d", ierr); } ierr = KmlScadssSpdAnalyzeDI(&matrix_handle); //Analyze phase if (ierr != 0) { printf("\nERROR in KmlScadssSpdAnalyzeDI: %d", ierr); } ierr = KmlScadssSpdFactorizeDI(&matrix_handle); //Factorize phase if (ierr != 0) { printf("\nERROR in KmlScadssSpdFactorizeDI: %d", ierr); } int nrhs = 1; int ldx=n, ldb=n; double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0}; double x[8]; ierr = KmlScadssSpdSolveDI(&matrix_handle, nrhs, x, ldx, b, ldb); //Solve phase if (ierr != 0) { printf("\nERROR in KmlScadssSpdSolveDI: %d", ierr); } ierr = KmlScadssSpdCleanDI(&matrix_handle); //clean if (ierr != 0) { printf("\nERROR in KmlScadssSpdcleanDI: %d", ierr); } MPI_Finalize();

2. 头文件
  迁移前（PARDISO）：

  #include "mkl_types.h"

  #include "mkl_cluster_sparse_solver.h"

  迁移前（PARDISO-Cluster）：

  #include "mkl_pardiso.h"

  #include "mkl_types.h"

  迁移后：

  #include "kml_scadss.h

3. 编译链接库。
  替换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。
