We found that (under Linux) Matlab mex files using IT++ crash since Matlab R2011b. After we have filed a support request at Mathworks it turned out that (see response attach at the end of this message) the reason for the crash is that since R2011b, Matlab's MKL (and hence the BLAS/LAPACK routines) expects 64-bit integers. When IT++ code is executed in a mex file it dynamically links against Matlab's MKL and hence crashes whenever BLAS/LAPACK routines are called since IT++ uses 32-bit integers.
I have created a patch (which is attached) to make sure that all BLAS and LAPACK routines are called with 64-bit integers. The patch applies cleanly against IT++ 4.2. All changes outside of itpp/base just fix some unused variable compile warnings. "make check" may fail at the tests which use BLAS/LAPACK if the local version of BLAS/LAPACK expects 32-bit integers.
We have now solved the problem for us by installing 2 versions of IT++, one using 32-bit integers (for stand-alone programs) and one using 64-bit integers (for mex programs). It might be possible to make a single version which can handle different MKL/BLAS/LAPACK versions (regarding integer width). To this end, we think that one would have to tackle the following two questions:
Is it possible to detect at run-time if a program is executed stand-alone or as a mex file from within Matlab?
Can a test be added to the configure script which checks if the local version of MKL/BLAS/LAPACK expects 64-bit or 32-bit integers? (This would be just a matter of detecting a SIGSEGV if the wrong integer width has been used.)
Response to our support request:
Because libitpp is dynamically linked against BLAS and LAPACK, at runtime of the MEX-file, automatically the MKL shipped with MATLAB will be used to provide BLAS and LAPACK functionality. There is a mismatch however between the integer datatypes used in the MKL shipped with MATLAB 7.13 (R2011b) (64-bit integers) and the integer datatypes used in libitpp (32-bit integers). This mismatch leads to a crash.
Now there are various possible solutions to this issue:
libitpp appears to be compilable without BLAS and LAPACK (--without-blas and --without-lapack options for the ./configure script). With these disabled the MEX-file works fine. This may have a negative impact on the performance of libitpp though.
You can force MATLAB to use your system's BLAS and LAPACK libraries (which work with 32-bit integers) instead of the MKL. To accomplish this create two environment variables BLAS_VERSION and LAPACK_VERSION and point them to your system's BLAS and LAPACK libraries respectively. So this could for example look like:
This may have a negative impact on MATLAB's performance though.
Log in to post a comment.