How to make openBLAS work with openMP?

你。 提交于 2019-12-25 14:25:08

问题


I got tons of warning from openBLAS like

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.

Here is what my src/Makevars file looks like

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

And here is my header file:

#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 is used in my code like this

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

where n_threads is passed via function argument. Everything is fine when n_threads = 1 but got the above warnings when n_threads = 2. A complete code can be found here, which depends on other files as well (sorry I cannot paste here as it is a bit long).

I tried adding USE_OPENMP=1 to src/Makevars, but it does not work. Any body has a solution? Thank you!


回答1:


I got the same warnings while running Torch on CPU mode. Rebuilding OpenBLAS with OPEN_MP 1 fixed it for me.

If you want to rebuild OpenBLAS with OPEN_MP 1, then:

Go to the folder where you cloned OpenBLAS repository (for me it is /home/brt/code/OpenBLAS)

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

if you have not already done so,

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

add the line: /opt/OpenBLAS/lib

save and close

sudo ldconfig

This should rebuild OpenBLAS with OPEN_MP as 1



来源:https://stackoverflow.com/questions/34578526/how-to-make-openblas-work-with-openmp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!