1

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Rob
  • 1,080
  • 2
  • 10
  • 24
  • The link to your code leads to error 404... You may be interested by [cblas](http://www.netlib.org/blas/#_cblas) and [Lapacke](http://www.netlib.org/lapack/lapacke.html) which are the C interfaces to BLAS / LAPACK. Otherwise, you may have to decleare [`extern dgemm_(...)`](http://nicolas.limare.net/pro/notes/2014/10/31_cblas_clapack_lapacke/) . Notice that declaring fortran functions this way may lead to portability problems, because the naming convention changes between Linux and the W-thing... Using Cblas and Lapacke leaves this issue (and some others) to the developers of these interfaces. – francis Sep 23 '16 at 21:15

2 Answers2

1

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)

Rob
  • 1,080
  • 2
  • 10
  • 24
0

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.

Community
  • 1
  • 1
paul-g
  • 3,797
  • 2
  • 21
  • 36