Program calling wrong version of LAPACK
Show older comments
I'm graduate student in applied math. I'm working on implementing a matrix factorization algorithm my advisor devised. I'm trying to run tests to compare his algorithm with the more standard rank-revealing QR factorization (rrqr).
I've got an implementation of (Communication Avoiding) RRQR `carrqr.f90`. I want to call this function from within MATLAB. To do this I create a shared library C library with that I can load and call with the `loadlibrary` and `calllib` functions. My build commands are as follows
gcc -g -m64 -fPIC -c src/clusol.c -o src/clusol.o
gfortran -m64 -fPIC -Jsrc -g -O0 -c src/lusol_precision.f90 -o src/lusol_precision.o
gfortran -m64 -fPIC -Jsrc -g -O0 -c src/lusol.f90 -o src/lusol.o
gfortran -m64 -fPIC -Jsrc -g -O0 -c src/carrqr.f90 -o src/carrqr.o
gfortran -m64 -fPIC -Jsrc -g -O0 -c src/updateA.f90 -o src/updateA.o
gfortran -m64 -fPIC -Jsrc -g -O0 -c src/paneling.f90 -o src/paneling.o
gfortran -m64 -fPIC -fdefault-integer-8 -g -O0 -c src/lusol_util.f -o src/lusol_util.o
gfortran -m64 -fPIC -fdefault-integer-8 -g -O0 -c src/lusol6b.f -o src/lusol6b.o
gfortran -m64 -fPIC -fdefault-integer-8 -g -O0 -c src/lusol7b.f -o src/lusol7b.o
gfortran -m64 -fPIC -fdefault-integer-8 -g -O0 -c src/lusol8b.f -o src/lusol8b.o
gfortran -m64 -fPIC -fdefault-integer-8 -g -O0 -c src/lusol9.f -o src/lusol9.o
gcc -g -m64 -shared src/clusol.o src/lusol_precision.o src/lusol.o src/carrqr.o src/updateA.o src/paneling.o src/lusol_util.o src/lusol6b.o src/lusol7b.o src/lusol8b.o src/lusol9.o -o src/libclusol.so -Wl,-rpath,/usr/lib -lgfortran
(clusol.c just contains wrappers to call the functions implemented in the fortran files)
But when I call the carrqr function from MATLAB I get a segfault. It happens when calling a LAPACK function `dnrm2`. Viewing the stack at the time of the crash I see
#0 0x00002aaafdeb4130 in mkl_blas_avx_xdnrm2 ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/mkl.so
#1 0x00002aaad3ff127f in ()
#2 0x00002aabd3ff137f in ()
#3 0x0000000000000011 in ()
#4 0x00000000d999999d in ()
#5 0x00002aaafcf01452 in mkl_blas_xdnrm2 ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/mkl.so
#6 0x00002aaafce9fde3 in mkl_blas_dnrm2_omp ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/mkl.so
#7 0x00002aaac5f146a3 in __kmp_invoke_microtask ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/../../sys/os/glnxa64/libiomp5.so
#8 0x00002aaac5ee3007 in __kmp_invoke_task_func ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/../../sys/os/glnxa64/libiomp5.so
#9 0x00002aaac5ee26f5 in __kmp_launch_thread ()
at /global/software/sl-7.x86_64/modules/tools/matlab/r2017b/bin/glnxa64/../../sys/os/glnxa64/libiomp5.so
#10 0x00002aaac5f149c3 in __kmp_launch_worker(void*) ()
#11 0x00002aaaac754ea5 in start_thread () at /lib64/libpthread.so.0
#12 0x00002aaaaca6796d in clone () at /lib64/libc.so.6
So it seems like it's calling LAPACK implementation within MATLAB. It's also trying to do some multithreading but the code should be single-threaded. So I'm pretty sure the cause of the crash is it just running the wrong dnrm2 function. I've got the LAPACK shared library on the system. But I don't know how to go about instructing the program to use this version of LAPACK at runtime. I've also tried incorporating the LAPACK library into the compilation process so that the necessary functions are inside `libclusol.so` but I couldn't figure out how to do that either. Anyone have any idea what I should do?
Just to be clear nothing I'm doing code is actually telling the program which version of LAPACK to use. At first I thought I would do this through linker flag "-llapack -lblas" at the last step of compilation but that didn't seem to have any affect. So I guess it shouldn't come as a surprise to me that it's not calling the right version of LAPACK. But I still don't know how to instruct it to use the right version. I'm thinking I need to somehow load the liblapack.so before I try to run my program but I don't know how to do that.
Answers (1)
Onyebuchi Ekenta
on 16 Feb 2021
Edited: Onyebuchi Ekenta
on 16 Feb 2021
0 votes
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!