设置“配置".用于R中的openMP [英] Setting up "configure" for openMP in R

查看:284
本文介绍了设置“配置".用于R中的openMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个R软件包,可以使用OpenMP轻松加速.如果您的编译器支持它,那么您将获胜;如果不支持,则将忽略实用程序,您将获得一个核心.

I have an R package which is easily sped up by using OpenMP. If your compiler supports it then you get the win, if it doesn't then the pragmas are ignored and you get one core.

我的问题是如何使程序包构建系统使用正确的编译器选项和库.目前,我有:

My problem is how to get the package build system to use the right compiler options and libraries. Currently I have:

PKG_CPPFLAGS=-fopenmp
PKG_LIBS=-fopenmp

被硬编码到我的机器上的src/Makevars中,并且使用OpenMP支持来构建它.但是它会在检查时产生有关非标准编译器标志的警告,并且可能在没有openMP功能的计算机上严重失败.

hardcoded into src/Makevars on my machine, and this builds it with OpenMP support. But it produces a warning about non-standard compiler flags on check, and will probably fail hard on a machine with no openMP capabilities.

解决方案似乎是使用configure和autoconf.这里有一些信息:

The solution seems to be to use configure and autoconf. There's some information around here:

http://cran.r-project. org/doc/manuals/R-exts.html#Using-Makevars

包括一个复杂的示例,可在odbc功能中进行编译.但是我看不到如何开始进行调整以检查openmp和libgomp.

including a complex example to compile in odbc functionality. But I can't see how to begin tweaking that to check for openmp and libgomp.

我看过的有关使用openMP的R软件包似乎都没有进行设置.

None of the R packages I've looked at that talk about using openMP seem to have this set up either.

那么有没有人介绍如何使用OpenMP设置R软件包?

So does anyone have a walkthrough for setting up an R package with OpenMP?

我现在可能已经破解了.我有一个configure.ac脚本和一个带有@ FOO @替代项的Makevars.in作为编译器选项.但是现在我不确定工作流程.是吗?

I may have cracked this now. I have a configure.ac script and a Makevars.in with @FOO@ substitutions for the compiler options. But now I'm not sure of the workflow. Is it:

  • 如果我更改configure.in文件,请运行"autoconf configure.in> configure; chmod 755 configure".
  • 进行程序包构建.
  • 在安装软件包时,系统会为我运行./configure并从Makevars.in中创建Makevars.

但要清楚一点,"autoconf configure.in> configure"不会在软件包安装中运行-它纯粹是开发人员过程,用于创建 分发的配置脚本-amirite?

But just to be clear, "autoconf configure.in > configure" doesn't run on package install - its purely a developer process to create the configure script that is distributed - amirite?

推荐答案

认为您的库选项错误,请尝试

Methinks you have the library option wrong, please try

## -- compiling for OpenMP 
PKG_CXXFLAGS=-fopenmp
##
## -- linking for OpenMP
PKG_LIBS= -fopenmp -lgomp 

换句话说,-lgomp使您链接到OpenMP库.而且我想您知道该库不是流行的Windows Rtools套件的一部分.在现代Linux上,您应该没事.

In other words, -lgomp gets you the OpenMP library linked. And I presume you know that this library is not part of the popular Rtools kit for Windows. On a modern Linux you should be fine.

在一个未发布的测试包中,我还将以下内容添加到PKG_LIBS中,但这主要是由于我使用了Rcpp:

In an unrelease testpackage I have here I also add the following to PKG_LIBS, but that is mostly due to my use of Rcpp:

$(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") \
                              $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

最后,我认为除非您需要通过configure测试OpenMP,否则并不需要autoconf业务.

Lastly, I think the autoconf business is not really needed unless you feel you need to test for OpenMP via configure.

SpacedMan是正确的.按照libgomp-4.4手册的开头:

SpacedMan is correct. Per the beginning of the libgomp-4.4 manual:

1启用OpenMP

激活以下各项的OpenMP扩展名: C/C ++和Fortran,编译时 必须指定标志"-fopenmp". 这将启用OpenMP指令 [...]旗帜也 安排自动链接 OpenMP运行时库.

1 Enabling OpenMP

To activate the OpenMP extensions for C/C++ and Fortran, the compile-time flag `-fopenmp' must be specified. This enables the OpenMP directive [...] The flag also arranges for automatic linking of the OpenMP runtime library.

所以我站得住脚了.似乎为了手动起见,手动添加将要添加的内容并没有什么害处...

So I stand corrected. Seems that it doesn't hurt to manually add what would get added anyway, just for clarity...

这篇关于设置“配置".用于R中的openMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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