设置“配置” R 中的 openMP
我有一个 R 包,可以通过使用 OpenMP 轻松加速。如果您的编译器支持它,那么您就获胜了,如果不支持,那么编译指示将被忽略,您将获得一个核心。
我的问题是如何让包构建系统使用正确的编译器选项和库。目前我已经:
PKG_CPPFLAGS=-fopenmp
PKG_LIBS=-fopenmp
硬编码到我的机器上的 src/Makevars 中,并且使用 OpenMP 支持构建它。但它会在检查时生成有关非标准编译器标志的警告,并且在没有 openMP 功能的机器上可能会严重失败。
解决方案似乎是使用configure和autoconf。这里有一些信息:
http://cran.r -project.org/doc/manuals/R-exts.html#Using-Makevars
包括一个在 odbc 功能中编译的复杂示例。但我不知道如何开始调整它来检查 openmp 和 libgomp。
我看过的有关使用 openMP 的 R 软件包似乎都没有进行此设置。
那么有人有使用 OpenMP 设置 R 包的演练吗?
[编辑]
我现在可能已经破解了这个。我有一个configure.ac 脚本和一个Makevars.in,其中@FOO@ 替换了编译器选项。但现在我不确定工作流程。是吗:
- 如果我更改configure.in文件,请运行“autoconf configure.in > configure; chmod 755 configure”。
- 进行包构建。
- 在软件包安装时,系统为我运行 ./configure 并从 Makevars.in 创建 Makevars
但需要明确的是,“autoconf configure.in > configure”不会在软件包安装时运行 - 它纯粹是一个开发人员过程来创建配置分布式脚本 - amirite?
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
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.
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
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.
None of the R packages I've looked at that talk about using openMP seem to have this set up either.
So does anyone have a walkthrough for setting up an R package with OpenMP?
[EDIT]
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:
- Run "autoconf configure.in > configure; chmod 755 configure" if I change the configure.in file.
- Do a package build.
- On package install, the system runs ./configure for me and creates Makevars from Makevars.in
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的库选项错误,请尝试
换句话说,
-lgomp
为您提供了链接的 OpenMP 库。我想您知道这个库不是流行的 Windows Rtools 套件的一部分。在现代 Linux 上你应该没问题。在我这里的未发布测试包中,我还将以下内容添加到 PKG_LIBS 中,但这主要是由于我使用了 Rcpp:
最后,我认为 autoconf 业务并不是真正需要的,除非您觉得需要通过配置测试 OpenMP。
编辑: SpacedMan 是正确的。根据 libgomp-4.4 手册的开头:
所以我纠正了。似乎手动添加无论如何都会添加的内容并没有什么坏处,只是为了清楚起见......
Methinks you have the library option wrong, please try
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.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:Lastly, I think the autoconf business is not really needed unless you feel you need to test for OpenMP via configure.
Edit: SpacedMan is correct. Per the beginning of the libgomp-4.4 manual:
So I stand corrected. Seems that it doesn't hurt to manually add what would get added anyway, just for clarity...
只是解决有关 autoconf 使用的问题 - 不,您不想使用任何参数运行 autoconf,也不应该重定向其输出。您是正确的,运行 autoconf 来构建配置脚本是软件包维护者所做的事情,并且生成的配置脚本已分发。通常,要从configure.ac(较旧的软件包使用名称configure.in,但该名称多年来一直不鼓励使用)生成配置脚本,开发人员只需运行不带参数的autoconf。在运行 autoconf 之前,需要运行 aclocal、autoheader、libtoolize 等...还有一个工具(autoreconf)可以简化流程并以正确的顺序调用所有必需的程序。现在更典型的是运行 autoreconf 而不是 autoconf。
Just addressing your question regarding the usage of autoconf--no, you do not want to run autoconf with any arguments, nor should you redirect its output. You are correct that running autoconf to build the configure script is something that the package maintainer does, and the resulting configure script is distributed. Normally, to generate the configure script from configure.ac (older packages use the name configure.in, but that name has been discouraged for several years), the developer simply runs autoconf with no arguments. Before running autoconf, it is necessary to run aclocal, autoheader, libtoolize, etc... There is also a tool (autoreconf) which simplifies the process and invokes all the required programs in the correct order. It is now more typical to run autoreconf instead of autoconf.