Rcpp sourceCpp compiler settings

烈酒焚心 提交于 2019-12-11 03:08:53

问题


I am using Rcpp to speed up a function that gets called repeatedly in R (3.4, Windows7) and I was hoping to change the compiler settings.

When I call: sourceCpp("scoreseq1.1.cc", verbose=TRUE)

Part of the output reads:

C:/RBuildTools/3.4/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-34~1.1/include" -O2 -Wall -mtune=core2 -c scoreseq1.1.cc -o scoreseq1.1.o

I would like to change -mtune to haswell, and -O2 to -O3 in search of some performance improvements.

Is there a way to do that through the sourceCpp or cppFunction, do I need a special header in my.cc file, or do I need to I need to modify some file on my system (and if so, what file?!)

Thanks!


回答1:


No, you can't (easily), and in general not from a function.

These settings are "fixed" from when R itself is built. You can edit the file -- but you will have to so each time R is rebuilt / reinstalled.

On my box the file is $(R RHOME)/etc/Makeconf.




回答2:


Just in case someone has a similar problem. You can do this in your C++ source. The following overrides command-line compiler settings:

void
__attribute__((optimize("-O3"),target("tune=haswell")))
foo() 
{
    // your code goes here
}

For reference take a look at: https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html.



来源:https://stackoverflow.com/questions/48917107/rcpp-sourcecpp-compiler-settings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!