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@nima-laptop:~/BioProject/fet$ gcc -I/usr/share/R/include -lm fexact.c
/usr/lib/libRmath.a

nima@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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to