I use gcc to compile under mac os x, I have Intel's mkl_lapack.h library installed. In the program I have a NxN tridiagonal matrix, so I just use two vectors to store values of the matrix. "d" vector is the main diagonal, the values of subdiagonals are stored in "e". First of all I initialize values, then since the matrix is 16x16 (in input I'm giving the value 16 as argv[1]), I split the vector into two vectors (I could just use dstev once for all, but it's for experimental purposes), from d[0] to d[N/2-1] I have the first vector, from d[N/2] to d[N-1] the second one. So once initilized the values of "e" and "d" , I call two times dstev. But I don't bother writing all the values in "z" (z will contain eigenvectors), because I know that after calling dstev two times, in all the "z" vector I should have only two submatrixes of values, 8x8 of non-zero values. But if I try priting "z", some values are 0.0, and I can't explain why this happens.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <mpi.h>
#include "mkl_lapack.h"
int main(int argc, char **argv)
{
int N,dim,info;
double *d,*e,*z,*work;
char jobz='V';
switch(argc)
{
case 2:
N=atoi(argv[1]);
break;
default:
fprintf(stderr,"Errore nell' inserimento degli argomenti\n");
exit(EXIT_FAILURE);
break;
}
if(N%2!=0)
{
fprintf(stderr,"La dimensione della matrice deve essere pari\n");
exit(EXIT_FAILURE);
}
dim=N/2;
d=(double*)malloc(N*sizeof(double));
e=(double*)malloc((N-1)*sizeof(double));
z=(double*)malloc(N*N/2*sizeof(double));
work=(double*)malloc((N-1)*2*sizeof(double));
for(int i=0;i<N-1;i++)
{
d[i]=(double)(i+3);
e[i]=1.0;
}
dstev(&jobz,&dim,d,e,z,&dim,work,&info);
dim--;
dstev(&jobz,&dim,&d[N/2],&e[N/2],&z[N*N/4],&dim,&work[N-1],&info);
for(int i=0;i<(N*N/2);i++)
printf("(%f) ",z[i]);
return 0;
}
I hope I explained this thing clearly, let me know is something isn't clear.