Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

mkl with matlab mex interface

$
0
0

Dear users:

I am having trouble interfacing my intel mkl code with Matlab using the mex interface. I have a code that does a certain factorization based on the pivoted QR decomposition. It works fine when I compile the code by itself. However, I would like to make a mex code for other users. I have done this before and have been able to compile simple mex files with icc and mkl. However, now I have a problem. Perhaps someone here has ideas for me to try. I am trying to use the pivoted QR decomposition function and this is where my code fails:

m = nrows; n = ncols;

data = (double*)mxCalloc(nrows*ncols,sizeof(double));

Iarr = (lapack_int*)mxCalloc(n,sizeof(lapack_int));

tauarr = (double*)mxCalloc(min(m,n),sizeof(double));



LAPACKE_dgeqp3(LAPACK_COL_MAJOR, (lapack_int)nrows, (lapack_int)ncols, data, (lapack_int)nrows, Iarr, tauarr);

sometimes it simply segfaults (when mex file is run inside matlab). Other times it complains that parameter 8 to dgeqp3 is incorrect.

Intel MKL ERROR: Parameter 8 was incorrect on entry to DGEQP3.

Parameter 8 is not present in the lapacke function, it is the info parameter in the fortran routines. Notice that I initialize space using mxCalloc vs regular C calloc..

https://software.intel.com/sites/products/documentation/hpc/mkl/mklman/G...

Here is how I compile my mex file:

#!/bin/bash

icc -c -DMX_COMPAT_32   -D_GNU_SOURCE -DMATLAB_MEX_FILE  -I"/apps/matlab2014a/extern/include" -I"/apps/matlab2014a/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -openmp -shared -O -DNDEBUG mex_code1.c  -o mex_code1.o

icc -openmp -shared -L"/opt/intel/mkl/lib/intel64/" -I"/opt/intel/mkl/include/" /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.a  /opt/intel/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/mkl/lib/intel64/libmkl_core.a /opt/intel/mkl/lib/intel64/libmkl_blas95_lp64.a  /opt/intel/mkl/lib/intel64/libmkl_lapack95_lp64.a -lmkl_rt -lmkl_core -lmkl_gnu_thread -lgomp -lpthread  -Wl,--no-undefined -Wl,-rpath-link,apps/matlab2014a/bin/glnxa64 -O -Wl,--version-script,"apps/matlab2014a/extern/lib/glnxa64/mexFunction.map" mex_code1.o   -L"apps/matlab2014a/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -o mex_code1.mexa64

rm -f mex_code1.o

I suspect the issue maybe in the compilation step (which compiles fine). As i mentioned, the code runs fine outside of the mex interface, when I replace back

all the mxCalloc calls by regular calloc.

thanks for your help

 


Viewing all articles
Browse latest Browse all 2652

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>