Call lapack routine from inside SImulink S function on 64bit

1 view (last 30 days)
I am trying to call a LAPACK routine (sgetrf) from inside a Simulink S function on a 64bit machine using libmwlapack. However, I get the error message: MKL ERROR: Parameter 1 was incorrect on entry to SGETRF
Here is the function prototype: extern void sgetrf_(mwSignedIndex *, mwSignedIndex *, float (*)[3], mwSignedIndex *, mwSignedIndex *, mwSignedIndex *);
And the function call: sgetrf_(&nvars,&nvars,(float (*)[3])Gmat,&nvars,ipiv,&info);
I also tried using int instead of mwSignedIndex, but I get the same error message.
The mwlapack library is not compiled with -g so I can't see my variables inside sgetrf.
Any suggestions?

Answers (1)

Matthew
Matthew on 23 Jul 2013
Here is a useful resource for understanding how to compile C code using mex on 64 bit devices: http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html?s_tid=doc_12b#bsgpkjp-3
The main pitfall is that the mex command uses the -compatibleArrayDims flag (32-bit API) by default. This results in the addition of the -DMX_COMPAT_32 flag in the call to mex. As mentioned above, this resulted in an error message stating that the array dimension I was passing in was incorrect: MKL ERROR: Parameter 1 was incorrect on entry to SGETRF. Merely changing the integers to a 64bit compatible type was not sufficient.
The fix was to include the -largeArrayDims flag in the call to mex and declare array indices as type mwSize. Since the S function is recompiled by the call to sim, it is necessary to set Simulation>Model Configuration Parameters>Device type> to the relevant 64-bit setting.
I don't understand why the -compatibleArrayDims flag is set automatically on a 64-bit machine. Perhaps someone can enlighten me.

Categories

Find more on Structures 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!