[R-SIG-Mac] malloc problem R2.6.1 on leopard

Herve Pages hpages at fhcrc.org
Tue Dec 4 21:27:54 CET 2007


Hi Hans,

In the case you plan to use the result of allsubsets(n) to loop over the
rows of the big returned matrix, then I would rather recommend a more
efficient approach where you don't generate this matrix at all. Something
like this:

nextSubset <- function(subset)
{

    i <- which(!subset)[1]
    if (is.na(i))
        return(NULL)
    subset[seq_len(i-1)] <- FALSE
    subset[i] <- TRUE
    subset
}

subset <- logical(30)
while (TRUE) {
    ... do something with 'subset' ...
    subset <- nextSubset(subset)
    if (is.null(subset))
        break
}

With an empty loop, I get the following:

  > subset <- logical(20)
  > system.time(while (1) { subset <- nextSubset(subset); if (is.null(subset)) break })
     user  system elapsed
   18.241   0.032  18.735

So with n = 30, this would take between 5 and 6 h just to loop over an
empty loop. This is a lot of time but at least you don't generate all
the possible subsets in advance which is just a waste of memory.

Cheers,
H.


Hans Kestler wrote:
> Hi,
> I just installed the latest release (2.6.1) on Leopard (Mac Pro - Quad-Core
> Intel Xeon, 16Gb).
> Calling :
> 
> allsubsets <- function (n)
> +   {
> +     if (n > 0)
> +       rbind(cbind(TRUE, Recall(n - 1)), cbind(FALSE, Recall(n -1)))
> +   }
>> a<-allsubsets(30)
> 
> I get the following error:
> 
> Error: cannot allocate vector of size 1.5 Gb
> 
> R(576,0xa04f8f60) malloc: *** mmap(size=1610616832) failed (error code=12)
> *** error: can't allocate region
> *** set a breakpoint in malloc_error_break to debug
> R(576,0xa04f8f60) malloc: *** mmap(size=1610616832) failed (error code=12)
> *** error: can't allocate region
> *** set a breakpoint in malloc_error_break to debug
> 
> Any ideas? Thank you.
> 
> Hans
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>



More information about the R-SIG-Mac mailing list