在MATLAB mex文件中使用外部BLAS和LAPACK库 [英] Use external BLAS and LAPACK libraries in a MATLAB mex file

查看:332
本文介绍了在MATLAB mex文件中使用外部BLAS和LAPACK库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试为MATLAB的数值软件库构建接口.因此,我遇到了以下问题:

I am currently try to build an interface for a numerical software library to MATLAB. Thereby I end up with the following problem:

MATLAB默认使用64位整数,并且其BLAS和LAPACK库(即MKL)也仅支持64位整数.不幸的是,我想通过mex文件连接到Matlab的库仅使用32位整数及其依赖项.现在,只要mex文件尝试从BLAS或LAPACK调用函数,由于整数宽度不同,它就会崩溃.

MATLAB uses per default 64 bit integers and its BLAS and LAPACK library (namely the MKL) supports only 64 bit integers as well. Unfortunately the library which I want to connect via a mex-file to Matlab uses only 32bit integers and its dependencies too. Whenever the mex-file now tries to call a function from BLAS or LAPACK it crashes because of the different integer widths.

我尝试使用

mex  myinterface.c -largeArrayDims -llapack -lblas

链接器在mex文件中包含对两个库的引用,但是如果我现在从MATLAB调用它,则会崩溃.从回溯中,我发现一个LAPACK调用会产生分段错误,这似乎是由不同的Integer宽度引起的.此外,回溯告诉我,MKL导致了此错误,而不是我链接到程序的BLAS和LAPACK.

The linker includes the reference to both libraries in the mex file, but if I call it now from MATLAB it crashes. From the backtrace I got that one LAPACK call produces a segementation fault which seems to be cause by the different Integer widths. Furthermore the backtrace tells me that the MKL caused this error instead of the BLAS and LAPACK I linked to my program.

问题是:是否有可能将mex文件链接到其依赖项,以便它解析文件中的符号而不是MATLAB中的符号,即使用给定的BLAS和LAPACK库?

The question is: Is there a possibility to link the mex file to its dependencies such that it resolves the symbols from it instead of the ones from MATLAB, i.e. uses the given BLAS and LAPACK libraries?

备注:

  • MATLAB 2013
  • GCC 4.6
  • BLAS和LAPACK库是动态的.

推荐答案

我知道这个问题已经一岁了,但这对某些人可能有用:

I know this question is a year old already, but this might be useful for somebody:

我相信,如果您预加载动态链接库以强制使用它们(也许可以像Shai所建议的那样更改LD_LIBRARY_PATH),就可以解决您的问题.我必须做一些类似的事情来强制使用某些库的特定版本. LD_LIBRARY_PATH适用于外部库(例如OpenCV),而LD_PRELOAD适用于 standard 库.在命令行上,输入以下内容:

I believe your problem would be solved if you pre-loaded dynamically linked libraries to enforce their use (maybe along with changing your LD_LIBRARY_PATH as Shai has suggested). I had to do something similar to enforce use of particular versions of some libraries. LD_LIBRARY_PATH works for external libraries (such as OpenCV), while LD_PRELOAD for standard libraries. On your command line, type the following:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/OpenCV/lib/:/path/to/SomethingElse/lib
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16:/path/to/libOtherStandardLibrary.so
matlab

这也有助于解决stdc ++对于系统和Matlab具有不同版本(具有自己的旧版本)的问题.

This helps also with the problem of stdc++ having different version for the system and for Matlab (which carries its own, older, version).

这篇关于在MATLAB mex文件中使用外部BLAS和LAPACK库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆