Migrating the Library That Uses the C Language
- MKL LAPACK provides the Fortran and LAPACKE (C language encapsulation) interfaces. The Fortran interface provided by KML LAPACK is the same as that provided by the MKL. When the C language is used, replace the header file #include "mkl.h" with #include "klapack.h".
- When compiling links, replace the link options related to MKL. For details, see "Installing the KML_LAPACK > Verifying the Installation" in Kunpeng Math Library Developer Guide.
Example
Use the Fortran interface before the migration:
/* Declare the dgetrf interface */
void dgetrf_(int *m, int *n, double *a, int *lda, int *ipiv, int *info);
......
int m = 4;
int n = 4;
int lda = 4;
int ipiv[4];
int info = 0;
double a[] = {1.80, 5.25, 1.58, -1.11,
2.88, -2.95, -2.69, -0.66,
2.05, -0.95, -2.90, -0.59,
-0.89, -3.80, -1.04, 0.80};
dgetrf_(&m, &n, a, &lda, ipiv, &info);
Use the LAPACKE interface before the migration:
#include "mkl.h"
......
int m = 4;
int n = 4;
int lda = 4;
int ipiv[4];
double a[] = {1.80, 5.25, 1.58, -1.11,
2.88, -2.95, -2.69, -0.66,
2.05, -0.95, -2.90, -0.59,
-0.89, -3.80, -1.04, 0.80};
int info = LAPACKE_dgetrf(LAPACK_COL_MAJOR, m, n, a, lda, ipiv);
Use the Fortran interface of KML LAPACK after the migration:
#include "klapack.h"
......
int m = 4;
int n = 4;
int lda = 4;
int ipiv[4];
int info = 0;
double a[] = {1.80, 5.25, 1.58, -1.11,
2.88, -2.95, -2.69, -0.66,
2.05, -0.95, -2.90, -0.59,
-0.89, -3.80, -1.04, 0.80};
dgetrf_(&m, &n, a, &lda, ipiv, &info);
Similar to the Fortran interface of the MKL, the C function declaration of the Fortran interface can be obtained by including klapack.h.
If the LAPACKE interface needs to be used after the migration, compile LAPACKE when compiling Netlib LAPACK. That is, add -DLAPACKE=ON after the cmake command in the step of installing the KML_LAPACK to compile the original Netlib LAPACK library.
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLAPACKE=ON
After LAPACK compilation, liblapacke.a is generated. During application compilation, you need to add the paths of the LAPAKE header file and LAPACKE library.
gcc app.c -o app -fopenmp -I /data/lapack-3.9.1/LAPACKE/include -I $KML_LAPACK_ROOT/include -L $KML_LAPACK_ROOT/lib64 -l:liblapacke.a -l:libklapack.a -L $ADAPT_ROOT -l:liblapack_adapt.a -L $KML_BLAS_ROOT -lkblas -l:libkservice.a -lgfortran -lm
Parent topic: Migrating a Linear Algebra Operation Library (LAPACK)