Openblas,OpenMP和R是否有一个不错的测试?

时间:2013-04-07 21:42:50

标签: r openmp

我正在尝试使用Openblas和OpenMP设置多线程R.我正在使用OpenSuSE 12.2和AMD fx-8230 8核处理器。在与ATLAS进行了一段时间的战斗之后,有人建议我把它包起来并尝试使用openblas。

首先。有一些报道说opencc 12.2 gcc有一个破碎的openmp,所以我想我应该测试一下。我去了http://openmp.org/wp/openmp-compilers/并编译并执行了所有线程响应的示例文件hello.c。

二。我设置了openblas的git clone。我阅读说明并执行'make USE_OPENMP = 1',然后执行'make PREFIX = / usr / lib64 / OpenBLAS install'安装程序并通过所有检查没有问题。

第三。设置R.我将R作为tar文件下载并解压缩。我最终会查看subversion R.我使用了这个configure命令../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设置包含更好的方法?也许我没有正确设置包含,而且找不到合适的文件?

使用信息here我在/ bin / exec / R中检查了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-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时,在测试示例时,有时超过250%的cpu使用率让我认为它正在工作而我忘了一些东西。在我的个人资料中,我设置'export OMP_NUM_THREADS = 8'和'export OPEN_BLAS_NUM_THREADS = 8'这是否意味着openblas不能使用openmp,我该如何修复它?

这个服务器实际上没有设置任何东西,如果我回显$ LD_LIBRARY_PATH没有出现,所以也许我需要设置一些东西才能让每个人一起工作?我最终的目标是安装boost库,snow和spp。有没有人有经验在R套件中设置带雪的openmp,它会起作用吗?

2 个答案:

答案 0 :(得分:1)

首先要找出的是

  • 全部使用优化的BLAS OpenBLAS已经使NUM_TREADS=1比默认BLAS快得多。检查m %*% m乘法的时间。

  • 一旦您知道使用了OpenBLAS,请检查产生的线程数(tophtop

  • 如果使用优化的BLAS,则会生成NUM_TREADS个线程,但会在同一个核心上执行所有线程,请参见此处:Parallel processing in R limited

答案 1 :(得分:0)

切换到OpenBLAS没有看到预期性能提升的问题可能与处理器关联性有关。来自OpenBLAS Github:

“在Linux上,OpenBLAS默认设置处理器关联。这可能会导致与R parallel的冲突。您可以使用NO_AFFINITY = 1构建库。”

使用NO_AFFINITY = 1标志进行编译,禁用处理器关联。

https://stat.ethz.ch/pipermail/r-sig-hpc/2012-April/001348.html