-
-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MATLAB Interface Is Incompatible with the Latest Version of MATLAB #1852
Comments
I will try to check whether using the ILP64 version of OpenBLAS will solve the incompatibility issue and whether it will be stable. |
I think the two challenges you will run into here are:
|
I think for the time being the best course of action is bypassing MATLAB's built-in MKL. I don't think 64-bit integer adoption rate is picking up anytime soon so most people will be working with LP64. The |
Fwiw, in the 'new' CLib I am currently working on, we'll have the option to generate code for different integer formats. This may involve some 'lossy' type casting between ILP64 and LP64, but that way, we'd have a clean separation of what MATLAB sees at the interface and what Cantera does under the hood. (To explain: the |
Problem description
The latest version of MATLAB (R2024b) comes with Intel MKL as the default library for BLAS and LAPACK. This version of MKL is built with ILP64 where a 64-bit
int
type is used for all integers in order to support very large array sizes (>2^31-1). The default OpenBLAS package that comes with Cantera uses LP64 where standard integers are 32-bit and thelong
type is required for 64-bit integers. This causes an incompatibility issue when data in an array is passed back and forth between MATLAB and OpenBLAS. In some cases this will just return an incorrect type error but in the worst case scenario will cause a buffer overflow and instantly crashes MATLAB.A partial workaround exists to resolve this problem, as mentioned in this thread. We can bypass ILP64 MKL by setting the environment variable
LD_PRELOAD
and force MATLAB to use the LP64 OpenBLAS library in the Cantera environment. This will correctly set the types of integers and Cantera will successfully solve any linear algebra problems. However, this workaround is unstable and will cause crashes when theplot
function is invoked, for example to plot to concentration of species over time.Steps to reproduce
ctLoad
;equil.m
;LD_PRELOAD
to the location of the OpenBLAS library in your Cantera environment;Behavior
The
gas
object will fail to equilibrate, this error appears in the MATLAB terminal:while this error will appear in the linux terminal:
Parameter 6 of DGEMV is the leading dimension of a matrix, which in MKL ILP64 is a 64-bit
int
type but in OpenBLAS is a 64-bitlong
.After setting the
LD_PRELOAD
variable to the correct OpenBLAS location. This example will successfully run until theplot
function is invoked to plot the equivalence ratio vs. temperature. MATLAB instantly crashes and throws either afree(): invalid pointer
error ormunmap_chunk()
error, both of which indicate a memory corruption has occured. It is unknown whether other built-in MATLAB functions will cause these crashes, but simple manipulations on the data being plotted did not return any errors or cause crashes. A crash dump info is included below:matlab_crash_dump_510456-1.txt
System information
Additional context
Older versions of MATLAB are untested.
The text was updated successfully, but these errors were encountered: