R中的C ++编译标志的替代系统默认值 [英] Overriding system defaults for C++ compilation flags from R

查看:75
本文介绍了R中的C ++编译标志的替代系统默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RcppEigen为我的R代码编写一些C ++函数,并且我想尽可能地优化它们的编译。过去使用Eigen时,我从-O3和-fopenmp获得了巨大的进步。遵循Dirk的建议,我对〜/ .R / Makevars进行了编辑,以便我的本征代码能够可以使用以下标志进行编译:

I'm using RcppEigen to write some C++ functions for my R code, and I'd like to optimize their compilation as much as possible. When I've used Eigen in the past, I've gotten a significant boost from -O3 and -fopenmp. Following Dirk's advice, I edited ~/.R/Makevars so that my Eigen code would be compiled with these flags:

CPPFLAGS=-O3 -fopenmp

这有效-当我检查编译期间发生的情况时(ps ax | grep cpp),我看到:

This works--when I check what's happening during compilation (ps ax | grep cpp) I see:

27097 pts/6    R+     0:00 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1plus -quiet -I/usr/include/R -I/home/sf/R/x86_64-redhat-linux-gnu-library/3.0/Rcpp/include -I/home/sf/R/x86_64-redhat-linux-gnu-library/3.0/RcppEigen/include -D_GNU_SOURCE -D_REENTRANT -DNDEBUG -D_FORTIFY_SOURCE=2 file69b757e053ad.cpp -quiet -dumpbase file69b757e053ad.cpp -m64 -mtune=generic -auxbase-strip file69b757e053ad.o -g -O3 -O2 -Wall -fopenmp -fpic -fexceptions -fstack-protector --param ssp-buffer-size=4 -o -

我想要的标志在那里-O3和-fopenmp。但是我也看到了-O2,这大概是系统范围的默认值(我通过删除〜/ .R / Makevars验证了这一点,实际上-O2在那里,但-O3和-fopenmp不在。)

The flags I wanted are there, -O3 and -fopenmp. But I also see -O2 there, which is presumably the system-wide default (I verified this by removing ~/.R/Makevars and indeed, -O2 is there but -O3 and -fopenmp are not.)

那么问题是:如何摆脱-O2?还是真的重要吗? g ++手册页显示:

So the question: how do I get rid of the -O2? Or, does it actually matter? The g++ man page says:

   -O3 Optimize yet more.  -O3 turns on all optimizations specified by -O2 and also 
   turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse- 
   after-reload, -ftree-vectorize and -fipa-cp-clone options.

那么同时拥有-O2和-O3也许很好吗?

So maybe it's fine to have both -O2 and -O3?

推荐答案

我认为您需要 CXXFLAGS 而不是 CPPFLAGS 在您的〜/ .R / Makevars

I think you need CXXFLAGS not CPPFLAGS in your ~/.R/Makevars

我在以下回购中设置了Makevars,以在其中测试各种C ++编译器标志R / Rcpp
https://github.com/jackwasey/optimization-comparison

I set Makevars in the following repo to benchmark various C++ compiler flags in R/Rcpp https://github.com/jackwasey/optimization-comparison

我使用 https://github.com/中的函数jimhester / covr 以编程方式执行此操作(如果对您有用)。

I use a function from https://github.com/jimhester/covr to do that programmatically, if that's of use to you.

此外,您是否看到以下内容? R:使用嵌入式程序包时的C ++优化标志

Also, did you see the following? R: C++ Optimization flag when using the inline package

这篇关于R中的C ++编译标志的替代系统默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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