[R] fastest R platform
M. Edward (Ed) Borasky
znmeb at aracnet.com
Mon Apr 9 15:15:25 CEST 2001
On 9 Apr 2001, Douglas Bates wrote:
> "M. Edward Borasky" <znmeb at aracnet.com> writes:
> > Once you've isolated the spots that are being executed most often, try
> > replacing scalar operations with vector operations and vector operations
> > with matrix operations. These are usually translated fairly efficiently by
> > modern compilers, and special assembler level packages can be found for
> > things like the Basic Linear Algebra Subroutines (BLAS).
>
> Profiling the R code can help in isolating the parts that are taking
> the most time. See the "Writing R Extensions" manual for details on
> how to do this.
Thanks!! I thought I saw something about profiling in the documentation and
was going to suggest it, but I couldn't remember where it was. I did an
'apropos ("profile")' and didn't come up with what I was looking for, so I
didn't say anything.
Given that the original poster re-wrote the outer product routine, he must have
found it a significant user of time. Outer products are easy to vectorize, at
least for largeish matrices. The trick is to have the longest dimension in
the innermost loop if possible, and then use an efficient vector - scalar
multiply. There are lots of other games you can play on machines like the
Pentium to keep numbers in the cache. Loop unrolling is another strategy to
pursue.
I used to do a *lot* of this sort of thing when I worked for Floating Point
Systems. Much of this knowledge is *in theory* embedded in today's FORTRAN
and C compilers, but I have no idea how good or bad the Gnu Compiler Collection
is in this respect. As an aside, I noticed when I did a batch build of all the
contributed packages that one of them, "Matrix", failed looking for the BLAS
in the library. That didn't seem relevant to the list, and I haven't had a
chance to dig into it further. I had assumed that the BLAS were embedded
somewhere in GCC or R, given the amount of FORTRAN and C code that are involved.
If enough of you are interested in this sort of thing, I'll post some more notes
on the "tricks of the trade" in speed-tuning FORTRAN and C. I've seen factor of
three speedups and even more *without going to assembler code*.
--
znmeb at aracnet.com (M. Edward Borasky) http://www.aracnet.com/~znmeb
I brought my inner child to "Take Your Child To Work Day."
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list