I need to find eigenvalue and eigenvector of a general nonsymmetric matrix.It compiles alright but gives segmentation fault when i run the program
The relevant portion of the code is as follows:
- Code: Select all
extern void dgeev_(char *JOBVL,char *JOBVR,int *N,double *A,int *LDA,double *WR,double *WI,double *VL,int *LDVL,double *VR,int *LDVR,double *WORK,int *LWORK,int *INFO);
int find_eigenvectors(double *mat)
{
int i,j,k;
char JOBVL='V';
char JOBVR='N';
int N;
int LDA=num_points;
int LDZ;
int LWORK=-1;
int LDVL,LDVR;
int INFO;
int LDB;
int ITYPE=3;
int *IWORK;
int *IFAIL;
double WR[num_points];
double WI[num_points];
double *VL;
double *VR;
double *WORK;
double *A;
printf("num_points->%d\n",num_points);
k=1;
A=mat;
/*A=(double*)malloc((num_points*num_points+1)*sizeof(double));
if(A==NULL)
{
printf("Error with allocating memory for A\n");
exit(0);
}
for(j=0;j<num_points;j++)
for(i=0;i<num_points;i++)
A[k++]=mat[i][j];
*/
N=num_points;
printf("N-->%d\n",N);
LDVL=num_points+1;
LDVR=num_points+1;
WORK=(double*)malloc(sizeof(double));
if(WORK==NULL)
{
printf("ERROR allocating memory for work\n");
exit(0);
}
VR=(double*)malloc(LDVR*N*sizeof(double*));
if(VR==NULL)
{
printf("ERROR allocating memory for VR\n");
exit(0);
}
/*for(i=0 ; i<num_points ; i++)
{
VR[i]=(double*)malloc(num_points*sizeof(double));
if(VR[i]==NULL)
{
printf("ERROR allocating memory for VR[%d]\n",i);
exit(0);
}
}
*/
VL=(double*)malloc(LDVR*N*sizeof(double*));
if(VL==NULL)
{
printf("ERROR allocating memory for VL\n");
exit(0);
}
/*for(i=0 ; i<num_points ; i++)
{
VL[i]=(double*)malloc(num_points*sizeof(double));
if(VL==NULL)
{
printf("ERROR allocating memory for VL[%d]\n",i);
exit(0);
}
}
*/
printf("calling lapack function\n");
//SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,
// LDVR, WORK, LWORK, INFO )
dgeev_( &JOBVL, &JOBVR, &N, A, &LDA, WR, WI, VL, &LDVL, VR,&LDVR,WORK, &LWORK, &INFO);
LWORK=(int)((double)(WORK[0]));
printf("lwork-->%d\n",LWORK);
free(WORK);
scanf("%d",&i);
WORK=(double*)malloc(LWORK*sizeof(double));
if(WORK==NULL)
{
printf("ERROR allocating memory for work\n");
exit(0);
}
dgeev_( &JOBVL, &JOBVR, &N, A, &LDA, WR, WI, VL, &LDVL, VR,&LDVR,WORK, &LWORK, &INFO);
if(INFO == 0)
{
printf("the eigen vectors successfully found\n");
}
return ;
}
mat is a one dimensional array of size num_points by num_points which is thedimension of the array.
I am using debian and have blas,atlas and lapack library installed.
i am using the following command to compile the program:
- Code: Select all
cc shell_gen.c quality.c mst.c main.c eigenvector.c -llapack -lblas -lm -lg2c -o gmst
Am I doing anything wrong?
Anysort of help will be appreciated..
Thanks

