MATLAB Answers


Lapacke in level-2 C S-function

Wouter van Dijk さんによって質問されました 2019 年 5 月 14 日
最新アクティビティ Wouter van Dijk さんによって コメントされました 2019 年 5 月 15 日
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?

  0 件のコメント

サインイン to comment.

1 件の回答

James Tursa
回答者: James Tursa
2019 年 5 月 14 日
編集済み: James Tursa
2019 年 5 月 14 日

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;

  1 件のコメント

Wouter van Dijk 2019 年 5 月 15 日
Spot on, this works!

サインイン to comment.

Translated by