BLAS 替换会导致 Linux 中的矩阵乘法失败,但在 Windows 中则不然
BLAS Replacement causes failure of matrix multiplication in Linux but not in windows
我已经下载并安装了软件包qpOASES。
考虑以下代码:
#define ARMA_DONT_USE_CXX11 /* In Cygwin */
#include <armadillo>
int main()
{
arma::mat A;
A
<<0.0119<<0<<arma::endr
<<0.0237<<0.0119<<arma::endr
<<0.0354<<0.0437<<arma::endr
<<0.0469<<0.0354;
arma::mat B;
B
<<1.0<<0<<0<<0<<arma::endr
<<0<<1.0<<0<<0<<arma::endr
<<0<<0<<1.0<<0<<arma::endr
<<0<<0<<0<<1.0;
std::cout<<"A^T*B:"<<std::endl<<A.t()*B<<std::endl;
return 0;
}
当我将两个矩阵相乘时,它在窗口中运行正常:
g++ test.cpp -std=c++11 -o bin/example1 -I/cygdrive/d/tmp/qpoases/qpOASES/include -I'C:cygwinusrlocalinclude' -I'C:cygwinusrinclude' -Wall -Wconversion -O3 -lqpOASES -larmadillo -L'C:cygwinusrlocallib' /cygdrive/d/tmp/qpoases/qpOASES/src/BLASReplacement.o -L/cygdrive/d/tmp/qpoases/qpOASES/bin /cygdrive/d/tmp/qpoases/qpOASES/src/LAPACKReplacement.o -Wfatal-errors -Wconversion
./bin/example1
A^T*B:
0.0119 0.0237 0.0354 0.0469
0 0.0119 0.0437 0.0354
但它在Linux(Ubuntu)下失败了:
g++ test.cpp -std=c++11 -g -o bin/example1 -Wall -Wconversion -O3 -lqpOASES -larmadillo -L'qpoases' qpOASES/LAPACKReplacement.o qpOASES/BLASReplacement.o -Wfatal-errors -Wconversion
./bin/example1
A^T*B:
Segmentation fault (core dumped)
我已经意识到导致错误的是BLASReplacement
。因此,BLASReplacement
程序中删除可以正常工作:
g++ test.cpp -std=c++11 -g -o bin/example1 -Wall -Wconversion -O3 -lqpOASES -larmadillo -L'qpoases' qpOASES/LAPACKReplacement.o -Wfatal-errors -Wconversion
./bin/example1
A^T*B:
0.0119 0.0237 0.0354 0.0469
0 0.0119 0.0437 0.0354
以下是对BLASReplacement.cpp的快速访问。
似乎一起使用qpOASES
和armadillo
在一起对我来说使用Linux会很麻烦。是什么原因导致此问题,为什么此问题在我的 Windows 中不存在?
更新
我使用代码块作为调试器,发现最后一行导致错误:
typedef double T;
arma_fortran(arma_dgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC);
这个包装器的定义是def_blas.hpp
extern "C"
{
...
void arma_fortran(arma_dgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* B, const blas_int* ldB, const double* beta, double* C, const blas_int* ldC);
...
}
一个指向Armadillo
库的 github 分支在这里。
它blas_wrapper.hpp
内部似乎dgemm
armadillo
armadillo
和BLASReplacement.o
qpOASES
正在发生冲突。绕过它的最佳方法是什么?
我知道
这个老了,但是 qpOASES 在 2021 年解决了这个问题: https://github.com/coin-or/qpOASES/pull/108
回到问题首次发布时,最好的选择可能是在BLASReplacement.hpp/cpp中为所有导出的函数添加前缀,以使其与BLAS API不兼容。
相关文章:
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 换位表导致测试失败(但在游戏中运行良好)
- OpenCV Tracker 属性访问在 ARM 上因 SEGFAULT 而失败,但在 X86_64 中工作
- ostream_iterator运算符=在pair<int,int>上失败,但在包装器类上工作。我不能为成对<>重载运算符<<吗?
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- 为什么这个来自 Objective-C++ 的dynamic_cast在调试中成功但在发布时失败?
- 驱动器号上的查找文件失败,但在路径上传递
- mkdir 从命令行工作,但在使用 NFS 时C++失败
- enable_if is_same constexpr函数使MSVC失败(但在Clang,GCC中效果很好)
- 写一个概念检查库,但在所有筹款算术类型上都失败了
- 在Java中生成RSA签名,但在C 中验证签名失败
- 为什么这段代码在Visual Studio中有效,但在gcc中失败
- Qt OpenGL帧缓冲在一台PC上创建,但在另一台PC上失败
- 在Windows 7下可以从C#调用C DLL,但在Windows 10下失败
- Ostream Tellp在Windows上失败,但在Linux上没有失败
- C++程序编译在 Ubuntu 中失败,但在 MacOSX 中工作
- 正则表达式传递正则表达式测试器,但在 qt 中失败
- 为什么将boost::move()的返回值分配给非常数引用在C++0x模式下失败,但在C++03模式下有效
- Regex在g++4.9下匹配,但在g++-5.1下失败
- SQL SP在SSMS中正常工作,但在VC++应用程序中失败