如何使用openMP使openBLAS工作?

时间:2016-01-03 16:01:56

标签: r openmp rcpp openblas

我从openBLAS那里得到了很多警告,比如

OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option.

这是我的src / Makevars文件的样子

PKG_CPPFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

这是我的头文件:

#define ARMA_NO_DEBUG

#ifdef _OPENMP
#include <omp.h>
#endif

//[[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>

//[[Rcpp::depends(RcppProgress)]]
#include <progress.hpp>

#include <Rcpp.h>
#include <R.h>

openMP在我的代码中使用,如此

#pragma omp parallel for num_threads(n_threads) schedule(dynamic) private(W, mu)
for (unsigned int j = 0; j < m; j++)

其中n_threads通过函数参数传递。在n_threads = 1时一切正常,但在n_threads = 2时收到了上述警告。 可以找到一个完整的代码here,这也取决于其他文件(对不起,我不能粘贴,因为它有点长)。

我尝试将USE_OPENMP=1添加到src / Makevars,但它不起作用。任何人都有解决方案吗?谢谢!

1 个答案:

答案 0 :(得分:1)

在CPU模式下运行Torch时,我收到了相同的警告。使用OPEN_MP 1重建OpenBLAS为我修复了它。

如果要使用OPEN_MP 1重建OpenBLAS,则:

转到您克隆OpenBLAS存储库的文件夹(对我来说是/ home / brt / code / OpenBLAS)

cd /home/brt/code/OpenBLAS/
make clean
make USE_OPENMP=1
sudo make install

如果你还没有这样做,

sudo vi /etc/ld.so.conf.d/openblas.conf

添加以下行:/ opt / OpenBLAS / lib

保存并关闭

sudo ldconfig

这应该使用OPEN_MP重建OpenBLAS为1