Re: [Rd] Performance of .C and .Call functions vs. native R code

From: Jeff Ryan <jeff.a.ryan_at_gmail.com>
Date: Thu, 14 Jul 2011 07:12:32 -0500

The .Call overhead isn't the issue. If you'd like some insight into what you are doing wrong (and right), you need to provide code for the list to reproduce your timings with.

This is outlined in the posting guide as well.

Best,
Jeff

On Jul 13, 2011, at 8:28 AM, asmahani <alireza.s.mahani_at_gmail.com> wrote:

> Hello,
>
> I am in the process of writing an R extension for parallelized MCMC, with
> heavy use of compiled code (C++). I have been getting my feet wet by
> implementing a simple matrix-vector multiplication function in C++ (which
> calls a BLAS level 2 function dgemv), and comparing it to the '%*%' operator
> in R (which apparently calls a BLAS level 3 function dgemm).
>
> Interestingly, I cannot replicate the performance of the R native operator,
> using either '.C' or '.Call'. The relative times are 17 (R), 30 (.C), and 26
> (.Call). In other words, R native operator is 1.5x faster than my compiled
> code. Can you explain to me why this is? Through testing I strongly suspect
> that the BLAS function itself isn't what takes the bulk part of the time,
> but perhaps data transfer and other overhead associated with the calls (.C
> and .Call) are the main issues. Are there any ways to reach the performance
> level of native R code in this case?
>
> Thank you,
> Alireza Mahani
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Performance-of-C-and-Call-functions-vs-native-R-code-tp3665017p3665017.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 14 Jul 2011 - 12:12:42 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 14 Jul 2011 - 16:10:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive