Migrating the Iterative Solver
Replaceability
The external interfaces provided by KML_SOLVER are different from those provided by MKL in terms of interface parameters and function names. Therefore, source code needs to be modified.
Table 1 shows the mapping relationship between alternative interfaces and MKL interfaces.
MKL Interface |
KML Interface |
|---|---|
dcg_init |
KmlIssCgInit?I |
dcg |
KmlIssCgSolve?I |
dcg_get |
KmlIssCgGet?I? |
mkl_sparse_destroy |
KmlIssCgClean?I |
The preceding interfaces are C interfaces. For details, see "Kunpeng Math Library Developer Guide" > "Applied Math Libraries" > "KML_SOLVER Library Functions" > "Function Syntax (Single-node Edition)" in Kunpeng HPCKit 26.1.RC1 Developer Guide.
Migrating the C-based Library
MKL and KML_SOLVER both provides C interfaces. However, the interface names and receiving parameters are inconsistent. Therefore, the corresponding function needs to be switched.
- InitializationBefore the migration:
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);
After the migration:1 2 3 4 5 6
int n = 8; int ia[9]; int ja[18]; double a[18]; void* handle; int error = KmlIssCgInitDI(&handle, &n, a, ja, ia);
- Finding the solution
After the migration:
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);
- Obtaining iteration parametersBefore the migration:
1 2
MKL_INT itercount dcg_get (&n, solution, rhs, &rci_request, ipar, dpar, tmp, &itercount);
After the migration:1 2 3
int *data; // user data. int nd = 1; int error = KmlIssCgGetDII(&handle, ITERATION_COUNT, data, nd);
- Clearing
After the migration:
1KmlIssCgCleanDI(&handle);
- Header files
#include "mkl_rci.h"
#include "mkl_spblas.h"
#include "mkl_service.h"
After the migration:
#include "kml_iss.h"
- Compiling the link library
Replace the link options related to MKL. For details, see "Installing KML" in Kunpeng HPCKit 26.1.RC1 Installation Guide.