[Rcpp-devel] R/Rcpp/RcppEigen Optimization WAS: NumericVector Double mismatch when indexing an array

Rodney Sparapani rsparapa at mcw.edu
Tue Oct 23 16:46:43 CEST 2012

On 09/25/2012 04:45 PM, Dirk Eddelbuettel wrote:
> I use and recommend ~/.R/Makevars for that --- as setting certain values at
> the package level is very verboten ("non portable code" and all that) as far
> as CRAN is concerned.
> Now, that's the "how do you" part.  As for "does it matter" that is a
> different beast as -O2 (or better) is already the default for R on my systems
> (running the vanilla Ubuntu packages based on my Debian packaging).
> Dirk

Hi Dirk:

I hope this not too far off-topic.  I don't want to show my messy code,
but I learned a lot about optimization on my own system which I assume
would be useful to others.  I was comparing an MCMC sampler written in
R with a line for line translation via inline/RcppEigen.

So, getting back to this discussion...  "The way" to do this is to
optimize R from the get go and then Rcpp/RcppEigen/etc. inherit the
appropriate switches.  And, as Dirk said, the RPM of R in the repo does
have -O2 (and a bunch of other switches which I don't know anything
about).  However, I found that R in the repo was no faster than my
naive compilation of R from source which did not include -O2 (or any
other black magic).

What gives?  What I found that does speed up the code dramatically
is the -march switch.  I guess that can't be repo-ed because it is
CPU dependent, right?  Here's the important settings that I used to
compile R from source:

CFLAGS="-g -O2 -march=amdfam10"
CXXFLAGS="-g -O2 -march=amdfam10"

With these settings...

MCMC Code	Switches		Relative Time
R		none or -O2		1.0
RcppEigen	none or -O2		0.09
R		-O2 -march=amdfam10	0.5
RcppEigen	-O2 -march=amdfam10	0.013

Rodney Sparapani, PhD  Center for Patient Care and Outcomes Research
Sr. Biostatistician               http://www.mcw.edu/pcor
4 wheels good, 2 wheels better!   Medical College of Wisconsin (MCW)
WWLD?:  What Would Lombardi Do?   Milwaukee, WI, USA

More information about the Rcpp-devel mailing list