segmentation fault with dgeev

Open discussion regarding features, bugs, issues, vendors, etc.

segmentation fault with dgeev

Postby wanderer » Wed Apr 11, 2007 6:17 pm

hi
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
wanderer
 
Posts: 1
Joined: Wed Apr 11, 2007 5:56 pm
Location: india

Postby Julien Langou » Wed Apr 11, 2007 6:43 pm

What's the complain?
Your code looks correct. I have tried it with a main file that's call it with
a random input matrix and passes num_points as a global variable.

Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>

int num_points;

int main(int argc, char ** argv) {
   double * A;
   int i,j,l;
   num_points = 200;
   A=(double*)malloc((num_points*num_points)*sizeof(double));
   l = 0;
   for (i = 0; i < num_points; i++) {
      for (j = 0; j < num_points; j++) {
         A[l] = ((double) rand()) / ((double) RAND_MAX) - 0.5 ;
         l++;   
      }
   }
   find_eigenvectors(A);
}


Works fine for me. I am using the latest LAPACK version.
Maybe you want to malloc toa llocate WR and WI ...

-j
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA


Return to User Discussion

Who is online

Users browsing this forum: Google [Bot] and 5 guests