[R] memory limitation with Fortran interface

Guillot Gilles Gilles.Guillot at inapg.inra.fr
Mon Jan 19 12:19:06 CET 2004


I'm using R 7.0 under Linux as a programming interface to Fortran (g77 
Basically, what I want to do is to call a fortran subroutine of mine 
which performs MCMC computations.
Apparently I'm getting into memory management problems.

To track the problem I wrote  the following small Fortran subroutine 
(saved as test.f) : 

      subroutine test(n,p)
      implicit none
      integer n,p,i,j
      real x(n,p)
      do i=1,n
         do j=1,p
            x(i,j) = 0

I compiled it by : 
g77 -c test.f

then I called it from R with :

n <- 10000
p <- 1000
system("R CMD SHLIB ~/test.o")
out.res<- .Fortran("test",

causing R breakdown with the following message : 

Segmentation fault

I don't understand why this subroutine causes segmentartion fault 
as its execution requires much less memory than what is existing  on my 
machine (RAM 512 Mo RAM + swap 512 Mo ).

More generally, it seems that memory limitations are stronger
when calling fortran code from R than when executing 
the same Fortran subroutine from a bash command line.


More information about the R-help mailing list