Rob
Rob

Reputation: 1131

C code that uses blas, lapack and openmp working with gcc 4.9 but gives run time error with gcc 6

I have written a code in C.

You can find the source code here.

It makes use of the libraries blas, lapack and openmp.

I have compiled the blas and lapack libraries following these instrucions.

I use these flags to tell the compiler the libraries that it should link: -lblas -llapack -fopenmp.

I was using gcc 4.9 and the program can run correctly.

Recently I have updated gcc to gcc 6 and it shows many warning msgs about the implicit declaration of the blas and lapack functions:

src/PSIRWLS-train.c:152:17: warning: implicit declaration of function 'dgemm_' [-Wimplicit-function-declaration]
                 dgemm_(&trans, &trans, &(dataset.l), &ncols, &size,&factorA, KSC, &(dataset.l), miZ, &size, &factor, miKSM, &(dataset.l));

And when I run the app a segmentation fault error appears.

I am completely lost about the differences of gcc 4.9 and gcc 6, do you know any explanation about this?

Upvotes: 1

Views: 999

Answers (2)

Rob
Rob

Reputation: 1131

Problem solved.

1 - Some default flags are different in gcc 4 and 6. gcc 6 shows warnings when you don't decleare blas and lapack functions this way:

extern void dgemm_(...)

2 - It scaped me the initialization of one variable that had to be initialized to 0. I coded int i,j = 0; when I had to code int i=0, j=0;

gcc 4 initialized i to 0 (and the program was running correctly) and gcc 6 didn't (creating a segmentation fault because these variables were to index)

Upvotes: 1

paul-g
paul-g

Reputation: 3877

I had a similar problem once, and it seems very likely that there is some undefined behaviour in your code (e.g. a double free), which is handled in a compiler specific manner. Perhaps this changed between gcc 4.9 and 6.0.

It's hard to say without knowing your code, but you can use a number of tools yourself to track this issue down, for example GDB or especially valgrind's memcheck (worked brilliantly for me):

valgrind --tool memcheck <your binary here>

This will report locations of memory related errors and undefined behaviours in your code.

Upvotes: 0

Related Questions