Hi,

I'm new by using C++ and Rcpp, but I wrote an minimal example which shows the problem:

------------------------

require( inline )
require( Rcpp )


src <- '
    RNGScope scope;
    //GetRNGstate();

    int NN = INTEGER(sNN)[0];
    int T = INTEGER(sT)[0];

    Rcpp::NumericMatrix lar(T+1,NN);
    Rcpp::NumericMatrix la1r(T+1,NN);

    Rcpp::NumericVector epsr(NN*(T+1));
    epsr = rnorm((T+1)*NN,0.0,1.0); // check

    Rcpp::List res = Rcpp::List::create(Rcpp::Named("gamma") = lar);

    //PutRNGstate();
    return(res);
'

inc <- '


using namespace Rcpp;
using namespace std;

#include <stdio.h>
#include <Rmath.h>

'



fun <- cfunction(signature(sNN="integer", sT="integer"),
                 src,
                 includes=inc,
                 Rcpp=TRUE,
                 cppargs="-I/usr/include")


a <- fun(10L,1000L)$gamma[-1,]


for (i in 1:10000){
a <- fun(10L,1000L)$gamma[-1,]
#if(i%%100 ==0)
   cat(i,"\n")
}

--------------------------------------------------------------

The output of this script is random, some times it runs without problem, but often the output is like as:
________________________________

....
639
640
641

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

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

 ____________________________________

The problem seems to be solved by using
GetRNGstate();  and
PutRNGstate();


Any help greatly appreciated.
Cheers,


--

Dr. Carlos Almeida
Technische Universitaet Muenchen
Zentrum Mathematik
Lehrstuhl fr Mathematische Statistik
Boltzmannstr. 3
85747 Garching
Germany

phone: +49-89-289-17439
fax: +49-89-289-17435

email: calme...@ma.tum.de
http://www-m4.ma.tum.de/m4/pers/almeida/index.html



_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to