Dear R experts, recently I started developing a Rcpp package "OpenMPTest". Within that package I want to use OpenMP, as in the following code example:
// header file #include <omp.h> using namespace Rcpp ; RcppExport SEXP testOpenMP( SEXP nThreads ) ; // cpp file SEXP testOpenMP( SEXP nThreads ) { BEGIN_RCPP NumericVector numberThreads = NumericVector( nThreads ); omp_set_num_threads( numberThreads(0) ); #pragma omp parallel { // Code inside this region runs in parallel. printf("Hello!\n"); } END_RCPP } As I am an absolute newbie with writing C++ extensions and have not much understanding of the Makevars file, I am unsure what to write into it. Currently I have: ## Use the R_HOME indirection to support installations of multiple R version PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` KG_CFLAGS = $(SHLIB_OPENMP_CXXFLAGS) PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) ## -- compiling for OpenMP PKG_CXXFLAGS=-fopenmp ## ## -- linking for OpenMP PKG_LIBS= -fopenmp -lgomp Obviously compilation fails with error: R CMD INSTALL OpenMPTest Symbol not found: __ZTIN4Rcpp19index_out_of_boundsE With standard setup of the above Makevars I get the Symbol not found: omp_set_num_threads Inline also does not work: fb <- 'omp_set_num_threads(10); + #pragma omp parallel + { Rf_PrintValue(wrap("HALLO JUPP")); } + ' > funk <- cxxfunction( signature(), body=fb, plugin='Rcpp' ) error: ‘omp_set_num_threads’ was not declared in this scope How do set the PKG_LIBS -and eventually other variables- to all required values in a single statement? Could anyone provide me with a working Makevars example, please? Help will be much appreciated! Kind regards and have a nice weekend! Cheers! ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.