[R] seg fault ==> Use more heap memory (R --vsize ...)

Martin Maechler maechler at stat.math.ethz.ch
Fri Mar 5 17:54:05 CET 1999

Lorenz, I've used your example code, somewhat ``improved'' by diagnostic

    library ("modreg")
    .Random.seed <- 0:3
    n <- 500

    while (TRUE) {
	cat("\nn=", n, ":")
	x <- runif(n)
	y <- 3 + 4*x + rnorm(n)/10

	cat(" time:", unix.time(loess(y ~ x, span= 1)),"\n")
	cat(" gc() free:"); print(as.vector(gc()[,"free"]))
	n <<- n+500

For me, it ends as


    4500  time: 78.2 0.02 141 0 0 
     gc() free:Ncells Vcells 
     83129 213516 

    5000  time: 96.8 0 174 0 0 
     gc() free:Ncells Vcells 
     83129 212516 

    5500 Error: heap memory (2048 Kb) exhausted [needed 85 Kb more]
	   See "help(Memory)" on how to increase the heap size.
    Timing stopped at: 116.42 0.02 210 0 0 
    Execution halted

Problems are:  

	 1) loess() does allocate memory dynamically in 
	    ``not so standard'' ways, namely using standard C's Calloc(.)
	      --> see loess_workspace(.) in src/library/modreg/src/loessc.c
	    instead of R's  C_alloc() function [from src/main/memory.c]
	    (yes yes, if this API would have been documented, Brian would
	     have used it when writing loessc.c for the modreg package..)

	     and hence gc() does not really show how much memory is used..

	 However the error message above clearly leads you in the right
	 direction, namely  ?Memory  (see below).

	 2) loessf.f (same directory) is really the heart of the algorithm,

	    However it is (modified) output of  ratfor or
	    something like it, and not really well documented;
            Tons of  ehg1<nm> routines which have no helpful names, 
	    and unfortunately don't have too many comments....

Solution for you:

Give more vector memory to R :

In  R versions <= 0.63.2, use  e.g.,

    R --vsize 10  

(uses 10 MBytes of vector heap memory).

>From the just released version 0.63.3 on, the syntax is

     R --vsize 10M

(idea behind: Both "nsize" and "vsize" are given in single units;
      Bytes for vsize  and  "Cons Cells" (= 4 Bytes)  for  nsize)

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list