Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

LAPACK_zheev with matrix_layout=LAPACK_ROW_MAJOR

$
0
0

There seems to be a bug in the routine LAPACK_zheev in MKL 2019 update 3 version. This routine is used for finding eigenvectors and eigenvalues of a Hermitian matrix 'a'. Its syntax is:

lapack_int LAPACKE_zheev ( int matrix_layout , char jobz , char uplo , lapack_int n , lapack_complex_double* a , lapack_int lda , double* w );

The problem seems to occur for only "matrix_layout = LAPACK_ROW_MAJOR" argument with jobz = 'V'. The eigenvectors are outputted in 'a' by rewriting it. However, the routine rewrites only upper triangular portion of 'a' and the rest of the matrix is unchanged.

For example, the following code calculates the eigenvectors of the 2x2 Pauli matrix sigma_x.

filename: lapack_zheev

#include <iostream>
#include <complex>
#define MKL_Complex16 std::complex<double>
#include "mkl.h"
#include "mkl_types.h"

using namespace std;

int main() {
    complex<double> a[4];
    a[0] = 0;
    a[1] = 1;
    a[2] = 1;
    a[3] = 0;

    double eigs[2];

    int info = LAPACKE_zheev(LAPACK_ROW_MAJOR, 'V', 'U', 2, a, 2, eigs);

    cout << "Info = "<< info << endl;
    cout << a[0] << ""<< a[1] << endl;
    cout << a[2] << ""<< a[3] << endl;
}

I compile it with:

icpc -std=c++14 -qopenmp -DMKL_ILP64 -m64 -I${MKLROOT}/include -O3 -DNDEBUG -ansi-alias -o lapack_zheev.out lapack_zheev.cpp -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -liomp5 -lpthread -lm -ldl

./lapack_zheev.out

The output is:

Info = 0
(-0.707107,0) (0.707107,0)
(1,0) (0.707107,0)

while it is supposed to be:

Info = 0
(-0.707107,0)   (0.707107,0)
(0.707107,0)   (0.707107,0)

Replacing LAPACK_ROW_MAJOR by LAPACK_COL_MAJOR produces the correct output.


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>