On Mon, Jan 19, 2004 at 12:19:06PM +0100, Guillot Gilles wrote: > Hi, > > I'm using R 7.0 under Linux as a programming interface to Fortran (g77 > v0.5.24). > 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) ^^^^^^^^^^^
Two errors here: 1. You must allocate memory for x in the calling R function and have x as an argument to 'test' 2. Use double precision ('double' in R) Another recommendation is to write an R package for tasks like yours. It is easier than you may think; see 'Writing R extensions'. Göran > do i=1,n > do j=1,p > x(i,j) = 0 > enddo > enddo > end > > 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") > dyn.load("~/test.so") > out.res<- .Fortran("test", > as.integer(n), > as.integer(p) > ) > > 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. > > > Gilles > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Göran Broström tel: +46 90 786 5223 Department of Statistics fax: +46 90 786 6614 Umeå University http://www.stat.umu.se/egna/gb/ SE-90187 Umeå, Sweden e-mail: [EMAIL PROTECTED] ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html