0

I am submitting an R package to CRAN with C++ code. I've read and re-read Section 1.2.1.1 "OpenMP support" in the manual: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#OpenMP-support

Based on this, I use conditionals for any OpenMP calls as follows:

#ifdef _OPENMP
  #include <omp.h>
#endif

#ifdef _OPENMP
  omp_set_num_threads(n_cores);
#endif

#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)
#endif

#ifdef _OPENMP
#pragma omp critical
#endif

Unfortunately, CRAN still flags my package for violating OpenMP issues.

I'm stumped. Why would this be? Surely the conditionals resolve this issue, no? Have I misunderstood the manual?

Any help appreciated. Thank you.

EB2127
  • 1,788
  • 3
  • 22
  • 43
  • What are these CRAN warnings exactly? And did you set the PKG flags in the Makevars file? – Stéphane Laurent Nov 27 '20 at 08:52
  • This is a very simple package with 4 *cpp files and Rcpp. There is no Makevars file which I'm using for them. As for the warnings, they were warnings after the package was accepted to CRAN and built. – EB2127 Nov 27 '20 at 13:50
  • No makevars file? Normally you should put a **Makevars** file and a **Makevars.win** file containing `PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)` and `PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)`. These files must be in the **src** directory. – Stéphane Laurent Nov 27 '20 at 13:54
  • @StéphaneLaurent My understanding was with the new version of Rcpp, this isn't necessary. It's quite possible I've been misunderstanding something though... – EB2127 Nov 27 '20 at 14:07
  • This is the way I'm using for one of my packages. I have not submitted to CRAN the version using OpenMP yet but I've tested on **R-hub** and got no issue. – Stéphane Laurent Nov 27 '20 at 14:14
  • @StéphaneLaurent I have no issue on rhub either. RE: Rcpp, I was using this information from https://dirk.eddelbuettel.com/code/rcpp/Rcpp-package.pdf. "Now optional: Makevars and Makevars.win This behaviour changed with Rcpp release 0.11.0. These files used to be mandatory, now they are merely optional" – EB2127 Nov 27 '20 at 14:17
  • That depends. For example a Makevars file is needed for a package using RcppArmadillo, because you have to tell to the compiler that your C++ code uses LAPACK. You are scaring me now, I'm fearing I will encounter the same problem with my package. – Stéphane Laurent Nov 27 '20 at 14:21
  • Look [here](https://stackoverflow.com/a/54062116/1100107). Dirk Eddelbuettel does not mention that the Makevars file is not mandatory for OpenMP usage. – Stéphane Laurent Nov 27 '20 at 14:36
  • That's fair enough. I am happy add Makevars and Makevars.win files. CC @DirkEddelbuettel – EB2127 Nov 27 '20 at 22:05

0 Answers0