Migration Using C Language
Both MKL and KML_SOLVER provide the C interface, but the interface name and receiving parameters are different. The corresponding function needs to be switched.
- InitializationBefore the migration:
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:int n = 8; int ia[9]; int ja[17]; double a[17]; void* handle; int error = KmlIssCgInitDI(&handle, &n, a, ja, ia);
- Finding the solution
After the migration:
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:
MKL_INT itercount dcg_get (&n, solution, rhs, &rci_request, ipar, dpar, tmp, &itercount);
After the migration:int *data; // user data. int nd = 1; int error = KmlIssCgGetDII(&handle, ITERATION_COUNT, data, nd);
- Clear
After the migration:
KmlIssCgCleanDI(&handle);
- Header file
#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 MKL-related link options. For details, see the description about installing KML_SOLVER in Kunpeng Math Library Developer Guide.
Parent topic: Iterative Solver Migration