The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

Segmentation fault

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

Segmentation fault

Postby axelyamel » Wed Jun 18, 2008 11:35 am

Hi. this is my code:


#include "stdio.h"
#include "stdlib.h"
#include "time.h"

extern void dgesdd_ ( char *JOBZ, int *M, int *N, double *A, int *LDA,double *S, double *U, int *LDU, double
*VT, int *LDVT, double *WORK,int *LWORK, int *IWORK, int *INFO );

int main()
{
char JOBU;
int k,h,i,j,l,v,b;
int M = 10;
int N = 3;
int LWORK;
int INFO;
double a[M][N];
double s[N];
double work[56046];
int iwork[M*N];
double uu[M][N];
double vt[N][N];
FILE *fp;


fp = fopen("vector1.txt","r");



for ( k = 0; k < M; k++){
for(h = 0; h < N; h++){
fscanf(fp,"%lf",&a[k][h]);
printf("a[%d][%d] = %lf\t",k,h,a[k][h]);
}
printf("\n");
}

fclose(fp);





LWORK = 56046;

JOBU = 'A';
dgesdd_( &JOBU, &M, &N, a, &M, s, uu, &M, vt, &N, work, &LWORK, iwork, &INFO);



for(i = 0; i<M; i = i +1){
for(j = 0; j<N; j = j +1){

printf("uu[%d][%d] = %lf\t",i,j,uu[i][j]);
}
printf("\n");
}

printf("\n");

for(l = 0; l<N; l = l +1){
printf("s[%d] = %lf\n",l,s[l]);
}

printf("\n");

for(v = 0; v<N; v = v +1){
for(b = 0; b<N; b = b +1){
printf("vt[%d] = %lf\t",v,vt[v][b]);
}
printf("\n");
}



printf("\n INFO=%d\n", INFO );

return 0;
}


I'm having the problem that when I load a file with a matrix 10x3 and I print the uu matrix, I got a segmentation fault in the second line. Also if I modify it for a large matrix, I got the uu meatrix with a columns of all 1, se s vector are all 0, and the vt are all 0.

Thank you very much for any help
axelyamel
 
Posts: 8
Joined: Mon Jun 16, 2008 10:59 am

Postby axelyamel » Thu Jun 19, 2008 1:12 pm

ahs1200 wrote:I am surprised that your code builds in the first place.

I needed to change a, u and v to be a[M*N], u[M*N], v[N*N]. So 1-dim c arrays. Lapack expects 1-dim arrays column major. Then everything should run fine.

Cheers.


Thanks, that fixed it :) . The problem is that when you have large or Huge vectors, the program get a segmentation fault
axelyamel
 
Posts: 8
Joined: Mon Jun 16, 2008 10:59 am


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 5 guests