Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

Eigenvalue routine heevr goes wrong very weirdly

$
0
0

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[N];
        double w[N];
        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" );
        }
}


Viewing all articles
Browse latest Browse all 2652

Trending Articles



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