[Rd] Segfault while calling fexact in C

From: Nima Mohammadi <nima.irt_at_gmail.com>
Date: Fri, 16 Mar 2012 12:57:48 +0330

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:

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 Received on Fri 16 Mar 2012 - 11:34:41 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 - 12:50: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