I&#39;m having a problem with running long MCMC chains.  When I run the chain for 1000 runs it takes about  30 seconds<div>---</div><div><div>&gt; n&lt;-1e3</div><div>&gt; time1&lt;- system.time({</div><div>+ run1 &lt;- d3$run(n, 1,1, 1,1, 50)</div>

<div>+ })</div><div>&gt; time1</div><div>   user  system elapsed </div><div> 30.120   0.950  31.105</div></div><div>---</div><div><br></div><div>When I run for 100 000 runs I should expect  something in the neighborhood of an hour.  What I&#39;m getting is about 8 hours.  And I have confirmed that  the longer  the run the longer each iteration takes.   My best guess is that this has something to do with efficient memory management.  Monitoring my system I know that things are staying in physical memory and not going to swap.  It might be that it is able to stay cached on chip, rather than memory.  Does anyone have good intuition for this?</div>

<div><br></div><div>Either way it looks like the way to proceed is to implement a caching mechanism where I can compute about 1000 iterations then store the results and keep going.  The problem is I have no intuition of how to go about this in Rcpp or anything else. </div>

<div><br></div><div>I R I would just perform something like</div><div> results[1:1000 +(i-1)*1000,] &lt;- results_temp</div><div><br></div><div>I don&#39;t know how to do that in Rcpp or if it would be more efficient.  Any direction and discussion would be helpful.  Sorry for being vague.</div>

<div><br></div><div>Thanks,</div><div>Andrew</div><div><div><br><div><br></div><div><br></div></div></div>