MATLAB: Matlab crushes when trying to run java code that contains function calls to JBLAS

jblaslapack

I have a Java code that uses JBLAS for matrix computations and in Java side everything runs fine. However for debugging purposes, visualization etc., I pack the java code to jar-file and run It from Matlab. Everything works fine until the program reaches code that uses JBLAS. First I get errors like "Intel MKL ERROR: Parameter 3 was incorrect on entry to DGEMM", but this does not yet crush Matlab. However when the code reaches a function call to JBLAS routine Solve.pinv() the Matlab crushes. In terminal I got message like
"# A fatal error has been detected by the Java Runtime Environment: # Internal Error (safepoint.cpp:687), pid=7302, tid=140358050563840 # fatal error: Deadlock in safepoint code. Should have called back to the VM before blocking. #"
In hs_error_xxx.log file I see traces from JBLAS pinv method to NativeBlas.dgelsd method. I think the problem may be related to dynamic linking of lapack-libraries, but not sure??

Best Answer

Hi Vili,
MATLAB's BLAS and LAPACK libraries differ in one important way from many other BLAS/LAPACK libraries: we use 64-bit integers wherever the functions expect integers whereas most other implementations still use 32-bit integers (even on 64-bit systems). If your library which probably works with 32-bit integers then calls our BLAS/LAPACK implementations which expect to see 64-bit integers, MATLAB may very well crash.
Luckily MATLAB is also able to work with other BLAS/LAPACK implementations though, even ones which work with 32-bit integers. So what you could try to do to work around this issue, is make MATLAB use your system's BLAS and LAPACK implementations. To do so you would need to point the BLAS_VERSION and LAPACK_VERSION environment variables to those other implementations.And then start MATLAB from this same shell. Once inside MATLAB you can use:
version -lapack
And:
version -blas
To verify that MATLAB is indeed using a different implementation (i.e. these should no longer return "IntelĀ® Math Kernel Library Version....").
Note, you always need to change both the LAPACK and BLAS implementation, changing only one of them will cause crashes in MATLAB when performing matrix and vector operations.
I hope this helps resolving the crash. If this was not the issue, please raise a help ticket with the MathWokrs Technical Support Department along with the crash dump to help understand the issue better.
-Rutuja
Related Question