[Rcpp-devel] Stack imbalance warning when using Rcpp and OpenMP

Michael Braun braunm at MIT.EDU
Wed Jul 27 21:04:21 CEST 2011


It is taking the SEXP as the argument.  If R is the Rcpp::List argument, and i is the index of the parallelized loop, then:

double y = as<double>(R(i));
double res = func(y);

does work.  So far, as long as the Rcpp stuff happens in the loop directly (same function), it works.  But if I call another function from the parallelized loop, and do some Rcpp work in that function, that's when I get problems.

So while it is great that this works on this simple example, my real-world application is much more complicated (e.g., passing lists of lists), and this kind of workaround doesn't help at all.  But let's get the simple case fixed first.

Are you aware of anyone at all who has had success combining Rcpp and OpenMP?



On Jul 27, 2011, at 2:55 PM, Davor Cubranic wrote:

> On 2011-07-27, at 10:33 AM, Michael Braun wrote:
> 
>> I want to avoid making a copy of the entire list (my real-world application might have lots of different elements for each element of the "master" list).  But what works fine is if, within the loop, I do the Rcpp-to-double conversion, and then call a version of the function that takes a double as an argument, instead of the SEXP.  So I think there is something going on with passing the SEXP to func, and then using Rcpp::as to convert the SEXP to double.
>> 
>> Is this close to what you are asking?
> 
> Yep. I'm still surprised that Rcpp:as works (I thought it would also take a SEXP as an argument), but if it works, then great.
> 
> Davor

-------------------------------------------
Michael Braun
Associate Professor of Management Science (Marketing Group)
MIT Sloan School of Management
100 Main St.., E62-535
Cambridge, MA 02139
braunm at mit.edu
617-253-3436




More information about the Rcpp-devel mailing list