Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
69 Views

Segmentation Fault in dgemv

Hi,

I have a very simple test file for calling dgemv in my C-Application: useblas.c

I compile and link it in this way:

icc -I/opt/intel/Compiler/11.1/069/mkl/include -g -c useblas.c

ifort -nofor_main -L/opt/intel/Compiler/11.1/069/mkl/lib/intel64 -lpthread -openmp -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -g useblas.o -lm


When executing the a.out file i get a segmentation fault in line 27 (which is the function call of dgemv):

Program received signal SIGSEGV, Segmentation fault.
0x00002aaaaaba31f7 in dgemv_ ()
from /opt/intel/Compiler/11.1/069/mkl/lib/intel64/libmkl_intel_lp64.so
(gdb) bt
#0 0x00002aaaaaba31f7 in dgemv_ ()
from /opt/intel/Compiler/11.1/069/mkl/lib/intel64/libmkl_intel_lp64.so
#1 0x00000000004012c5 in main () at useblas.c:27

My code was running on: Intel Xeon CPU X7460 @ 2.66GHz.


A ldd give me the following:

$ ldd a.out
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003921000000)
libmkl_intel_lp64.so => /opt/intel/Compiler/11.1/069/mkl/lib/intel64/libmkl_intel_lp64.so (0x00002aaaaaad6000)
libmkl_intel_thread.so => /opt/intel/Compiler/11.1/069/mkl/lib/intel64/libmkl_intel_thread.so (0x00002aaaaaed0000)
libmkl_core.so => /opt/intel/Compiler/11.1/069/mkl/lib/intel64/libmkl_core.so (0x00002aaaabf35000)
libm.so.6 => /lib64/libm.so.6 (0x0000003920800000)
libiomp5.so => /opt/intel/Compiler/11.1/069/lib/intel64/libiomp5.so (0x00002aaaac2f4000)
libc.so.6 => /lib64/libc.so.6 (0x0000003920400000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003925c00000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003920c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003920000000)


What's wrong? Or is there Bug? Btw, the same code works fine with "AMD Core Math Library (ACML)" and the intel compiler.


Cheers,
Tim
0 Kudos
8 Replies
Highlighted
Moderator
69 Views

Hi Tim,
please try C intreface of dgemv (cblas_dgemv )
--Gennady
0 Kudos
Highlighted
Beginner
69 Views

Hi Gennady,

thanks for the hint. Using the C interface works fine. But why cant i use the Fortran lib directly. And why does this work with acml?

Cheers,
Tim
0 Kudos
Highlighted
Black Belt
69 Views

Calling the Fortran library from C is possible but the calling conventions are not the same. See the Mixed Language Programming chapters in the Intel Fortran Users' Guide.

Depending on the compilers and platform used, it may be possible to make it appear as if you are calling one library routine from either C or Fortran. For example, if in C you have dgemv(...), in the compiled code there may be a reference to _dgemv, where as a corresponding call in Fortran may result in a reference to _DGEMV. The linker matches up the reference with the appropriate library routine. Users who know only one of the two languages may find this method easier to use.

On the other hand, one may want the Fortran library routine to be called directly from C, without going through a C wrapper around the Fortran library routine. In this case, one has to know how the two languages correspond as to types, call by value/call by reference, etc.
0 Kudos
Highlighted
New Contributor I
69 Views

The problem is that Fortran expects call by reference and some of your parameters to DGEMV are call-by-value. Changing your BLAS call to:

dgemv("N", &m, &n, α, a, &n, x, &one, β, y, &one);

works fine.

0 Kudos
Highlighted
Black Belt
69 Views

If the Fortran Lapack routines are called directly from C, it should be kept in mind that C and Fortran have different conversions for representing two-dimensional arrays. The difference may not matter if a full, symmetric matrix is being passed but, in all other cases, care is necessary.
0 Kudos
Highlighted
Moderator
69 Views

I would throw my 2 cents in this discussion: Tim, as an additional info please look at the MKL User'sGuide. See Chapter7,Mixed-language Programming with Intel MKL. You can find there link to the 2 examples ( 7.2 and 7.3) show how to call Fortran routines fromC-languageprograms.
--Gennady
0 Kudos
Highlighted
Beginner
69 Views

Thank you very much for the detailed information and explanations. Now I understood how to use the MKL in the correct way. :-)
0 Kudos
Highlighted
Employee
69 Views

Here's an article that summarizes some of the what has already been said on this thread.

Todd
0 Kudos