Openblas,OpenMP和R是否有不错的测试? [英] Openblas, OpenMP, and R is there a decent test?

查看:117
本文介绍了Openblas,OpenMP和R是否有不错的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Openblas和OpenMP设置多线程R.我正在将OpenSuSE 12.2与AMD fx-8230 8核处理器一起使用.与 ATLAS 战斗了一段时间后,建议我将其装好并尝试我拥有的openblas.

I am trying to setup a multithreaded R with Openblas and OpenMP. I am using OpenSuSE 12.2 with an AMD fx-8230 8-core processor. After fighting awhile with ATLAS it was suggested that I bag it and try openblas, which I have.

首先.有一些关于opensuse 12.2 gcc的openmp损坏的报告,所以我认为我应该对其进行测试.我去了 http://openmp.org/wp/openmp-compilers/并进行了编译并在所有线程响应的情况下执行示例文件hello.c.

First. There was some reports of opensuse 12.2 gcc having a broken openmp, so I figured I should test it. I went to http://openmp.org/wp/openmp-compilers/ and compiled and executed the example file hello.c with all threads responding.

第二.我设置了一个openblas的git克隆.我阅读了说明并执行了"make USE_OPENMP = 1",然后执行了"make PREFIX =/usr/lib64/OpenBLAS install".该程序已安装并顺利通过所有检查.

Second. I set up a git clone of openblas. I read the instructions and executed 'make USE_OPENMP=1' followed by 'make PREFIX=/usr/lib64/OpenBLAS install' The program installed and passed all checks with no problem.

第三.设置R.我将R下载为tar文件并解压缩.我最终将签出SubversionR.我使用了此配置命令../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

Third. Setting up R. I downloaded R as a tar file and unpacked. I will eventually check out the subversion R. I used this configure command ../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文件更改为:

The prefix and -with-blas information doesn't make it into the Makeconf file. Why is that? I changed the Makeconf file to:

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)

哪些仍然找不到公开的bla.我建立了指向libopenblas.so.0的/usr/lib64的符号链接,然后找到了openblas.有没有比-I更好的方法来设置包含?也许我没有正确设置include并找不到正确的文件?

Which still couldn't find open blas. I made a symbolic link into /usr/lib64 of libopenblas.so.0 and then openblas was found. Is there a better way than -I to set include? Maybe I am not properly setting include and it is not finding the right files?

此处中使用信息检查了R在/bin/exec/R中找到的库

Using the information here I checked the libraries being found by R in /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和

I expected that it would not find libRblas if it isn't using it. So I found libR.so and

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安装说明,我确实进行了检查(通过)并进行了全部检查并通过了.

Following the rest of the R installation instructions I did make check (passed) make check-all and it passed.

好的,现在是踢球者.我如何测试以确保R确实使用了多个内核.我能够找到在R中进行测试的方案:

Ok, so now's the kicker. How can I test to see that R is indeed using more than one core. I was able to find a scheme for testing in R:

a = matrix(rnorm(5000*5000), 5000, 5000)
b = matrix(rnorm(5000*5000), 5000, 5000)
c = a%*%b

然后使用"top"检查cpu.我这样做了,但是它从来没有超过cpu的100.1%!这让我很伤心.我确实看到我在运行make-all时发现,在测试示例时,有时有超过250%的cpu使用率,这使我认为它正在运行,而我却忘记了一些东西.在我的个人资料中,我设置了'export OMP_NUM_THREADS = 8'和'export OPEN_BLAS_NUM_THREADS = 8'这是否意味着openblas无法与openmp一起使用,我该如何解决?

Then check cpu with 'top'. I did this, but it never used more than 100.1% of a cpu! This made me pretty sad. I did see when I was running make-all that when the examples were being tested that there was sometimes more than 250% cpu usage which makes me think that it is working and I am forgetting something. In my profile I set 'export OMP_NUM_THREADS=8' and 'export OPEN_BLAS_NUM_THREADS=8' Does this mean that openblas is not working with openmp and how can I fix it?

此服务器实际上没有设置任何东西,如果我回显$ LD_LIBRARY_PATH,则什么也没有发生,所以也许我需要在其中设置一些东西,以便每个人一起工作吗?我最终的目标是安装Boost库,snow和spp.有没有人有在R程序包中使用snow设置openmp的经验,会起作用吗?

This server doesn't really have anything set, if I echo $LD_LIBRARY_PATH nothing comes up, so maybe there is something that I need to set there in order for everyone to work together? My eventual goal is to install the boost libraries, snow and spp. Does anyone have experience setting up openmp with snow in the R package, will it work?

推荐答案

首先要弄清的是

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

  • the optimized BLAS is used at all
    OpenBLAS is already with NUM_TREADS=1 much faster than the default BLAS. Check the times of the m %*% m multiplication.

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

Once you know that OpenBLAS is used, check the number of threads spawned (top or htop)

如果使用优化的BLAS,则会生成NUM_TREADS线程,但所有线程都在同一内核上执行,请参见此处:

If the optimized BLAS is used, NUM_TREADS threads are spawned but get all executed on the same core, see here: Parallel processing in R limited

这篇关于Openblas,OpenMP和R是否有不错的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆