[Rd] Patch: context stack size in gram.y

Hin-Tak Leung hin-tak.leung at cimr.cam.ac.uk
Mon Jun 5 13:37:38 CEST 2006


Hmm, I think you can "flatten" the for-loop with something like this, 
without modifying R:

for(ParamAll in 1:(length01*length02*length03*length*4...)) {

idx1 <- as.integer(ParamAll/(length02*length03...))
Param01 <- Param01Set[idx1]
idx2 = as.integer((ParamAll - idx1 * length01)/length03*length04...)
Param02 <- Param02Set[idx2]
...
central code
...
}

It is the same way generalizing addressing matrix element[i,j] as
element[i*length_j + j], etc. Then you won't have over 50 nested
for-loops. If you have something that deeply nested, I would also be 
writing those idx1 <- as.integer(...) in C for speed ( or use
% properly, but it is too early in the morning and my head is a bit 
wuzzy at the moment...), or even the Param01, etc. e.g.

Param01 <- .Call("my_element_selector", c(Parm01Set, Param02Set ...), 
ParamAll)

HTL

Thomas Dreibholz wrote:
> On Wednesday 31 May 2006 15:26, Prof Brian Ripley wrote:
>> On Wed, 31 May 2006, Thomas Dreibholz wrote:
>>> Hi!
>>>
>>> Attached to this mail, you find a patch for gram.y setting a #define
>>> CONTEXT_STACK_SIZE for the context stack size and replacing the following
>>> constants 50 and 49 by CONTEXT_STACK_SIZE and CONTEXT_STACK_SIZE-1. The
>>> new #define makes setting the stack size much more easy; I also have
>>> increased it to 500, because 50 is too small (we use R to iterate through
>>> sets of simulation parameters, which requires a context stack size of
>>> around 100).
>> I think you will have to explain in detail why you need this, when for a
>> decade R users have not reported a need for it.  It is not related to
>> iteration in R, rather to the depth of recursion needed to parse R code.
> 
> We use R to create input files for OMNeT++ simulations. The simulation 
> parameters are defined like this:
> param01Set <- c(...)
> param02Set <- c(...)
> ...
> paramXYSet <- c(...)
> Most of these sets only contain a single element.
> 
> The input file generation, which should be usable for all simulations, works 
> as follows:
> for(param01 in param01Set) {
>  for(param02 in param02Set) {
>   ...
>    for(paramXY in paramXYSet) {
>      Generate input file for these parameter settings
>    }
>   ...
>  }
> }
> 
> The simulation has more than 50 different parameters, so a "contextstack 
> overflow" error will be the result. Increasing the context stack size in 
> gram.y solves this problem. (Clearly, only using "for" iterations for sets 
> consisting of more than one element would solve the problem - but this 
> requires a special version of the parameter generation function for every 
> simulation.)
> 
> 
> Best regards
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list