MATLAB: Lapacke in level-2 C S-function

choleskydpotrslapacklevel-2 c s-functionlmwlapack

Hi, I would like to implement the function dpotrs from LAPACKE in the level-2 C S-function. However, whenever I make a call to this function, matlab/simulink gives an internal error. The S-function runs when I put dpotrs in comments (and thus I just copy the input B). My mdlOutputs looks like the following:
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T *dimsB = ssGetInputPortDimensions(S, 1);
real_T n = dimsB[0];
real_T m = dimsB[1];
real_T q;
real_T *C;
const real_T *A = ssGetInputPortRealSignal(S,0);
const real_T *B = ssGetInputPortRealSignal(S,1);
real_T *X = ssGetOutputPortRealSignal(S,0);
memcpy( X, B, (size_t)m*(size_t)n*sizeof(real_T));
/* Solve system */
dpotrs("U", &n, &m, A, &n, X, &n, &q);
if (q < 0) ssSetErrorStatus(S,"Error: illegal input to solve_chol");
}
I am able to compile the C code with:
mex -R2018a solve_chol_sfun.c -lmwlapack
I'm quite certain that the dimensions of the variables are correct. Any suggestions?

Best Answer

According to the interface listed here and the link you list above:
The n, m, and q arguments should be integer type. Typically, when linking with the MATLAB supplied BLAS and LAPACK libraries, this means mwSignedIndex. So try:
mwSignedIndex n = dimsB[0];
mwSignedIndex m = dimsB[1];
mwSignedIndex q;