[Rd] dmvnorm

Simon Urbanek simon.urbanek at r-project.org
Mon Jun 10 14:18:30 CEST 2013


On Jun 6, 2013, at 2:06 AM, Joshua N Pritikin wrote:

> Summary:
> 
> + I am writing an R extension that needs to call dmvnorm more than 
> 10,000 times during a model fitting computation.
> 
> + My extension uses openmp for parallel execution.
> 
> + As of R 3.0, it is no longer permitted for threads to call the R 
> interpreter because there is a stack overflow check that always trips 
> because the thread's stack is different from what R is expecting.
> 

You can call the interpreter from threads, you just have to make sure your access is properly synchronized and you disable the stack check. This is not new on R 3.0, this was always the case. However this is irrelevant to what you are describing above, because it doesn't make any sense to serial code in OpenMP.


> + Therefore, I need a C version of dmvnorm.
> 

C version alone is not sufficient, if you want to use it in threads, you would need a thread-safe version. This means that you really need your own version, so I don't think adding C version of dmvnorm to R has necessarily any bearing to what you are trying to do.

Cheers,
Simon



> + The mvtnorm package maintainer is not interested in 
> R_RegisterCCallable.
> 
> Can a C version of dmvnorm get added to the R core?
> 
> -- 
> Joshua N. Pritikin
> Department of Psychology
> University of Virginia
> 485 McCormick Rd, Gilmer Hall Room 102
> Charlottesville, VA 22904
> http://people.virginia.edu/~jnp3bc
> 
> From: Torsten Hothorn <Torsten.Hothorn at uzh.ch>
> Date: June 5, 2013 9:26:03 AM EDT
> To: Joshua N Pritikin <jpritikin at pobox.com>
> Subject: Re: dmvnorm
> 
> 
> 
> On Mon, 3 Jun 2013, Joshua N Pritikin wrote:
> 
>> On Mon, Jun 03, 2013 at 03:24:54PM +0200, Torsten Hothorn wrote:
>>> On Sat, 1 Jun 2013, Joshua N Pritikin wrote:
>>>> On Fri, May 31, 2013 at 07:22:52PM +0200, Torsten Hothorn wrote:
>>>>> - what exactly is the advantage of using C? How much time / memory can be
>>>>> saved?
>>>> 
>>>> I bet the difference will only appear in micro-benchmarks. There is
>>>> probably no real world impact.
>>>> 
>>>> As I said, the main reason I wrote this is because I need to call
>>>> dmvnorm from C.
>>> 
>>> I see -- so now that you have the C code ready, why do we need it to
>>> be part of mvtnorm?
>> 
>> I want to share. What if somebody else has the same need?
> 
> sure, but interfacing C code from other packages is always troublesome (at least this is my experience). I can't see any advantage for mvtnorm, so I think one should put the code somewhere else.
> 
>> 
>> Should I submit it to the R core?
>> 
> 
> I suggest that, yes. Maybe R core is keen to add the multivariate normal density to R's C API. This would be the easiest way to make your code accessible.
> 
> Best,
> 
> Torsten
> 
>> -- 
>> Joshua N. Pritikin
>> Department of Psychology
>> University of Virginia
>> 485 McCormick Rd, Gilmer Hall Room 102
>> Charlottesville, VA 22904
>> http://people.virginia.edu/~jnp3bc
>> 
> 
> 
> <dmvnorm.patch>______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list