Re: [Rd] Segfault while calling fexact in C

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Fri, 16 Mar 2012 08:06:28 -0400

On 12-03-16 5:27 AM, Nima Mohammadi wrote:
> Hi folks,
> I'm trying to call an R function (fisher.test) in my program for like a
> billion times! Though my program is in Python and I feel that using rpy2 to
> interface R to python doesn't give me satisfactory performance. So I looked
> into R code and found out that fisher.test is actually a wrapper around
> another function called fexact which is implemented in C. Using Cython I
> managed to directly call the function and get the desired results.
> But the weird problem is that after calling the function for like 4000
> times (with same parameters) a segmentation fault occurs! Eliminating the
> possibility that my interfacing code has any problem, I wrote a piece of
> code in C to call the fexact multiple times:

I don't think fexact is mentioned in Rmath.h, so it's not a function designed to be called from a standalone program.

Duncan Murdoch

>
> int main(){
> int nr = 3, nc = 2;
> int x[6] = {3, 1, 5, 1, 3, 6};
> double expect = -1, percnt = 100, emin = 0, prt = 1;
> double p;
> int workspace = 200000, mult = 30;
> int i;
> for (i=0; i<100000; i++){
> fexact(&nr,&nc, x,&nr,&expect,
> &percnt,&emin,&prt,&p,&workspace,&mult);
> printf("%d %f\n", i, p);
> }
> return 0;
> }
>
> I statically linked the program to libRmath, which I don't suppose has
> anything to do with problem. I also dynamically linked to libRmath.so which
> yielded the same problem.
>
> nima_at_nima-laptop:~/BioProject/fet$ gcc -I/usr/share/R/include -lm fexact.c
> /usr/lib/libRmath.a
>
> nima_at_nima-laptop:~/BioProject/fet$ ./a.out
> 0 0.408431
> 1 0.408431
> 2 0.408431
> 3 0.408431
> 4 0.408431
> ....
> ....
> 4003 0.408431
> 4004 0.408431
> 4005 0.408431
> Segmentation fault
>
> Any help would be highly appreciated :)
>
> *-- **Nima Mohammadi*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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 Fri 16 Mar 2012 - 12:08:47 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 Fri 16 Mar 2012 - 18:10:30 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