<div dir="ltr">Thanks for your reply Dirk.<div><br></div><div style>Maybe I have found something.</div><div style>Hopefully this is reproducible and simple enough:</div><div style><br></div><div style>/*</div><div style>* C++ file "b.cpp" </div>
<div style>* Just copying the input matrix into A and returning A.</div><div style>*/</div><div style><br></div><div style><div><div>#include <Rcpp.h></div><div><br></div><div>using namespace Rcpp;</div><div><br></div>
<div>// [[Rcpp::export]]</div><div>NumericMatrix myFun(NumericMatrix input, int n){</div><div><br></div><div>NumericMatrix A(n, n);</div><div><br></div><div>for(int Row = 0; Row < n; Row++)</div><div>  for(int Col = 0; Col < n; Col++)</div>
<div>  {</div><div>    A(Row, Col) = input(Row, Col);</div><div>  }</div><div><br></div><div>return A;</div><div>}</div></div><div><br></div><div><br></div><div>///////////////////////////////////////////</div><div><br></div>
<div style>Then I open a terminal:</div><div style><br></div><div style><div><div>teo@oracolo:~$ R --vanilla</div><div><br></div><div>R version 3.0.0 (2013-04-03) -- "Masked Marvel"</div><div>Copyright (C) 2013 The R Foundation for Statistical Computing</div>
<div>Platform: x86_64-pc-linux-gnu (64-bit)</div><div>[........]</div><div>Type 'q()' to quit R.</div><div><br></div><div>> library(Rcpp)</div><div>> sourceCpp("~/Desktop/b.cpp")</div><div>> </div>
<div>> #I run it 10 times and everything is fine.</div><div>> n = 10</div><div>> x <- 1:n^2</div><div>> </div><div>> for(ii in 1:10)</div><div>+ { </div><div>+   means <- matrix(x, n, n) </div><div>+   res <- myFun(means, n)</div>
<div>+   a <- res[1, 1]</div><div>+ }</div><div>> res</div><div>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]</div><div> [1,]    1   11   21   31   41   51   61   71   81    91</div><div> [2,]    2   12   22   32   42   52   62   72   82    92</div>
<div> [3,]    3   13   23   33   43   53   63   73   83    93</div><div> [4,]    4   14   24   34   44   54   64   74   84    94</div><div> [5,]    5   15   25   35   45   55   65   75   85    95</div><div> [6,]    6   16   26   36   46   56   66   76   86    96</div>
<div> [7,]    7   17   27   37   47   57   67   77   87    97</div><div> [8,]    8   18   28   38   48   58   68   78   88    98</div><div> [9,]    9   19   29   39   49   59   69   79   89    99</div><div>[10,]   10   20   30   40   50   60   70   80   90   100</div>
<div>> </div><div>> </div><div>> #I run it 10^6 times and everything and I get a segfault.</div><div>> n = 10</div><div>> x <- 1:n^2</div><div>> </div><div>> for(ii in 1:10^6)</div><div>+ { </div><div>
+   means <- matrix(x, n, n) </div><div>+   res <- myFun(means, n)</div><div>+   a <- res[1, 1]</div><div>+ }</div><div><br></div><div> *** caught segfault ***</div><div>address (nil), cause 'unknown'</div>
<div><br></div><div>Traceback:</div><div> 1: res[1, 1]</div></div><div><br></div><div><br></div><div style>If I run the same code without the --vanilla option it works fine!</div><div style>Certainly you know why using --vanilla is a problem here, honestly I've always used that option</div>
<div style>because I don't want R to ask me if I want to save the working environment when I quit. </div><div style>As you said the problem was coming from R (actually my improper use of R) and hopefully this is it! </div>
<div><br></div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 16, 2013 at 3:42 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Matteo,<br>
<br>
Can you provide a single, self-contained example and calling sequence that<br>
leads to reproducible crashes?<br>
<br>
That would be a bug. And we try to address it in Rcpp.<br>
<br>
As for your "issues" with RNGScope, I'd recommend that you write a C(++)<br>
function called from R __without using Rcpp__ and I very confident that you<br>
would the exact same issue.  Meaning that that all comes form R, which in<br>
itself is a pretty big system with numerous temp. allocations. But generally<br>
no known bug.  So please learn more about R and valgrind -- I suspect that<br>
you are simply getting confused by the copious and somewhat technical output<br>
produced by valgrind when running R.<br>
<div class=""><div class="h5"><br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</div></div></blockquote></div><br></div></div>