我正在尝试使用 Openblas 和 OpenMP 设置多线程 R。我正在使用带有 AMD fx-8230 8 核处理器的 OpenSuSE 12.2。在与ATLAS战斗了一段时间后,有人建议我将它打包并尝试我拥有的 openblas。
第一的。有一些关于 opensuse 12.2 gcc 的 openmp 损坏的报告,所以我想我应该对其进行测试。我去了http://openmp.org/wp/openmp-compilers/并编译并执行了示例文件 hello.c,所有线程都有响应。
第二。我设置了一个 openblas 的 git 克隆。我阅读了说明并执行了“make USE_OPENMP=1”,然后执行了“make PREFIX=/usr/lib64/OpenBLAS install”程序安装并通过了所有检查,没有任何问题。
第三。设置 R。我将 R 下载为 tar 文件并解压缩。我最终会检查 subversion R。我使用了这个配置命令../configure --prefix=/usr/lib64/R --enable-openmp --enable-R-shlib --with-blas="-L/opt/maths/OpenBLAS -lopenblas" --with-tcl-config=/usr/lib64/tclConfig.sh --with-tk-config=/usr/lib64/tkConfig.sh --with-x
前缀和 -with-blas 信息不会进入 Makeconf 文件。这是为什么?我将 Makeconf 文件更改为:
PACKAGE = R
VERSION = 2.15.3
abs_top_srcdir = /opt/maths/R-2.15.3/gserver/..
abs_top_builddir = /opt/maths/R-2.15.3/gserver
include $(top_srcdir)/share/make/vars.mk
AR = ar
ACLOCAL = aclocal
AUTOCONF = autoconf
AUTOMAKE = automake
AUTOHEADER = autoheader
BLAS_LIBS = -L/opt/maths/OpenBLAS/ -lopenblas
BUILDDIR_IS_SRCDIR = no
## next two for future support of cross-compiling, not actually used
BUILD_CC =
BUILD_R =
CC = gcc -std=gnu99
CFLAGS = -g -O2 -fopenmp
CPICFLAGS = -fpic
CPPFLAGS = -I/usr/include
DEFS = -DHAVE_CONFIG_H
DISTDIR_TAR_EXCLUDE = --exclude=.svn --exclude=Makefile --exclude="*.o" --exclude="*$(SHLIB_EXT)" --exclude="*~"
DYLIB_EXT = .so
DYLIB_LD = gcc -std=gnu99
DYLIB_LDFLAGS = -shared -fopenmp# $(DYLIBS_LTO)
DYLIB_LINK = $(DYLIB_LD) $(DYLIB_LDFLAGS) $(LDFLAGS)
DYLIBS_LTO = $(CFLAGS) $(CPICFLAGS)
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
FFLAGS = -g -O2 -fopenmp
FLIBS = -lgfortran -lm -lquadmath
FLIBS_IN_SO = -lgfortran -lm -lquadmath
FPICFLAGS = -fpic
F77 = gfortran
GETWD = /usr/bin/pwd
GZIP = --best
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_DIR = ${INSTALL} -d
LDFLAGS = -L/usr/lib64
LIBINTL=
LIBM = -lm
LIBR = -L$(R_HOME)/lib$(R_ARCH) -lR
LIBS = -lrt -ldl -lm
LIBnn = lib64
LIBTOOL = $(SHELL) $(top_builddir)/libtool
## AFAICS unused
LN_S = ln -s
MAIN_CFLAGS =
MAIN_FFLAGS =
MAIN_LD = gcc -std=gnu99# $(CFLAGS)
MAIN_LDFLAGS = -Wl,--export-dynamic -fopenmp # # -Wl,-bE:$(top_builddir)/etc/R.exp
MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
## need this for bootstrapping
MKINSTALLDIRS = /bin/sh $(top_srcdir)/src/scripts/mkinstalldirs.in
NOTANGLE = false
R_ARCH =
R_FRAMEWORK_DIR = $(prefix)/R.framework
R_GZIPCMD = /usr/bin/gzip
## needed for AIX only
# R_HOME = $(top_builddir)
R_OPENMP_CFLAGS = -fopenmp
R_OPENMP_FFLAGS = -fopenmp
R_OSTYPE = unix
R_PKGS = $(R_PKGS_BASE) $(R_PKGS_RECOMMENDED)
R_PLATFORM = x86_64-unknown-linux-gnu
R_XTRA_CFLAGS =
R_XTRA_CPPFLAGS = -I. -I$(top_builddir)/src/include -I$(top_srcdir)/src/include
R_XTRA_FFLAGS =
R_XTRA_LIBS =
RANLIB = ranlib
READLINE_LIBS = -lreadline
SED = /usr/bin/sed
SHELL = /bin/sh
SHLIB_EXT = .so
SHLIB_CFLAGS =
SHLIB_FFLAGS =
SHLIB_LD = gcc -std=gnu99
SHLIB_LDFLAGS = -shared# $(SHLIB_LTO)
SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LDFLAGS)
SHLIB_LTO = $(CFLAGS) $(CPICFLAGS)
STRIP_LIBS = strip --strip-unneeded
STRIP_STATIC_LIBS = strip --strip-debug
TAR = /bin/tar
USE_NLS = yes
X_CFLAGS =
X_LIBS = -lX11 -lXt -lXmu
X_PRE_LIBS = -lSM -lICE
X_EXTRA_LIBS =
YACC = bison -y
ALL_CFLAGS = $(R_XTRA_CFLAGS) $(R_OPENMP_CFLAGS) $(MAIN_CFLAGS) $(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(CPPFLAGS) $(DEFS)
ALL_FFLAGS = $(R_XTRA_FFLAGS) $(R_OPENMP_FFLAGS) $(MAIN_FFLAGS) $(FFLAGS)
ALL_CFLAGS_LO = $(R_XTRA_CFLAGS) $(R_OPENMP_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
ALL_FFLAGS_LO = $(R_XTRA_FFLAGS) $(R_OPENMP_FFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) $(FFLAGS)
.SUFFIXES:
.SUFFIXES: .c .f .m .d .o
.c.o:
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
.c.d:
@echo "making $@ from $<"
@gcc -std=gnu99 -MM $(ALL_CPPFLAGS) $< > $@
.m.d:
@echo > $@
.f.o:
$(F77) $(ALL_FFLAGS) -c $< -o $@
prefix = /usr/lib64/R
exec_prefix = ${prefix}
datarootdir = ${prefix}/share
## only used for installing 'R'.
bindir = ${exec_prefix}/bin
## not used
datadir = ${datarootdir}
## used for 'rhome' and installation of standalone Rmath
libdir = ${exec_prefix}/${LIBnn}
## used for man page
mandir = ${datarootdir}/man
## used for installation of standalone Rmath headers
includedir = ${prefix}/include
rhome = ${libdir}/R
rsharedir = ${rhome}/share
rincludedir = ${rhome}/include
rdocdir = ${rhome}/doc
## Overrides for installing R as a framework (MacOS X).
#FW_VERSION =
#rhome = $(R_FRAMEWORK_DIR)/Versions/$(FW_VERSION)/Resources
#bindir = $(rhome)
#mandir = $(rhome)
Rexecbindir = $(rhome)/bin
Rexecbindir2 = $(rhome)/bin/exec$(R_ARCH)
Rexeclibdir = $(rhome)/lib$(R_ARCH)
## FIXME:
## Alternatively, we could try to set pkglibdir = $(rhome)/lib when
## switching to automake.
## </FIXME>
Rexecmodulesdir = $(rhome)/modules$(R_ARCH)
仍然找不到打开的 blas。我在 libopenblas.so.0 的 /usr/lib64 中建立了一个符号链接,然后找到了 openblas。有没有比 -I 设置包含更好的方法?也许我没有正确设置包含并且没有找到正确的文件?
使用此处的信息,我检查了 R 在 /bin/exec/R 中找到的库
gserver/bin/exec # ldd R
linux-vdso.so.1 (0x00007fff4b278000)
libR.so => not found
libRblas.so => not found
libgomp.so.1 => /usr/lib64/libgomp.so.1 (0x00007f2cb3e00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2cb3be0000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2cb3830000)
librt.so.1 => /lib64/librt.so.1 (0x00007f2cb3628000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2cb4010000)
我预计如果它不使用它,它不会找到 libRblas。所以我找到了 libR.so 和
gserver/lib # ldd libR.so
linux-vdso.so.1 (0x00007fffaf360000)
libopenblas.so.0 => /usr/lib64/libopenblas.so.0 (0x00007fe131158000)
libgfortran.so.3 => /usr/lib64/libgfortran.so.3 (0x00007fe130e40000)
libm.so.6 => /lib64/libm.so.6 (0x00007fe130b40000)
libquadmath.so.0 => /usr/lib64/libquadmath.so.0 (0x00007fe130908000)
libreadline.so.6 => /lib64/libreadline.so.6 (0x00007fe1306c0000)
librt.so.1 => /lib64/librt.so.1 (0x00007fe1304b8000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fe1302b0000)
libgomp.so.1 => /usr/lib64/libgomp.so.1 (0x00007fe1300a0000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe12fe80000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe12fad0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe132610000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fe12f8b8000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fe12f680000)
按照 R 安装说明的其余部分,我做了 make check(通过) make check-all 并且它通过了。
好的,现在是踢球者。我如何测试以查看 R 确实使用了多个内核。我能够找到在 R 中进行测试的方案:
a = matrix(rnorm(5000*5000), 5000, 5000)
b = matrix(rnorm(5000*5000), 5000, 5000)
c = a%*%b
然后用'top'检查cpu。我这样做了,但它从未使用超过 100.1% 的 cpu!这让我很伤心。我确实在运行 make-all 时看到,在测试示例时,有时 CPU 使用率超过 250%,这让我认为它正在工作并且我忘记了一些东西。在我的个人资料中,我设置了“export OMP_NUM_THREADS=8”和“export OPEN_BLAS_NUM_THREADS=8”这是否意味着 openblas 不能与 openmp 一起使用,我该如何解决?
这个服务器并没有真正设置任何东西,如果我回显 $LD_LIBRARY_PATH 什么都没有出现,那么也许我需要在那里设置一些东西才能让每个人一起工作?我的最终目标是安装 boost 库、snow 和 spp。有没有人有在 R 包中用雪设置 openmp 的经验,它会工作吗?