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