我很难在Ubuntu 16.04中为R启用OpenMP支持。在安装RcppArmadillo时,找到了OpenMP,但在安装依赖于RcppArmadillo的软件包(例如' forecast')时,我收到以下消息:
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-
library/Rcpp/include" -I"/usr/local/lib/R/site-
library/RcppArmadillo/include" -fpic -g -O2 -fstack-protector-strong -
Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c
calcBATS.cpp -o calcBATS.o
In file included from /usr/local/lib/R/site-
library/RcppArmadillo/include/armadillo:53:0,
from /usr/local/lib/R/site-
library/RcppArmadillo/include/RcppArmadilloForward.h:46,
from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
from calcBATS.h:36,
from calcBATS.cpp:1:
/usr/local/lib/R/site-
library/RcppArmadillo/include/armadillo_bits/compiler_setup.hpp:474:96:
note: #pragma message: WARNING: use of OpenMP disabled; this compiler
doesn't support OpenMP 3.0+
#pragma message ("WARNING: use of OpenMP disabled; this compiler doesn't
support OpenMP 3.0+")
我的〜/ .R / Makevars如下:
VER=-5.4
CC=ccache gcc-$(VER)
CXX=ccache g++-$(VER)
FC=ccache gfortran
F77=ccache gfortran
CXX11 =ccache g++-$(VER)
CXX14=ccache g++-$(VER)
CXX_STD = CXX11
CFLAGS= -O3 -Wall -pipe -pedantic -std=gnu11 -fopenmp
FCFLAGS=-O3 -Wall -pipe -pedantic -std=gnu11 -fopenmp
CXXFLAGS = -O3 -Wall -pipe -pedantic -std=gnu11 -fopenmp
CXX11FLAGS = -O3 -Wall -pipe -pedantic -std=gnu11 -fopenmp
CXX14FLAGS = -O3 -Wall -pipe -pedantic -std=gnu14 -fopenmp
PKG_CFLAGS= -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp
PKG_CXXFLAGS= -fopenmp
PKG_LIBS = -fopenmp -lgomp
CFLAGS= -O3 -Wall -pipe -pedantic -std=gnu99 -fopenmp
FCFLAGS=-O3 -g0 -Wall -pipe -fopenmp
我玩过这些设置,但似乎没有任何帮助。任何明智的想法将不胜感激。非常感谢。
更新
我认为现在有些软件包正在使用openMP(例如xgboost)。但是,我仍然收到一些包(例如Amelia)的错误消息:
* installing *source* package ‘Amelia’ ...
** package ‘Amelia’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-
library/Rcpp/include" -I"/usr/local/lib/R/site-
library/RcppArmadillo/include" -fpic -g -O2 -fstack-protector-strong -
Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c
em.cpp -o em.o
In file included from /usr/local/lib/R/site-
library/RcppArmadillo/include/armadillo:53:0,
from /usr/local/lib/R/site-
library/RcppArmadillo/include/RcppArmadilloForward.h:46,
from /usr/local/lib/R/site-
library/RcppArmadillo/include/RcppArmadillo.h:31,
from em.h:3,
from em.cpp:2:
/usr/local/lib/R/site-
library/RcppArmadillo/include/armadillo_bits/compiler_setup.hpp:474:96:
note: #pragma message: WARNING: use of OpenMP disabled; this compiler
doesn't support OpenMP 3.0+
#pragma message ("WARNING: use of OpenMP disabled; this compiler doesn't
support OpenMP 3.0+")
^
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o
Amelia.so em.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -
lR
installing to /usr/local/lib/R/site-library/Amelia/libs
我可以看到Amelia没有完成' -fopenmp'不像xgboost,但我不知道还有什么要添加到我的〜/ .R / Makevars中。 xgboost的安装结束如下(注意-fopenmp):
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-
z,relro -o xgboost.so ./xgboost_R.o ./xgboost_custom.o ./xgboost_assert.o
./amalgamation/xgboost-all0.o ./amalgamation/dmlc-minimum0.o
./rabit/src/engine_empty.o ./rabit/src/c_api.o -fopenmp -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/xgboost/libs
答案 0 :(得分:1)
@hejseb的评论是正确的。 (Rcpp)Armadillo现在想要在新的编译器上使用OpenMP。
但是客户端软件包需要启用此功能,这意味着他们必须更改他们的文件src/Makevars
才能使用
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
到
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
在编译和链接的客户端软件包中启用OpenMP
例如, forecast
包尚未执行此操作。
您还可以在#define
中设置“全局”~/.R/Makevars
,以便在发现太嘈杂时跳过OpenMP。但是你会在桌面上留下一些表现,这不是一个好的默认值。这就是为什么(Rcpp)Armadillo发表嘈杂的评论。
编辑:您需要为每个C ++方言设置标志,这有一个小麻烦,所以请务必设置CFLAGS
,{{1 },CXXFLAGS
和CXX11FLAGS
。当CXX14FLAGS
工作时,您应该在命令行上看到-fopenmp
。