Bobert
Bobert

Reputation: 33

Rcpp sourceCpp compiler settings

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!

Upvotes: 3

Views: 995

Answers (2)

user3105691
user3105691

Reputation:

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.

Upvotes: 3

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

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.

Upvotes: 5

Related Questions