[Bioc-devel] R_CheckUserInterrupt guidelines (was Re: R_CheckUserInterrupt in IRanges)
Wolfgang Huber
whuber at embl.de
Tue Jan 12 00:59:11 CET 2010
Hi Seth
Yes. I would hope that someone who goes to the trouble of writing C code
understands that.
Best wishes
Wolfgang
Seth Falcon wrote:
> On 1/11/10 1:31 PM, Patrick Aboyoun wrote:
>> I just modified the C or Fortran code section of package guidelines to
>> reflect this new entry:
>>
>> http://wiki.fhcrc.org/bioc/Package_Guidelines#c-or-fortran-code
>
> This looks reasonable.
>
> It is worth noting, however, that calling R_CheckUserInterrupt is not
> entirely free. If you have a tight loop it might make more sense to
> check at intervals rather than each time through and the choice of when
> to check will depend very much on the computation.
>
> Here's an example using the inline package (code is at the bottom) with
> a silly double loop to compare checking vs not:
>
> With R_CheckUserInterrupt inner loop:
>
> > system.time(z <- funx(10000L, TRUE))
> user system elapsed
> 1.310 0.001 1.313
>
> No checking:
>
> system.time(z <- funx(10000L, FALSE))
> user system elapsed
> 0.08 0.00 0.08
>
> Now this may be completely unrealistic, but I suspect that a sensible
> take away message is that we should be making sure our C code that loops
> does call R_CheckUserInterrupt, but depending on the computation, not at
> every loop iteration.
>
> + seth
>
>
> ## example code is below.
>
> library("inline")
>
> code <- "
> int i, j, sum = 0, int n = INTEGER(max)[0];
> int check_inter = LOGICAL(do_check)[0];
> SEXP ans;
> PROTECT(ans = allocVector(INTSXP, n));
> for (i = 0; i < n; i++) {
> INTEGER(ans)[i] = i;
> for (j = 0; j < n; j++) {
> sum = i + j;
> if (check_inter) {
> R_CheckUserInterrupt();
> }
> }
> }
> UNPROTECT(1);
> return ans;
> "
>
> funx <- cfunction(signature(max="integer", do_check="logical"), code)
>
> system.time(z <- funx(10000L, TRUE))
> system.time(z <- funx(10000L, FALSE))
>
>
--
Best wishes
Wolfgang
--
Wolfgang Huber
EMBL
http://www.embl.de/research/units/genome_biology/huber/contact
More information about the Bioc-devel
mailing list