[Rcpp-devel] OpenMP and Rcpp - compiler error
Michael Braun
braunm at MIT.EDU
Thu Mar 24 17:43:01 CET 2011
Hi. I would like to be able to use OpenMP in conjunction with Rcpp. Here's is an example of the kind of thing I want to do:
#include <Rcpp.h>
RcppExport SEXP omptest (SEXP X) {
BEGIN_RCPP
Rcpp::NumericVector Y = X;
int n = Y.size();
Rcpp::NumericVector Z(n);
int i;
double a;
#pragma omp parallel
{
#pragma omp for
for (i=0; i<n; i++) {
a = sqrt(Y(i));
Z(i) = a;
}
}
return Z;
END_RCPP
}
But I am getting a compiler error in certain situations. Here is an example of the compiler command I am using (of course, there are other calls to the linker, etc, but this is where the error is)
g++ -O1 -arch x86_64 -fopenmp -g -Wall -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -I/usr/local/include -I/Library/Frameworks/R.framework/Resources/library/Rcpp/include -c Rcpp_omp.cpp -o Rcpp_omp.o
If I execute this command, I get the following error:
Rcpp_omp.cpp: In function ‘void omptest.omp_fn.0(void*)’:
Rcpp_omp.cpp:13: internal compiler error: in get_expr_operands, at tree-ssa-operands.c:2093
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for instructions.
(note that in the "real" project, the compiler actually segfaults, but let's keep this simple for now).
Now, if I comment out the omp pragmas, no problem. It all works.
If I change optimizations to -O0, no problem, it all works (although this is not really a good solution. Higher-level optimizations also crash.)
If I remove the -fopenmp option, no problem, it all works.
If I comment out the BEGIN_RCPP and END_RCPP macros, no problem, it all works.
It's this last point, the error-catching macros, that might be the problem. Note that they are not inside the parallel section of the code. But it appears that the intersection of the error-catching macros, compiler optimizations, and OpenMP are causing some kind of problem.
And incidentally, I am using g++ version 4.2.1 on a Mac Pro running OSX 10.6.6.
Any thoughts?
Thanks,
Michael
-------------------------------------------
Michael Braun
Homer A. Burnell (1928) Career Development Professor,
and Assistant 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