[Rcpp-devel] Segfault error during simulation in Rcpp

Xiao He praguewatermelon at gmail.com
Thu May 16 18:56:02 CEST 2013


I tried it just now. Did not crash on my R. Mmm

myFun =cppFunction('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;
+ }')
> 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]
+  }
>


On Thu, May 16, 2013 at 9:40 AM, Jonathan Olmsted <jolmsted at princeton.edu>wrote:

> Ditto Kevin's comment. I segfault no matter what.
>
> > sessionInfo()
> R version 2.15.3 (2013-03-01)
> Platform: x86_64-apple-darwin12.3.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
>  [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>
> -------------------------------------------------------------------------
> J.P. Olmsted
>
> 029 Corwin (Office)
> 130 Corwin Hall (Mail)
>
> Politics Department
> Princeton University
> Princeton, NJ 08544
>
>
> t: 609.258.6202
> f: 609.258.1110
> jolmsted at princeton.edu
> http://about.me/olmjo
> -------------------------------------------------------------------------
>
>
> On Thu, May 16, 2013 at 12:38 PM, Kevin Ushey <kevinushey at gmail.com>wrote:
>
>> FWIW, I can reproduce the segfault with this example, whether running R
>> as vanilla or not.
>>
>> > sessionInfo()
>> R version 3.0.0 (2013-04-03)
>> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>>
>> locale:
>> [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] Rcpp_0.10.3
>>
>> -Kevin
>>
>>
>> On Thu, May 16, 2013 at 9:01 AM, Matteo Fasiolo <matteo.fasiolo at gmail.com
>> > wrote:
>>
>>> 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
>>>>
>>>
>>>
>>> _______________________________________________
>>> Rcpp-devel mailing list
>>> Rcpp-devel at lists.r-forge.r-project.org
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>>
>>
>>
>>
>> --
>> -Kevin
>>
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130516/f6ab37aa/attachment.html>


More information about the Rcpp-devel mailing list