I have a bit a problem understanding some issues I obtain when trying to compile a piece of C-code. In particular, with calling the dgemm function for matrix transposition.
For a bit of context: I am completely new at C-code, the code I am trying to compile is a decade old, and I had several issues compiling when running MATLAB on Windows, so I moved to Ubuntu.
I downloaded the code C-code from here, and I followed the instructions therein which in summary say:
- Run "mex -setup" and enter the number corresponding to the template option gccopts.sh.
- Compile with "mex fmpc_sim.c -lblas -llapack".
- Compile with "mex fmpc_step.c -lblas -llapack".
- Test by running the example "masses_example.
Everything compiled properly in Ubuntu, once I was able to install a version of gcc that is compatible with MATLAB, however I was never offered any options when running "mex-setup. Furthermore, although everything compiles without errors, MATLAB crashes when running the example.
Further investigation showed that crashing occurs when the code first encounters the line:
I stripped most of the code to ensure that I can ask a more specific question. Let's say that the original C-code is called "stripped.c" and reads:
const double fone = 1;
const double fzero = 0;
void mexFunction(int nlhs, mxArray *plhs, int nrhs, const mxArray *prhs)
/* problem setup */
int i, n;
double *A, *At;
/* inputs */
A = mxGetPr(mxGetField(prhs,0,"A"));
n = (int)mxGetScalar(mxGetField(prhs,0,"n"));
/* outputs */
plhs = mxCreateDoubleMatrix(n,n,mxREAL);
At = mxGetPr(plhs);
eyen = malloc(sizeof(double)*n*n);
dptr = eyen;
for (i = 0; i < n*n; i++)
*dptr = 0;
dptr = dptr-n*n;
for (i = 0; i < n; i++)
*dptr = 1;
dptr = dptr+n+1;
Then when I execute this MATLAB-code
mex stripped.c -lblas -llapack
I get no compilation errors, but a matrix At filled with zeros.
If in turn I change the type declaration of variable n to:
Then I get one compilation warning per each "integer" input of the F77_CALL(dgemm) function saying: "expected 'const int *' but argument is of type 'size_t *'", however At is not anymore filled with zeros, but the transpose of A as requested.
I understand the warnings, since the documentation of dgemm here says that I such inputs must be integers, but then again, it works.
Now, this is a just a very minimal working example, and many more calls to C-functions such as dgemm take place. The C-code I downloaded corresponds to what is reported in a very well cited paper, hence the compilation-running issues I am experiencing must be on my side, but I am at a lost on what could I be doing wrong. Since the C-code is so old I suspect it migth be some sort of compatibility issue, but I can't spot it also.
Any help is appreciated.