Skip to content

Conversation

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Nov 20, 2025

This PR implements the data.table "decision tree" in their configure shell script via configure.ac. There are two broad cases: Linux and macOS, and within each different strategies are tested. It accommodates macOS three different ways, including homebrew.

@coatless When you have a moment, please eyeball. It still contains a CI matrix with/without calling your installer script so we see these two aspects. I do not think I can automate homebrew testing but I trust the data.table choices.

I may comment-out some of the bits in the CI file before merging but for now it is helpful to have the additional output.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive OpenMP detection mechanism inspired by the data.table package's configure script. It replaces the previous simpler approach with a decision-tree based detection that handles both Linux and macOS platforms with multiple fallback strategies.

Key changes:

  • Platform-specific OpenMP detection with separate logic for Linux and macOS
  • Multiple detection strategies including homebrew support on macOS (Intel and ARM64)
  • Extended Makevars template to accept PKG_CXXFLAGS and PKG_LIBS from configure
  • CI matrix expanded to test both with and without OpenMP installer on macOS

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
configure.ac Implements new decision-tree based OpenMP detection with platform-specific logic for Linux and macOS, including homebrew support
configure Generated script from configure.ac with the new OpenMP detection logic
src/Makevars.in Extended to accept PKG_CXXFLAGS and PKG_LIBS substitutions for custom compiler/linker flags
DESCRIPTION Version bump to 15.2.2-0.1
.github/workflows/ci.yaml Added matrix configuration to test macOS with and without OpenMP installer script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eddelbuettel
Copy link
Member Author

Best value add I had seen from Copilot. Caught a few not-that-easy-to-spot gotchas I had left.

@coatless
Copy link
Contributor

@eddelbuettel the issue here is this will tick #define ARMA_USE_OPENMP on CRAN machines; but, this might not hold up on non-CRAN machines. The beauty of data.table is it does not need to be re-compiled once installed.

So, this approach while more rigorous, will fail on an invocation of sourceCpp() with // [[Rcpp::depends(RcppArmadillo)]] without the user's computer having the OpenMP files present. This is unfortunately the status quo and why I was trying to approach it with the header def to override the existing permanent on/off approach.

@eddelbuettel
Copy link
Member Author

There is still the override we added in a previous PR:

// macOS special case as discussed in https://github.com/RcppCore/RcppArmadillo/issues/493
#if !defined(ARMA_USE_OPENMP)
#if defined(__APPLE__) && defined(_OPENMP)
// User has OpenMP available, but check if they want it disabled
#ifndef RCPPARMADILLO_MACOS_DISABLE_OPENMP
#define ARMA_USE_OPENMP 1
#else
#define ARMA_DONT_USE_OPENMP 1
#endif
#else
// from configure test for OpenMP based on how R is configured
@ARMA_HAVE_OPENMP@
#endif
#endif

I think that is the best we can do. sourceCpp() use is after all a (rather nice to have not essential) add-on. And we may be able to use something like an environment variable as an override for a plugin (which connects this to the OpenMP plugin question for Rcpp and how to deal with plugins which remains an open questions.

And users who know what they are doing can set local #define statements too to override. I think net-net we are still improving as we will be able to get more OpenMP to macOS users of Armadillo.

## Additional Apple check
AC_MSG_CHECKING([for macOS])
RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
if test x"${RSysinfoName}" = x"Darwin"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this check back in to disable the #define ARMA_DONT_USE_OPENMP?

Copy link
Member Author

@eddelbuettel eddelbuettel Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I actually went on purpose to the 'try three different ways in sequence' model from data.table to then accept the result. And not to ignore it just because we're on macOS.

Wouldn't one possible fix be to say "oh so you want to use sourceCpp() and compile locally so could we ask you to reinstall RcppArmadillo from source" ?

@eddelbuettel
Copy link
Member Author

Going to move forward, merge this and release. We can always refine in a subsequent PR.

@eddelbuettel eddelbuettel merged commit 9ecbf99 into master Nov 21, 2025
8 of 11 checks passed
@eddelbuettel eddelbuettel deleted the feature/openmp branch November 21, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants