Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Ivan Popivanov
Ignore my previous mail ... On Thu, May 16, 2013 at 11:12 PM, Ivan Popivanov wrote: > How is this code supposed to work? If n=1e6, then the matrix has 1e12 > elements, right? That's in the terabyte range - the memory manager is going > to blow up or overflow and the results would be unpredictabl

Re: [Rcpp-devel] non-empty character argument expected

2013-05-16 Thread Dirk Eddelbuettel
Instead of time.f1 <- system(x2 <- f1(input=x, parms=p)) you probably meant time.f1 <- system.time(x2 <- f1(input=x, parms=p)) Also see the rbenchmark and microbenchmark packages. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com _

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Ivan Popivanov
How is this code supposed to work? If n=1e6, then the matrix has 1e12 elements, right? That's in the terabyte range - the memory manager is going to blow up or overflow and the results would be unpredictable. Or am I missing something? Regards, Ivan On Thu, May 16, 2013 at 7:14 PM, Jonathan Olms

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Dirk Eddelbuettel
On 16 May 2013 at 19:14, Jonathan Olmsted wrote: | Matteo, | |   | | The other obvious of course is that you are not forced to control a loop | over | 10^6 elements from R either:  pass N=10^6 down to C++ code, and run your N | loops there.  You will also get a considerable speed

[Rcpp-devel] non-empty character argument expected

2013-05-16 Thread Benjamin Tyner
Hello, I'm getting an error that I'm at a loss to explain; here is my code: # library(inline) f1 <- cxxfunction(signature(input = "numeric", parms = "list" ), plugin = "Rcpp",

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Jonathan Olmsted
Matteo, > The other obvious of course is that you are not forced to control a loop > over > 10^6 elements from R either: pass N=10^6 down to C++ code, and run your N > loops there. You will also get a considerable speed boost. > > ^ I could have been more explicit. This is what I meant. You mi

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Dirk Eddelbuettel
On 16 May 2013 at 23:27, Matteo Fasiolo wrote: | So the error appears when we are creating a RNGScope object AND we are | allocating memory  | repeatedly? It is unclear. It is possible that setting up RNGScope 10^6 times tickles something somewhere. You should only call it once. OTOH what the c

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Matteo Fasiolo
So the error appears when we are creating a RNGScope object AND we are allocating memory repeatedly? So that something like this: library(Rcpp) myFun <- cppFunction('void myFun(){ RNGScope scope; }') N <- 1e6 for (j in 1:N) { res <- myFun( ) } doesn't crash because we are not allocating mem

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Dirk Eddelbuettel
On 16 May 2013 at 14:49, Jonathan Olmsted wrote: | Several things. | | Xiao, Dirk's code gives me a segfault immediately and reliably. | | All, when I do this whole song and dance using the "old" Rcpp/inline/ | cxxfunction approach, I don't have any issues. One obvious difference you can | see (

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Jonathan Olmsted
Several things. Xiao, Dirk's code gives me a segfault immediately and reliably. All, when I do this whole song and dance using the "old" Rcpp/inline/cxxfunction approach, I don't have any issues. One obvious difference you can see (like was mentioned) in the generated code (visibile using verbose

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Xiao He
Hi Dirk, Does the code crash your R every time you run it or only occasionally? I ran your sample code exactly the way it's written, and my R did not crash. > myFun <- cppFunction('NumericMatrix myFun(NumericMatrix input, int n){ + NumericMatrix A(n, n); + for(int Row = 0; Row < n; Row++) { +

Re: [Rcpp-devel] Is creating a DataFrame from std::vector-s supposed to work?

2013-05-16 Thread Dirk Eddelbuettel
Hi Ivan, Thanks for the follow-up. On 16 May 2013 at 13:17, Ivan Popivanov wrote: | Are you saying that DataFrame::create doesn't work properly with std::vector? I | think I have seen examples and test units doing exactly that. No, it works. At least "in general". But as the parallel thread sh

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Dirk Eddelbuettel
Here is the self-contained example I asked for. And yes, it crashes for me too. So let's not create 1e6 temp matrices. Until someone has time to debug memory management internals. Which is really hard, so this may not get fixed for a while. Sorry. #!/usr/bin/Rscript library(Rcpp) myFun <-

Re: [Rcpp-devel] Is creating a DataFrame from std::vector-s supposed to work?

2013-05-16 Thread Ivan Popivanov
Are you saying that DataFrame::create doesn't work properly with std::vector? I think I have seen examples and test units doing exactly that. In my example, I'd like the c++ layer doing the actual work to stay pure c++, so that this code could be used without Rcpp (in a c++ program for instance).

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Matteo Fasiolo
Correction: as said by Brian it crashes also without --vanilla: teo@oracolo:~$ R 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) [...] 'help.start()' for an HTML browser interface to help. Type 'q

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Xiao He
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 >

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Jonathan Olmsted
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 datase

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Kevin Ushey
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 gra

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Matteo Fasiolo
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 using namespace Rcpp; // [[Rcpp::export]] NumericMatrix myFun(NumericMatrix input, int n){ Num

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Dirk Eddelbuettel
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 v

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-16 Thread Matteo Fasiolo
Hi all, I'm writing again about the segfault problem during simulation. I have added the missing line: RNGScope scope; and I have got rid of all temporary expressions. After that everything seemed to go well, actually to make sure it was working I run 10^8 iterations in 4 R session without gett