segmentation violation using armadillo pinv() mex file MATLAB 2013a

조회 수: 1 (최근 30일)
Andrea
Andrea 2013년 10월 17일
답변: Matthias 2014년 1월 4일
Hi everybody, I am having issues using armadillo's pinv(arma::mat m) function in my mex file (created using the legacy code tool). Here is an example of what I'am trying to do
arma::mat unit(2,2);
arma::mat p;
unit.randu();
unit.print();
p = pinv(unit);
p.print();
When I perform the peudo inverse and the assignment I get a segmentation violation error causing matlab to crash. I cannot understand why this is appening. Even because the following code, actually works
arma::mat unit(2,2);
arma::mat p;
unit.randu();
unit.print();
pinv(unit);
But obviously I cannot access to the pseudoinverse. Can anyone help me? Is very important and I cannot find any information on the matter. Thank you very much Andrea
  댓글 수: 1
Andrea
Andrea 2013년 10월 17일
편집: Andrea 2013년 10월 17일
There is an update. The problem is caused by the file /usr/local/MATLAB/R2013a/bin/glnxa64/mkl.so Here are the firt rows of the stacktrace
[ 0] 0x00007ff96f8c46cb /usr/local/MATLAB/R2013a/bin/glnxa64/mkl.so+06420171 mkl_lapack_dlange+00000187
[ 1] 0x00007ff96f90c626 /usr/local/MATLAB/R2013a/bin/glnxa64/mkl.so+06714918 mkl_lapack_dgesvd+00006006
[ 2] 0x00007ff96f3853e6 /usr/local/MATLAB/R2013a/bin/glnxa64/mkl.so+00918502 dgesvd+00000150
[ 3] 0x00007ff966895292 /usr/local/lib/libarmadillo.so.3+00017042 wrapper_dgesvd_+00000135
[ 4] 0x00007ff966aa8277 /home/mago/Development/Repository/MIPWips/Heterogeneous/matlab/hetCon.mexa64+00062071
[ 5] 0x00007ff966aae737 /home/mago/Development/Repository/MIPWips/Heterogeneous/matlab/hetCon.mexa64+00087863
[ 6] 0x00007ff966aa29b3 /home/mago/Development/Repository/MIPWips/Heterogeneous/matlab/hetCon.mexa64+00039347
[ 7] 0x00007ff966a9af11 /home/mago/Development/Repository/MIPWips/Heterogeneous/matlab/hetCon.mexa64+00007953
It is clear now that the problem is matlab. Apparently armadillo does not use the system lapack libraries but it uses the "mkl_lapack_dlange" loaded by matlab. I'm trying to solve the problem. The options are
  1. compiling statically the lapack and blas libraries in armadillo
  2. rename the referred libary and add a symbolic link to the lapack library.
If anyone has got a better way of solving this problem please let me know.
thank you
Andrea

댓글을 달려면 로그인하십시오.

채택된 답변

Andrea
Andrea 2013년 10월 17일
Here I am with a work around. The problem is caused by the fact that armadillo invokes lapack and blas with 32bit integer pointerd. Matlab instead uses the mkl version of the above libraries and invokes them with a 64bit pointer. This causes the segmentation fault. To avoid this problem it is necessary to export to environment variable that force matlab to use the system libraries. This can be done prompting the two following commands in the same terminal from which matlab is launched
export BLAS_VERSION="/usr/lib/libblas.so"
export LAPACK_VERSION="/usr/lib/liblapack.so"
this is the case of my machine (running ubuntu 12.04). Use the locate command to find the libraries on your system. However, this solution reduces the efficiency of matlab, therefore is just a workaround for the people that are forced to write S-Functions using armadillo (just like me). Hence, do no include this exports in your .bashrc file!
Thanks to everyone
Andrea

추가 답변 (1개)

Matthias
Matthias 2014년 1월 4일
I have to mention that it is actually not necessary to use the systems "blas+lapack" libraries. For exactly your problem Armadillo offers the define flags "ARMA_BLAS_LONG" and "ARMA_BLAS_LONG_LONG". You can use these flags to define the correct array element sizes that serve as parameters for blas and lapack routines. In my case (also Ubuntu 12.04 64bit) I compile the mex files with "-DARMA_BLAS_LONG" and link them with "-lmwlapack -lmwblas". Afterwards everything works fine.
You may have a look at the "config.hpp" and "typedef_blas_int.hpp" headers of the armadillo library.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by