<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Dirk:</div><div><br></div><div>I've been able to upgrade my compiler to g++ 4.6 on the Mac, and I also checked this on a Red Hat Linux system with g++ 4.4. &nbsp;In both cases, the OpenMP code does compile and run, so I agree that it must have been a compiler issue. &nbsp;However, 4.6 appears to be an experimental version, with some odd quirks (like not recognizing the -arch option). &nbsp;I was able to find only a binary for 4.6, and compiling 4.5 takes a very, very long time. &nbsp;So I'm wondering if you could suggest a source for a binary of a stable version of gcc for the Mac, or possibly suggest a way that Rcpp could run under the compiler that ships with Snow Leopard.</div><div><br></div><div>I'll start another thread for the second issue, about the compiler not being able to compile one of the Rcpp-sugar examples, since it is still unsolved and unrelated.</div><div><br></div><div>Thanks again.</div><div><br></div><div>Michael</div><div><br></div><div><br></div><br><div><div>On Mar 24, 2011, at 6:15 PM, Dirk Eddelbuettel wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br><br>On 24 March 2011 at 17:50, Michael Braun wrote:<br>| Dirk:<br>| <br>| This does work when I use the Intel compiler, so perhaps you are right. &nbsp;I am, however, using the standard Apple-provided version, which is 4.2.1. <br>| <br>| I suspect there is a related issue in how OpenMP handles private Rcpp objects in a parallel section. &nbsp;For example, if I declare<br>| <br>| NumericVector X;<br>| <br>| #pragma omp parallel (private X)<br>| {<br>| #pragma omp for<br>| for (i=0; i&lt;n; i++) {<br>| <span class="Apple-tab-span" style="white-space:pre">        </span>// some code that uses X<br>| <br>| }<br>| }<br>| <br>| then I would have thought that the compiler would create an instance of X for each thread. &nbsp;Instead, I am getting memory segfaults even with the Intel compiler, and I wonder if these two issues are related (i.e., perhaps the compielr doesn't know what to do with code like this, and hence the error).<br><br>There should never be a segfault. &nbsp;Even is copies are made (which would be<br>shallow, deep copies require clone) I fail to see how that would great out of<br>bounds access. &nbsp;Maybe there are other issue with the Intel compiler and Rcpp so<br>maybe you could try a full 'R CMD check Rcpp_0.9.2.tar.gz' for it?<br><br>| Could I be on track, or way off base?<br><br>I don't not know but fear the latter. &nbsp;Anyway, as I had already compiled your<br>example earlier (as shown in the quoted text below):<br><br>edd@max:/tmp$ cat michael.cpp <br><br>#include &lt;Rcpp.h&gt;<br><br>RcppExport SEXP omptest (SEXP X) {<br><br> &nbsp;BEGIN_RCPP<br><br> Rcpp::NumericVector Y = X;<br> int n = Y.size();<br> Rcpp::NumericVector Z(n);<br> int i;<br> double a;<br><br>#pragma omp parallel<br> {<br>#pragma omp for<br> for (i=0; i&lt;n; i++) {<br> &nbsp;&nbsp;a = sqrt(Y(i));<br> &nbsp;&nbsp;Z(i) = a;<br> }<br> }<br> return Z;<br><br> END_RCPP<br><br>}<br>edd@max:/tmp$ R --quiet<br>R&gt; dyn.load("michael.so")<br>R&gt; .Call("omptest", 1:10)<br> [1] 1.00000 1.41421 2.64575 2.00000 2.64575 2.44949 2.64575 2.82843 3.00000 3.16228<br>R&gt; q()<br>Save workspace image? [y/n/c]: n<br>edd@max:/tmp$ <br><br>So still no issue here....<br><br>Dirk<br><br>| <br>| Thanks,<br>| <br>| Michael<br>| <br>| <br>| <br>| <br>| On Mar 24, 2011, at 1:03 PM, Dirk Eddelbuettel wrote:<br>| <br>| &gt; <br>| &gt; Michael,<br>| &gt; <br>| &gt; As a quick off-the-cuff remark, I suspect it is your compiler. I have done<br>| &gt; quite a few builds with OpenMP when experimenting with a parallel version of<br>| &gt; RcppDE (the differential evolution optimisation I "ported" from C to<br>| &gt; C++/Rcpp). &nbsp;I had no issues building this (but issues getting replicable<br>| &gt; streams going which is still unsolved though I have some tests working).<br>| &gt; <br>| &gt; The incomplete RcppParDE fragment is actually in Rcpp's SVN and there I<br>| &gt; simply do <br>| &gt; <br>| &gt; ## Hey Emacs make this a -*- mode: makefile; -*- file <br>| &gt; ##<br>| &gt; ## -- compiling for OpenMP <br>| &gt; PKG_CXXFLAGS=-fopenmp<br>| &gt; ##<br>| &gt; ## -- linking for OpenMP<br>| &gt; #PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)<br>| &gt; ##<br>| &gt; ## -- linking for OpenMP and Google Perftools profiling<br>| &gt; PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lprofiler<br>| &gt; <br>| &gt; and that is all it takes to deploy OpenMP with R and Rcpp on my Linux box:<br>| &gt; <br>| &gt; edd@max:~/svn/rcpp/pkg/RcppParDE$ R CMD INSTALL .<br>| &gt; * installing to library ‘/usr/local/lib/R/site-library’<br>| &gt; * installing *source* package ‘RcppParDE’ ...<br>| &gt; ** libs<br>| &gt; ccache g++ -I/usr/share/R/include &nbsp;&nbsp;-I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" &nbsp;-fopenmp -fpic &nbsp;-g -O3 -Wall -pipe -pedantic -Wno-variadic-macros &nbsp;-c deoptim.cpp -o deoptim.o<br>| &gt; ccache g++ -I/usr/share/R/include &nbsp;&nbsp;-I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" &nbsp;-fopenmp -fpic &nbsp;-g -O3 -Wall -pipe -pedantic -Wno-variadic-macros &nbsp;-c devol.cpp -o devol.o<br>| &gt; ccache g++ -I/usr/share/R/include &nbsp;&nbsp;-I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" &nbsp;-fopenmp -fpic &nbsp;-g -O3 -Wall -pipe -pedantic -Wno-variadic-macros &nbsp;-c permute.cpp -o permute.o<br>| &gt; g++ -shared -o RcppParDE.so deoptim.o devol.o permute.o -fopenmp -lgomp -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -llapack -lblas -lgfortran -lm -lprofiler -L/usr/lib64/R/lib -lR<br>| &gt; installing to /usr/local/lib/R/site-library/RcppParDE/libs<br>| &gt; ** R<br>| &gt; ** preparing package for lazy loading<br>| &gt; ** help<br>| &gt; *** installing help indices<br>| &gt; ** building package indices ...<br>| &gt; ** testing if installed package can be loaded<br>| &gt; <br>| &gt; * DONE (RcppParDE)<br>| &gt; edd@max:~/svn/rcpp/pkg/RcppParDE$ <br>| &gt; <br>| &gt; Now this packages has run-time issue, and my recent test code is somewhere so<br>| &gt; take the package for a working package -- but it does prove that OpenMP can<br>| &gt; easily be thrown in the mix on suitable systems.<br>| &gt; <br>| &gt; And what "suitable systems" are is an open question. We know Rtools for<br>| &gt; Windows does not include the libgomp library needed. &nbsp;Maybe OS X is not<br>| &gt; suitable either in that version?<br>| &gt; <br>| &gt; Your file certainly builds here:<br>| &gt; <br>| &gt; edd@max:/tmp$ cat michael.cpp <br>| &gt; <br>| &gt; #include &lt;Rcpp.h&gt;<br>| &gt; <br>| &gt; RcppExport SEXP omptest (SEXP X) {<br>| &gt; <br>| &gt; &nbsp;BEGIN_RCPP<br>| &gt; <br>| &gt; Rcpp::NumericVector Y = X;<br>| &gt; int n = Y.size();<br>| &gt; Rcpp::NumericVector Z(n);<br>| &gt; int i;<br>| &gt; double a;<br>| &gt; <br>| &gt; #pragma omp parallel<br>| &gt; {<br>| &gt; #pragma omp for<br>| &gt; for (i=0; i&lt;n; i++) {<br>| &gt; &nbsp;&nbsp;a = sqrt(Y(i));<br>| &gt; &nbsp;&nbsp;Z(i) = a;<br>| &gt; }<br>| &gt; }<br>| &gt; return Z;<br>| &gt; <br>| &gt; END_RCPP<br>| &gt; <br>| &gt; }<br>| &gt; edd@max:/tmp$ PKG_LIBS="-fopenmp -lgomp -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -llapack -lblas -lgfortran -lm -L/usr/lib64/R/lib -lR" PKG_CXXFLAGS="-I/usr/share/R/include &nbsp;&nbsp;-I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" &nbsp;-fopenmp -fpic &nbsp;-g -O3 -Wall -pipe -pedantic" R CMD SHLIB michael.cpp<br>| &gt; ccache g++ -I/usr/share/R/include &nbsp;&nbsp;&nbsp;&nbsp;-I/usr/share/R/include &nbsp;&nbsp;-I/usr/local/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RcppArmadillo/include &nbsp;-fopenmp -fpic &nbsp;-g -O3 -Wall -pipe -pedantic -fpic &nbsp;-g -O3 -Wall -pipe -pedantic -Wno-variadic-macros &nbsp;-c michael.cpp -o michael.o<br>| &gt; g++ -shared -o michael.so michael.o -fopenmp -lgomp -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -llapack -lblas -lgfortran -lm -L/usr/lib64/R/lib -lR -L/usr/lib64/R/lib -lR<br>| &gt; edd@max:/tmp$ <br>| &gt; <br>| &gt; I am using g++ 4.4 (and sometimes 4.5), current R 2.12.2, current Rcpp 0.9.2.<br>| &gt; <br>| &gt; Regards, Dirk<br>| &gt; <br>| &gt; <br>| &gt; <br>| &gt; <br>| &gt; -- <br>| &gt; Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com">http://dirk.eddelbuettel.com</a><br>| <br>| -------------------------------------------<br>| Michael Braun<br>| Homer A. Burnell (1928) Career Development Professor, <br>| <span class="Apple-tab-span" style="white-space:pre">        </span>and Assistant Professor of Management Science (Marketing Group)<br>| MIT Sloan School of Management<br>| 100 Main St.., E62-535<br>| Cambridge, MA 02139<br>| <a href="mailto:braunm@mit.edu">braunm@mit.edu</a><br>| 617-253-3436<br>| <br>| <br><br>-- <br>Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com">http://dirk.eddelbuettel.com</a><br></div></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>-------------------------------------------<br>Michael Braun<br>Homer A. Burnell (1928) Career Development Professor,&nbsp;<br><span class="Apple-tab-span" style="white-space: pre; ">        </span>and Assistant Professor of Management Science (Marketing Group)<br>MIT Sloan School of Management<br>100 Main St.., E62-535<br>Cambridge, MA 02139<br><a href="mailto:braunm@mit.edu">braunm@mit.edu</a><br>617-253-3436</div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>