Skip to content

[Rcpp-devel] Package using Rcpp+openmp - fatal error: 'omp.h' file not found

4 messages · Simon Urbanek, Dirk Eddelbuettel, Naeem Khoshnevis

#
Dear All,

I hope this email finds you well and this is a right place to ask this
question.

I recently submitted a package to CRAN (thanks for all supports); however,
it has been archived. According to the email, the installation was not
successful on some configurations. One of them is macOS (the other one is
Solaris).
I am using Rcpp and OpenMP; here are the initial lines of the code:
--------------
#include <Rcpp.h>
#include <omp.h>
using namespace Rcpp;

// [[Rcpp::plugins(openmp)]]

// [[Rcpp::export]]
IntegerVector compute_closest_wgps_helper(NumericVector a,
                                          NumericVector b,
                                          NumericVector cd,
                                          double sc) {

------------------
Please see the following link for the entire code:
https://github.com/fasrc/CausalGPS/blob/master/src/compute_closest_wgps_helper.cpp

The error that I receive on R-hub is:

-------------------
compute_closest_wgps_helper.cpp:2:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~
1 error generated.
make: *** [compute_closest_wgps_helper.o] Error 1
ERROR: compilation failed for package ‘CausalGPS’
-------------------

Do you know a workaround for this issue?
I understand some R developers do not use macOS; however, I have to address
this comment.

Best regards,
Naeem Khoshnevis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20210809/e0336a34/attachment.html>
#
Naeem,

you cannot assume that OpenMP is available as that is an optional capability, so make sure you make the inclusion of omp.h optional. Please read section 1.2.1.1 OpenMP support of the Writing R Extensions manual:
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#OpenMP-support

Cheers,
Simon
#
(I replied earlier but that seems to have gotten lost. Apologies to anybody
who may receive two copies, and thanks to Simon for his answer.  -- Dirk)
On 9 August 2021 at 17:04, Naeem Khoshnevis wrote:
| Do you know a workaround for this issue?

Wrap the #include by #ifdef _OPENMP and #endif

Test for presence of OpenMP (for example via a configure script). 

Use the standard R compilation flags. RcppArmadillo uses

  PKG_CXXFLAGS = -I../inst/include @OPENMP_FLAG@
  PKG_LIBS= @OPENMP_FLAG@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

where @OPENMP_FLAG@ gets set if OpenMP is found.  Other packages just use

  PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
  PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

relying on R which sets SHLIB_OPENMP_CXXFLAGS.

Dirk
#
Dear Simon and Dirk,

Thank you so much for the answers. I really appreciate your help.

Best regards,
Naeem
On Mon, Aug 9, 2021 at 8:32 PM Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20210809/ef0683e8/attachment.html>