[Rcpp-devel] Segfault error during simulation in Rcpp

Matteo Fasiolo matteo.fasiolo at gmail.com
Mon May 6 20:03:58 CEST 2013


Thanks for the quick replies! I'm using log() and then exp() on the
parameters because
this function goes within an optimization routine, so I need it keep the
parameters positive.

Sorry for the silly question, but since I'm using sourceCpp() too I
should't call
getRNGstate/putRNGstate, right?

I run the code with Dirk's change:
params <- matrix(log(c(r = exp(3.8), theta = 1, sigma = 0.3, phi = 10)), 1,
4)

 but I still get the same error in Valgrind. Also, when I was looking for
this error
I was running 6 R sessions in parallel with 10^8 iterations and only 1 gave
me
a segfault, so you might run 10^6 iterations and everything seems ok. Other
times
it crashes immediately, as it just happened:

library(Rcpp)
sourceCpp("~/Desktop/genRickerCpp.cpp")


> params <- matrix(log(c(r = exp(3.8), theta = 1, sigma = 0.3, phi = 10)),
1, 4)
> for(ii in 1:(2*(10^6))){
+ data <- genRickerCpp(days = 1, nSimul = 50, nBurn = 50,
+                      params = params)
+ data <- as.numeric(data)
+ }

 *** caught segfault ***
address 0x30, cause 'memory not mapped'

If I open another R window and I paste the same code it just keeps crashing
with the previous error
message or:

 *** caught segfault ***
address (nil), cause 'unknown'



On Mon, May 6, 2013 at 3:00 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 6 May 2013 at 08:34, Douglas Bates wrote:
> | The segfaults seem to be related to PutRNGstate and I don't see that you
> have
> | declared an instance of the class that causes the RNGstate to be
> accessed and
> | restored (I have forgotten the name of the class but it should be fairly
> easy
> | to find in the examples).  When you use random number generators from
> within
> | Rcpp you either need to call getRNGstate/putRNGstate yourself or to
> simply
> | declare an instance of this class.
>
> Very good point.
>
> By using sourceCpp(), I got that added automagically thanks to JJ and hence
> never saw the error.
>
> Dirk
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130506/189e70c7/attachment.html>


More information about the Rcpp-devel mailing list