Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Eigenvalue routine heevr goes wrong very weirdly

kingking_r_
Beginner
512 Views

I am trying to make use of the official example code of heevr routine in LAPACK. Once I changed the range parameter from 'V' to 'A' and commented out il and iu, the first two eigenvalues wrongly showed zero. Below is my tinily modified example code. I used icpc 13.1.3 and run in Linux. Thanks in advance.

#include <stdlib.h>
#include <stdio.h>
#include "mkl_lapacke.h"

/* Auxiliary routines prototypes */
extern void print_matrix( char* desc, MKL_INT m, MKL_INT n, MKL_Complex16* a, MKL_INT lda );
extern void print_rmatrix( char* desc, MKL_INT m, MKL_INT n, double* a, MKL_INT lda );

/* Parameters */
#define N 4
#define LDA N
#define LDZ N

/* Main program */
int main() {
        /* Locals */
        MKL_INT n = N, lda = LDA, ldz = LDZ, il, iu, m, info;
        double abstol, vl, vu;
        /* Local arrays */
        MKL_INT isuppz;
        double w;
        MKL_Complex16 z[LDZ*N];
        MKL_Complex16 a[LDA*N] = {
           {-2.16,  0.00}, {-0.16,  4.86}, {-7.23,  9.38}, {-0.04, -6.86},
           { 0.00,  0.00}, { 7.45,  0.00}, { 4.39, -6.29}, {-8.11,  4.41},
           { 0.00,  0.00}, { 0.00,  0.00}, {-9.03,  0.00}, {-6.89,  7.66},
           { 0.00,  0.00}, { 0.00,  0.00}, { 0.00,  0.00}, { 7.76,  0.00}
        };
        /* Executable statements */
        printf( "LAPACKE_zheevr (column-major, high-level) Example Program Results\n" );
        /* Negative abstol means using the default value */
        abstol = -1.0;
        /* Set VL, VU to compute eigenvalues in half-open (VL,VU] interval */
        //vl = -5.0;
        //vu = 5.0;
        /* Solve eigenproblem */
        info = LAPACKE_zheevr( LAPACK_COL_MAJOR, 'V', 'A', 'L', n, a, lda,
                        vl, vu, il, iu, abstol, &m, w, z, ldz, isuppz );
        /* Check for convergence */
        if( info > 0 ) {
                printf( "The algorithm failed to compute eigenvalues.\n" );
                exit( 1 );
        }
        /* Print the number of eigenvalues found */
        printf( "\n The total number of eigenvalues found:%2i\n", m );
        /* Print eigenvalues */
        print_rmatrix( "Selected eigenvalues", 1, m, w, 1 );
        /* Print eigenvectors */
        print_matrix( "Selected eigenvectors (stored columnwise)", n, m, z, ldz );
        exit( 0 );
} /* End of LAPACKE_zheevr Example */

/* Auxiliary routine: printing a matrix */
void print_matrix( char* desc, MKL_INT m, MKL_INT n, MKL_Complex16* a, MKL_INT lda ) {
        MKL_INT i, j;
        printf( "\n %s\n", desc );
        for( i = 0; i < m; i++ ) {
                for( j = 0; j < n; j++ )
                        printf( " (%6.2f,%6.2f)", a[i+j*lda].real, a[i+j*lda].imag );
                printf( "\n" );
        }
}

/* Auxiliary routine: printing a real matrix */
void print_rmatrix( char* desc, MKL_INT m, MKL_INT n, double* a, MKL_INT lda ) {
        MKL_INT i, j;
        printf( "\n %s\n", desc );
        for( i = 0; i < m; i++ ) {
                for( j = 0; j < n; j++ ) printf( " %6.2f", a[i+j*lda] );
                printf( "\n" );
        }
}

0 Kudos
3 Replies
Gennady_F_Intel
Moderator
512 Views

it looks like the issue with this function. Could you please try LAPACKE_zheevd instead of this. We will fix this problem and keep you informed with the status. zheevd returned  -20.958232, -4.178050, 3.566461, 25.589821 with this case.

0 Kudos
kingking_r_
Beginner
512 Views

Gennady Fedorov (Intel) wrote:

it looks like the issue with this function. Could you please try LAPACKE_zheevd instead of this. We will fix this problem and keep you informed with the status. zheevd returned  -20.958232, -4.178050, 3.566461, 25.589821 with this case.

Thanks for your reply. Besides that, I also found other strange behavior of zheevr when you use std::complex<double> (0,0) to initialize your matrix...

Could you please provide any info of heev? I can't find its algorithm in the manual. How is it compared with heevd?
 

0 Kudos
Gennady_F_Intel
Moderator
512 Views

we have found out the cause of the problem - actually pls allocate the array isuppz[2*N] and issue will disappear. pls see at the description of this parameter :  isuppz  Array, size at least 2 *max(1, m).......

0 Kudos
Reply