Using GotoBLAS2 in a MATLAB MEX file (shared library help?)
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have been having a lot of trouble using the GotoBLAS2 library with a C program, which I want to call via the MEX interface.
Basically, I have some numerical optimization code in C that I want to use in a MATLAB script. I am trying to link the code to GotoBLAS2 for a fast BLAS library. Based on an example I saw of the use of this code, I am compiling it with the linker options
-llapack -lgoto2
to link it with GotoBLAS2.
I have a separate stand-alone program (non-MEX) which compiles this way and works fine. However, when I compile the MEX version and then run it, the LAPACK functions I call end up going to the MATLAB LAPACK libraries, which do not seem to be compatible. For example, my code contains a LAPACK call such as
int work_sz = -1; dsytrf("U", (int *)&m, NULL, (int *)&m, NULL, (LM_REAL *)&tmp, (int *)&work_sz, (int *)&info);
I understand this code is supposed to make a direct call to a FORTRAN library, since C and FORTRAN have the same calling conventions (?), and in my stand-alone program it works. However, if I execute the same call using MATLAB's gdb debugging, I see the error
MKL ERROR: Parameter 7 was incorrect on entry to DSYTRF.
This tells me that the "dsytrf_" symbol is actually being loaded from the Intel Math Kernel Library (which comes with MATLAB) instead of the LAPACK my stand-alone program uses (which is in /usr/lib/liblapack.so). So my question is this: how can I choose which LAPACK library my MEX-ified program uses?
Note: to make things more complicated, when I compiled GotoBLAS2, I set it to statically link a version of LAPACK it came with. When I execute "nm libgotoblas2.so", I see that it actually contains a symbol called "dsytrf_" as well. So I guess I would be happy if my MEX program used either the function in some separate LAPACK, or this one in libgotoblas2.so.
Many thanks for any help!
0 个评论
回答(1 个)
Stephen Becker
2012-2-22
Matlab is probably adding a -lmwblas flag somewhere, so their version of blas is overriding yours. You can probably edit mexopts.sh and change this.
Also, try http://www.stanford.edu/~echu508/matlab.html. He has an interesting method to change the version of BLAS that Matlab uses. Basically, for him (he was on a Mac), he edited this file: /Applications/MATLAB_R2008b.app/bin/maci/blas.spec
Best of luck!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!