Rate This Document
Findability
Accuracy
Completeness
Readability

Migrating a Linear Algebra Operation Library (LAPACK)

Replaceability

The external interfaces provided by KML_LAPACK are the same as those provided by MKL_LAPACK in terms of interface parameters and function names, and can be directly replaced.

Table 1 describes the mapping between alternative interfaces and Fortran interfaces of MKL_LAPACK. Only optimized interfaces are provided.

Table 1 LAPACK replacement mapping

MKL Interface

KML Interface

Data Type

Description

?getrf

?getrf

s, d, c, z

Computes the LU factorization of matrix A.

?geqrf

?geqrf

s, d, c, z

Computes the QR factorization of a matrix.

?gerqf

?gerqf

s, d, c, z

Computes the RQ factorization of a matrix.

?geqlf

?geqlf

s, d, c, z

Computes the QL factorization of a matrix.

?gelqf

?gelqf

s, d, c, z

Computes the LQ factorization of a matrix.

?ppsv

?ppsv

s, d, c, z

Computes the Cholesky factorization of matrix A and solves a system of linear equations based on the factorization result.

?ptsv

?ptsv

s, d, c, z

Solves a system of linear equations, in which the coefficient matrix A is a conjugate symmetric positive definite tridiagonal matrix.

?getri

?getri

s, d, c, z

Computes the inverse matrix based on the LU factorization result obtained using ?getrf.

?syevd

?syevd

s, d

Computes all the eigenvalues and eigenvectors of a symmetric (Hermitian) matrix.

?heevd

?heevd

c, z

Computes all the eigenvalues and eigenvectors of a symmetric (Hermitian) matrix.

?sytrd

?sytrd

s, d

Transforms a symmetric matrix to a symmetric tridiagonal matrix by means of similarity transformation.

?hetrd

?hetrd

c, z

Transforms a Hermitian matrix to a symmetric tridiagonal matrix by means of similarity transformation.

?potrf

?potrf

s, d, c, z

Computes the Cholesky factorization of a symmetric positive definite matrix or Hermitian positive definite matrix.

?pttrf

?pttrf

s, d, c, z

Computes the LDL* or U*DU factorization of a real (conjugate) symmetric positive definite tridiagonal matrix A

?potri

?potri

s, d, c, z

Computes the inverse of a symmetric positive definite matrix.

?gesv

?gesv

s, d, c, z

Solves a system of linear equations , where is an matrix. and are matrices.

?orglq

?orglq

s, d

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?unglq

?unglq

c, z

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?ormlq

?ormlq

s, d

Computes or , where Q is returned by calling ?gelqf.

?unmlq

?unmlq

c, z

Computes or , where Q is returned by calling ?gelqf.

?orgql

?orgql

s, d

Generates a real or complex matrix Q with orthonormal columns. The matrix is defined as the first N columns of the product of K M-order elementary reflectors.

?ungql

?ungql

c, z

Generates a real or complex matrix Q with orthonormal columns. The matrix is defined as the first N columns of the product of K M-order elementary reflectors.

?ormql

?ormql

s, d

Computes or , where Q is returned by calling ?geqlf.

?unmql

?unmql

c, z

Computes or , where Q is returned by calling ?geqlf.

?orgqr

?orgqr

s, d

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?ungqr

?ungqr

c, z

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?orgrq

?orgrq

s, d

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?ungrq

?ungrq

c, z

Generates a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors.

?ormrq

?ormrq

s, d

Computes or , where Q is returned by calling ?gerqf.

?unmrq

?unmrq

c, z

Computes or , where Q is returned by calling ?gerqf.

?ormqr

?ormqr

s, d

Computes or , where Q is returned by calling ?geqrf.

?unmqr

?unmqr

c, z

Computes or , where Q is returned by calling ?geqrf.

?syev

?syev

s, d

Computes all the eigenvalues and eigenvectors of a symmetric (Hermitian) matrix.

?heev

?heev

c, z

Computes all the eigenvalues and eigenvectors of a symmetric (Hermitian) matrix.

?pttrs

?pttrs

s, d, c, z

Solves the tridiagonal equation AX = B, where the coefficient matrix A is the ?pttrf factorization result.

?ptts2

?ptts2

s, d, c, z

Solves the tridiagonal equation AX = B, where the coefficient matrix A is the ?pttrf factorization result.

?lasr

?lasr

s, d, c, z

Performs a plane rotation operation on matrix A.

?gtsv

?gtsv

s, d, c, z

Solves the system of linear equations A * X = B, where A is a general tridiagonal coefficient matrix.

?gttrf

?gttrf

s, d, c, z

Computes the LU factorization of general tridiagonal matrix A.

?gttrs

?gttrs

s, d, c, z

Solves the tridiagonal equation A * X = B, AT * X = B, or AH * X = B, where coefficient matrix A is the ?gttrf factorization result.

?sytrd_2stage

?sytrd_2stage

s, d, c, z

Transforms a symmetric or Hermitian matrix A to a symmetric or Hermitian tridiagonal matrix T.

?trtrs

?trtrs

s, d, c, z

Solves the trigonometric equation A * X = B or AT * X = B.

?laset

?laset

s, d, c, z

Initializes an m * n matrix and sets the diagonal elements to beta and the non-diagonal elements to alpha.

?sptrf

?sptrf

s, d, c, z

Computes the LDL* or U*DU factorization of a packed symmetric matrix.

?hptrf

?hptrf

s, d, c, z

Computes the LDL* or U*DU factorization of a packed Hermitian matrix.

?pptrf

?pptrf

s, d, c, z

Computes the LLT or UTU factorization of a symmetric positive definite matrix in packed format.

?pptrs

?pptrs

s, d, c, z

Solves the tridiagonal equation A * X = B, AT * X = B, or AH * X = B. The coefficient matrix A is obtained by calling ?gttrf.

?pptri

?pptri

s, d, c, z

Computes the inverse matrix of a symmetric positive definite matrix stored in packed format.

?getrs

?getrs

s, d, c, z

Solves the general linear equation A * X = B, AT * X = B, or AH * X = B. The coefficient matrix A is obtained by calling ?getrf.

?posv

?posv

s, d, c, z

Solves the system of linear equations , where A is an positive definite matrix of real symmetry or conjugate symmetry, and X and B are matrices.

?trtri

?trtri

s, d, c, z

Computes the inverse matrix of an upper/lower triangular matrix.

?laswp

?laswp

s, d, c, z

Performs a series of row exchange operations on a matrix.

?lascl

?lascl

s, d, c, z

Performs scalar operations on a matrix.

?lange

?lange

s, d, c, z

Computes the norms of a matrix, including 1-norm, F-norm, and infinite norm.

?sgesv

?gesv

ds, zc

Solves a system of linear equations , where is an matrix. and are matrices.

?gels

?gels

s, d, c, z

Uses QR or LQ factorization to solve an overdetermined or underdetermined linear system with full rank matrix.

?gelsd

?gelsd

s, d, c, z

Computes the minimum-norm solution to a linear least squares problem using a divide and conquer method.

?gelss

?gelss

s, d, c, z

Computes the minimum-norm solution to a linear least squares problem using SVD.

?steqr

?steqr

s, d, c, z

Computes the eigenvalues and eigenvectors of a symmetric tridiagonal matrix through QL or QR factorization.

?gtts2

?gtts2

s, d, c, z

Solves the tridiagonal equation A * X = B, AT * X = B, or AH * X = B, where coefficient matrix A is the ?gttrf factorization result.

?ormbr

?ormbr

s, d

Computes C = Q * C, QT * C, C * Q, C * QT, C = P * C, PT * C, C * P, or C * PT.

?unmbr

?unmbr

c, z

Computes C = Q * C, QT * C, C * Q, C * QT, C = P * C, PT * C, C * P, or C * PT.

?orgtr

?orgtr

s, d

Generates an orthogonal matrix Q through reflector factors computed by a call to SYTRD.

?ungtr

?ungtr

c, z

Generates an orthogonal matrix Q through reflector factors computed by a call to SYTRD.

?lacpy

?lacpy

s, d, c, z

Copies all or some elements of matrix A to matrix B.

?stedc

?stedc

s, d, c, z

Computes the eigenvalues of a symmetric tridiagonal matrix using the Divide-and-Conquer algorithm.

?gesvd

?gesvd

s, d, c, z

Performs singular value decomposition (SVD) on a general matrix.

?gebrd

?gebrd

s, d, c, z

Transforms a general matrix to a bidiagonal matrix.

?bdsdc

?bdsdc

s, d

Computes SVD of an N*N upper/lower bidiagonal matrix B using a divide and conquer algorithm.

?gesdd

?gesdd

s, d, c, z

Computes SVD of a rectangular matrix using a divide and conquer algorithm to compute left and right singular vectors.

?bdsqr

?bdsqr

s, d, c, z

Solves singular values or left and right singular vectors using SVD of the QR algorithm for a bidiagonal matrix.

The preceding interfaces are Fortran interfaces. When using them in the C language, add an underscore (_) to the end of the interface name, and ensure that the parameter type is pointer. For details, see "Kunpeng Math Library Developer Guide" > "Applied Math Libraries" > "KML_LAPACK Library Functions" > "Function Syntax" in Kunpeng HPCKit 26.1.RC1 Developer Guide.

To use the LAPACKE interfaces (standard C interfaces in MKL), you need to add the compilation of the LAPACKE encapsulation library when compiling the open-source Netlib LAPACK. For details, see Migrating the C-based Library.

Migrating the C-based Library

  1. MKL_LAPACK provides Fortran and LAPACK (encapsulated in the C language) interfaces. The Fortran interfaces provided by KML_LAPACK are the same as those provided by MKL. When the C language is used, replace the header file #include "mkl.h" with #include "klapack.h".

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 MKL, the C function declaration of the Fortran interface can be obtained by including klapack.h.

Migrating the Fortran-based Library

The Fortran interfaces are the same as those of MKL. The code does not need to be modified.