From dc51b1241d76f78bb7f08052abe570f554de6686 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 08:53:43 -0600 Subject: [PATCH 1/8] Generalizing configure openmp treatment following data.table: part 1 --- configure | 76 ++++++++++++++----- configure.ac | 72 ++++++++++++++---- .../config/RcppArmadilloConfigGenerated.h | 40 ++++++++++ 3 files changed, 155 insertions(+), 33 deletions(-) create mode 100644 inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h diff --git a/configure b/configure index 4d7948a7..51ba2a2e 100755 --- a/configure +++ b/configure @@ -3225,13 +3225,26 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what system we are on" >&5 +printf %s "checking what system we are on... " >&6; } +#SYSKERNEL=$(uname -s) +#SYSMACHINE=$(uname -m) +#SYSOS=$(uname -o) +#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}]) +## Rely on Sys.info() from R for cross-compilation cases +SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])') +SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["machine"])') +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: running ${SYSKERNEL} on ${SYSMACHINE}" >&5 +printf "%s\n" "running ${SYSKERNEL} on ${SYSMACHINE}" >&6; } + + ## Is R already configured to compile things using OpenMP without ## any extra hand-holding? #openmp_already_works="no" ## default to not even thinking about OpenMP as Armadillo wants a pragma ## variant available if and only if C++11 is used with g++ 5.4 or newer -#can_use_openmp="no" +can_use_openmp="no" ## Ensure TMPDIR is set. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we have a suitable tempdir" >&5 @@ -3240,10 +3253,6 @@ TMPDIR=$("${R_HOME}/bin/R" --vanilla --slave -e "cat(dirname(tempdir()))") { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${TMPDIR}" >&5 printf "%s\n" "${TMPDIR}" >&6; } -## Check if R is configured to compile programs using OpenMP out-of-the-box. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile programs using OpenMP" >&5 -printf %s "checking whether R CMD SHLIB can already compile programs using OpenMP... " >&6; } - ## Create private directory in TMPDIR. BUILDDIR="${TMPDIR}/rcpparmadillo-$$-$RANDOM" mkdir -p "${BUILDDIR}" @@ -3258,22 +3267,55 @@ int main() { } EOF -## Execute R CMD SHLIB. -"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 -if test x"$?" = x"0"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +if test x"${SYSKERNEL}" = x"Linux"; then + + ## Check if R is configured to compile programs using OpenMP out-of-the-box. + if test x"${can_use_openmp}" = x"no"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5 +printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; } + + ## Execute R CMD SHLIB. + "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" - can_use_openmp="yes" -else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" +##FIXME can_use_openmp="yes" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi + + ## If needed, check if R is configured to compile programs using OpenMP with -fopenmp + if test x"${can_use_openmp}" = x"no"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5 +printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; } + + ## Execute R CMD SHLIB. + PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" + can_use_openmp="yes" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" - can_use_openmp="no" + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi fi + + ## Go back home. cd "${owd}" rm -rf "${BUILDDIR}" diff --git a/configure.ac b/configure.ac index 27602a50..54b01af9 100644 --- a/configure.ac +++ b/configure.ac @@ -28,22 +28,30 @@ AC_LANG(C++) AC_REQUIRE_CPP AC_PROG_CXX +AC_MSG_CHECKING([what system we are on]) +#SYSKERNEL=$(uname -s) +#SYSMACHINE=$(uname -m) +#SYSOS=$(uname -o) +#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}]) +## Rely on Sys.info() from R for cross-compilation cases +SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])') +SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["machine"]])') +AC_MSG_RESULT([running ${SYSKERNEL} on ${SYSMACHINE}]) + + ## Is R already configured to compile things using OpenMP without ## any extra hand-holding? #openmp_already_works="no" ## default to not even thinking about OpenMP as Armadillo wants a pragma ## variant available if and only if C++11 is used with g++ 5.4 or newer -#can_use_openmp="no" +can_use_openmp="no" ## Ensure TMPDIR is set. AC_MSG_CHECKING([whether we have a suitable tempdir]) TMPDIR=$("${R_HOME}/bin/R" --vanilla --slave -e "cat(dirname(tempdir()))") AC_MSG_RESULT([${TMPDIR}]) -## Check if R is configured to compile programs using OpenMP out-of-the-box. -AC_MSG_CHECKING([whether R CMD SHLIB can already compile programs using OpenMP]) - ## Create private directory in TMPDIR. BUILDDIR="${TMPDIR}/rcpparmadillo-$$-$RANDOM" mkdir -p "${BUILDDIR}" @@ -58,20 +66,52 @@ int main() { } EOF -## Execute R CMD SHLIB. -"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 -if test x"$?" = x"0"; then - AC_MSG_RESULT([yes]) - openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" - can_use_openmp="yes" -else - AC_MSG_RESULT([no]) - openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" - can_use_openmp="no" +if test x"${SYSKERNEL}" = x"Linux"; then + + ## Check if R is configured to compile programs using OpenMP out-of-the-box. + if test x"${can_use_openmp}" = x"no"; then + AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs]) + + ## Execute R CMD SHLIB. + "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" +##FIXME can_use_openmp="yes" + else + AC_MSG_RESULT([no]) + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi + + ## If needed, check if R is configured to compile programs using OpenMP with -fopenmp + if test x"${can_use_openmp}" = x"no"; then + AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp]) + + ## Execute R CMD SHLIB. + PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" + PKG_LIBS="${PKG_LIBS} -fopenmp" + else + AC_MSG_RESULT([no]) + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi fi + + ## Go back home. cd "${owd}" rm -rf "${BUILDDIR}" diff --git a/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h b/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h new file mode 100644 index 00000000..ea766987 --- /dev/null +++ b/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h @@ -0,0 +1,40 @@ + +// RcppArmadilloConfigGenerated.h: Autoconf-updated file for LAPACK and OpenMP choices +// +// Copyright (C) 2013 - 2025 Dirk Eddelbuettel +// 2025 James J. Balamuta +// +// This file is part of RcppArmadillo. +// +// RcppArmadillo is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// RcppArmadillo is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RcppArmadillo. If not, see . + +#ifndef RcppArmadillo__RcppArmadilloConfigGenerated__h +#define RcppArmadillo__RcppArmadilloConfigGenerated__h + +// 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 + #define ARMA_USE_OPENMP 1 + #endif +#endif + +#endif From 5578accd8233121bd5932fb4ca04d00568cf9da0 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 09:53:13 -0600 Subject: [PATCH 2/8] Generalizing configure openmp treatment following data.table: part 2 --- .github/workflows/ci.yaml | 23 +++++++++++++- DESCRIPTION | 2 +- configure | 65 +++++++++++++++++++++++---------------- configure.ac | 64 +++++++++++++++++++++++++------------- src/Makevars.in | 4 +-- 5 files changed, 106 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3375996c..3aca46d1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,7 +15,8 @@ jobs: matrix: include: - { name: container, os: ubuntu-latest, container: rocker/r2u4ci } - - { name: macos, os: macos-latest } + - { name: macos, os: macos-latest, openmp: yes } + - { name: macos, os: macos-latest, openmp: no } #- { name: ubuntu, os: ubuntu-latest } @@ -31,6 +32,26 @@ jobs: with: dev_version: 'TRUE' + - name: OpenMP for macOS + if: ${{ matrix.os == 'macos-latest' && matrix.openmp == 'yes' }} + run: | + curl -fsSL https://raw.githubusercontent.com/coatless-shell/openmp/main/install-openmp.sh | bash -s -- --yes + mkdir -p ~/.R + cat < ~/.R/Makevars + CPPFLAGS += -Xclang -fopenmp + LDFLAGS += -lomp + EOF + + - name: Show config on macOS + if: ${{ matrix.os == 'macos-latest' && matrix.openmp == 'yes' }} + run: | + cat ~/.R/Makevars + echo -n "R CMD config CXX: "; R CMD config CXX + echo -n "R CMD config CPPFLAGS: "; R CMD config CPPFLAGS + echo -n "R CMD config LDFLAGS: "; R CMD config LDFLAGS + echo -n "R CMD config SHLIB_CXXLD: "; R CMD config SHLIB_CXXLD + echo -n "R CMD config SHLIB_CXXLDFLAGS: "; R CMD config SHLIB_CXXLDFLAGS + - name: Configure run: ./configure; cat src/Makevars diff --git a/DESCRIPTION b/DESCRIPTION index 0bf951d3..65f7805e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: RcppArmadillo Type: Package Title: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library -Version: 15.2.2-0 +Version: 15.2.2-0.1 Date: 2025-11-20 Authors@R: c(person("Dirk", "Eddelbuettel", role = c("aut", "cre"), email = "edd@debian.org", comment = c(ORCID = "0000-0001-6419-907X")), diff --git a/configure b/configure index 51ba2a2e..9a69d2aa 100755 --- a/configure +++ b/configure @@ -610,6 +610,8 @@ PACKAGE_URL='' ac_subst_vars='LTLIBOBJS LIBOBJS +PKG_LIBS +PKG_CXXFLAGS OPENMP_FLAG ARMA_HAVE_OPENMP CXXCPP @@ -3269,19 +3271,18 @@ EOF if test x"${SYSKERNEL}" = x"Linux"; then - ## Check if R is configured to compile programs using OpenMP out-of-the-box. + ## Check if R is configured to compile OpenMP programs out-of-the-box. if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5 printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; } - ## Execute R CMD SHLIB. "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" -##FIXME can_use_openmp="yes" + can_use_openmp="yes" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } @@ -3291,19 +3292,21 @@ printf "%s\n" "no" >&6; } fi fi - ## If needed, check if R is configured to compile programs using OpenMP with -fopenmp + ## If needed, check if R is configured to compile OpenMP programs using -fopenmp if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5 printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; } - ## Execute R CMD SHLIB. - PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" + PKG_LIBS="${PKG_LIBS} -fopenmp" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } @@ -3314,33 +3317,37 @@ printf "%s\n" "no" >&6; } fi fi +if test x"${SYSKERNEL}" = x"Darwin"; then + ## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp + if test x"${can_use_openmp}" = x"no"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'" >&5 +printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'... " >&6; } + + PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" + PKG_LIBS="${PKG_LIBS} -lomp" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi +fi ## Go back home. cd "${owd}" rm -rf "${BUILDDIR}" -## Additional Apple check -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for macOS" >&5 -printf %s "checking for macOS... " >&6; } -RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])') -if test x"${RSysinfoName}" = x"Darwin"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found" >&5 -printf "%s\n" "found" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for macOS Apple compiler" >&5 -printf %s "checking for macOS Apple compiler... " >&6; } - apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm') - if test x"${apple_compiler}" = x"1"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found" >&5 -printf "%s\n" "found" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: OpenMP unavailable and turned off." >&5 -printf "%s\n" "$as_me: WARNING: OpenMP unavailable and turned off." >&2;} - can_use_openmp="no" - fi -else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -printf "%s\n" "not found" >&6; } -fi if test x"${can_use_openmp}" = x"yes"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5 @@ -3366,6 +3373,10 @@ ARMA_HAVE_OPENMP="${arma_have_openmp}" OPENMP_FLAG="${openmp_flag}" +PKG_CXXFLAGS="${PKG_CXXFLAGS}" + +PKG_LIBS="${PKG_LIBS}" + ac_config_files="$ac_config_files inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h src/Makevars" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index 54b01af9..9806835b 100644 --- a/configure.ac +++ b/configure.ac @@ -68,17 +68,16 @@ EOF if test x"${SYSKERNEL}" = x"Linux"; then - ## Check if R is configured to compile programs using OpenMP out-of-the-box. + ## Check if R is configured to compile OpenMP programs out-of-the-box. if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs]) - ## Execute R CMD SHLIB. "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" -##FIXME can_use_openmp="yes" + can_use_openmp="yes" else AC_MSG_RESULT([no]) openmp_already_works="no" @@ -87,12 +86,11 @@ if test x"${SYSKERNEL}" = x"Linux"; then fi fi - ## If needed, check if R is configured to compile programs using OpenMP with -fopenmp + ## If needed, check if R is configured to compile OpenMP programs using -fopenmp if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp]) - ## Execute R CMD SHLIB. - PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) openmp_already_works="yes" @@ -110,27 +108,49 @@ if test x"${SYSKERNEL}" = x"Linux"; then fi fi +if test x"${SYSKERNEL}" = x"Darwin"; then + ## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp + if test x"${can_use_openmp}" = x"no"; then + AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp']) + + PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + openmp_already_works="yes" + arma_have_openmp="#define ARMA_USE_OPENMP 1" + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" + PKG_LIBS="${PKG_LIBS} -lomp" + else + AC_MSG_RESULT([no]) + openmp_already_works="no" + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + can_use_openmp="no" + fi + fi +fi ## Go back home. cd "${owd}" rm -rf "${BUILDDIR}" -## 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 - AC_MSG_RESULT([found]) - AC_MSG_CHECKING([for macOS Apple compiler]) - apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm') - if test x"${apple_compiler}" = x"1"; then - AC_MSG_RESULT([found]) - AC_MSG_WARN([OpenMP unavailable and turned off.]) - can_use_openmp="no" - fi -else - AC_MSG_RESULT([not found]) -fi +dnl ## Additional Apple check +dnl AC_MSG_CHECKING([for macOS]) +dnl RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])') +dnl if test x"${RSysinfoName}" = x"Darwin"; then +dnl AC_MSG_RESULT([found]) +dnl AC_MSG_CHECKING([for macOS Apple compiler]) +dnl apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm') +dnl if test x"${apple_compiler}" = x"1"; then +dnl AC_MSG_RESULT([found]) +dnl AC_MSG_WARN([OpenMP unavailable and turned off.]) +dnl can_use_openmp="no" +dnl fi +dnl else +dnl AC_MSG_RESULT([not found]) +dnl fi if test x"${can_use_openmp}" = x"yes"; then AC_MSG_CHECKING([for OpenMP]) @@ -151,5 +171,7 @@ fi ## now use all these AC_SUBST([ARMA_HAVE_OPENMP], ["${arma_have_openmp}"]) AC_SUBST([OPENMP_FLAG], ["${openmp_flag}"]) +AC_SUBST([PKG_CXXFLAGS], ["${PKG_CXXFLAGS}"]) +AC_SUBST([PKG_LIBS], ["${PKG_LIBS}"]) AC_CONFIG_FILES([inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h src/Makevars]) AC_OUTPUT diff --git a/src/Makevars.in b/src/Makevars.in index 5922ebc0..b3d490df 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -1,4 +1,4 @@ ## -*- mode: makefile; -*- PKG_CPPFLAGS = -I../inst/include -DARMA_USE_CURRENT -PKG_CXXFLAGS = @OPENMP_FLAG@ -PKG_LIBS= @OPENMP_FLAG@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) +PKG_CXXFLAGS = @PKG_CXXFLAGS@ @OPENMP_FLAG@ +PKG_LIBS= @PKG_LIBS@ @OPENMP_FLAG@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) From 31c5e2f19c786d1ebb160194fba9a4e41066ad13 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 10:09:45 -0600 Subject: [PATCH 3/8] Generalizing configure openmp treatment following data.table: part 2a --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 9a69d2aa..516e7557 100755 --- a/configure +++ b/configure @@ -3324,7 +3324,7 @@ if test x"${SYSKERNEL}" = x"Darwin"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'" >&5 printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'... " >&6; } - PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } diff --git a/configure.ac b/configure.ac index 9806835b..67751b91 100644 --- a/configure.ac +++ b/configure.ac @@ -114,7 +114,7 @@ if test x"${SYSKERNEL}" = x"Darwin"; then if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp']) - PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) openmp_already_works="yes" From b0ca0d24dde46b1045aa367c848d808bc207ca44 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 10:30:22 -0600 Subject: [PATCH 4/8] Generalizing configure openmp treatment following data.table: part 3 --- configure | 48 +++++++++++++++++++++------------------------- configure.ac | 54 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/configure b/configure index 516e7557..986dc593 100755 --- a/configure +++ b/configure @@ -3269,7 +3269,11 @@ int main() { } EOF +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether on Linux" >&5 +printf %s "checking whether on Linux... " >&6; } if test x"${SYSKERNEL}" = x"Linux"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } ## Check if R is configured to compile OpenMP programs out-of-the-box. if test x"${can_use_openmp}" = x"no"; then @@ -3280,13 +3284,13 @@ printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi @@ -3301,7 +3305,7 @@ printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set @@ -3310,14 +3314,21 @@ printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi -fi +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi # if Linux +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether on macOS" >&5 +printf %s "checking whether on macOS... " >&6; } if test x"${SYSKERNEL}" = x"Darwin"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } ## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp if test x"${can_use_openmp}" = x"no"; then @@ -3328,7 +3339,7 @@ printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xcla if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set @@ -3337,36 +3348,21 @@ printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi -fi +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi # if macOS ## Go back home. cd "${owd}" rm -rf "${BUILDDIR}" -if test x"${can_use_openmp}" = x"yes"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5 -printf %s "checking for OpenMP... " >&6; } - ## if R has -fopenmp we should be good - allldflags=$(${R_HOME}/bin/R CMD config --ldflags) - hasOpenMP=$(echo ${allldflags} | grep -- -fopenmp) - if test x"${hasOpenMP}" = x""; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: missing" >&5 -printf "%s\n" "missing" >&6; } - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" - openmp_flag="" - else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found and suitable" >&5 -printf "%s\n" "found and suitable" >&6; } - arma_have_openmp="#define ARMA_USE_OPENMP 1" - openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' - fi -fi ## now use all these ARMA_HAVE_OPENMP="${arma_have_openmp}" diff --git a/configure.ac b/configure.ac index 67751b91..a28652c9 100644 --- a/configure.ac +++ b/configure.ac @@ -66,7 +66,9 @@ int main() { } EOF +AC_MSG_CHECKING([whether on Linux]) if test x"${SYSKERNEL}" = x"Linux"; then + AC_MSG_RESULT([yes]) ## Check if R is configured to compile OpenMP programs out-of-the-box. if test x"${can_use_openmp}" = x"no"; then @@ -75,12 +77,12 @@ if test x"${SYSKERNEL}" = x"Linux"; then "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" else AC_MSG_RESULT([no]) - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi @@ -93,7 +95,7 @@ if test x"${SYSKERNEL}" = x"Linux"; then PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set @@ -101,14 +103,18 @@ if test x"${SYSKERNEL}" = x"Linux"; then PKG_LIBS="${PKG_LIBS} -fopenmp" else AC_MSG_RESULT([no]) - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi -fi +else + AC_MSG_RESULT([no]) +fi # if Linux +AC_MSG_CHECKING([whether on macOS]) if test x"${SYSKERNEL}" = x"Darwin"; then + AC_MSG_RESULT([yes]) ## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp if test x"${can_use_openmp}" = x"no"; then @@ -117,7 +123,7 @@ if test x"${SYSKERNEL}" = x"Darwin"; then PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - openmp_already_works="yes" + #openmp_already_works="yes" arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set @@ -125,12 +131,14 @@ if test x"${SYSKERNEL}" = x"Darwin"; then PKG_LIBS="${PKG_LIBS} -lomp" else AC_MSG_RESULT([no]) - openmp_already_works="no" + #openmp_already_works="no" arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi -fi +else + AC_MSG_RESULT([no]) +fi # if macOS ## Go back home. cd "${owd}" @@ -152,21 +160,21 @@ dnl else dnl AC_MSG_RESULT([not found]) dnl fi -if test x"${can_use_openmp}" = x"yes"; then - AC_MSG_CHECKING([for OpenMP]) - ## if R has -fopenmp we should be good - allldflags=$(${R_HOME}/bin/R CMD config --ldflags) - hasOpenMP=$(echo ${allldflags} | grep -- -fopenmp) - if test x"${hasOpenMP}" = x""; then - AC_MSG_RESULT([missing]) - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" - openmp_flag="" - else - AC_MSG_RESULT([found and suitable]) - arma_have_openmp="#define ARMA_USE_OPENMP 1" - openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' - fi -fi +dnl if test x"${can_use_openmp}" = x"yes"; then +dnl AC_MSG_CHECKING([for OpenMP]) +dnl ## if R has -fopenmp we should be good +dnl allldflags=$(${R_HOME}/bin/R CMD config --ldflags) +dnl hasOpenMP=$(echo ${allldflags} | grep -- -fopenmp) +dnl if test x"${hasOpenMP}" = x""; then +dnl AC_MSG_RESULT([missing]) +dnl arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" +dnl openmp_flag="" +dnl else +dnl AC_MSG_RESULT([found and suitable]) +dnl arma_have_openmp="#define ARMA_USE_OPENMP 1" +dnl openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' +dnl fi +dnl fi ## now use all these AC_SUBST([ARMA_HAVE_OPENMP], ["${arma_have_openmp}"]) From f9904f37be081e665e71d61dda4eb99fa6563642 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 10:57:03 -0600 Subject: [PATCH 5/8] Generalizing configure openmp treatment following data.table: part 4 --- configure | 90 +++++++++----- configure.ac | 113 ++++++++---------- .../config/RcppArmadilloConfigGenerated.h | 40 ------- 3 files changed, 114 insertions(+), 129 deletions(-) delete mode 100644 inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h diff --git a/configure b/configure index 986dc593..18e7d93c 100755 --- a/configure +++ b/configure @@ -3227,25 +3227,16 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +## Rely on Sys.info() from R for cross-compilation cases { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what system we are on" >&5 printf %s "checking what system we are on... " >&6; } -#SYSKERNEL=$(uname -s) -#SYSMACHINE=$(uname -m) -#SYSOS=$(uname -o) -#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}]) -## Rely on Sys.info() from R for cross-compilation cases SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])') SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["machine"])') { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: running ${SYSKERNEL} on ${SYSMACHINE}" >&5 printf "%s\n" "running ${SYSKERNEL} on ${SYSMACHINE}" >&6; } -## Is R already configured to compile things using OpenMP without -## any extra hand-holding? -#openmp_already_works="no" - -## default to not even thinking about OpenMP as Armadillo wants a pragma -## variant available if and only if C++11 is used with g++ 5.4 or newer +## Default to not assuming OpenMP, but then test a variety of setups can_use_openmp="no" ## Ensure TMPDIR is set. @@ -3279,19 +3270,14 @@ printf "%s\n" "yes" >&6; } if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5 printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; } - "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi @@ -3300,22 +3286,16 @@ printf "%s\n" "no" >&6; } if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5 printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; } - PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" - can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi @@ -3334,13 +3314,10 @@ printf "%s\n" "yes" >&6; } if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'" >&5 printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'... " >&6; } - PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" @@ -3348,10 +3325,52 @@ printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi + fi + + ## Check if R is configured to compile OpenMP programs using -fopenmp (cf data.table #6409) + if test x"${can_use_openmp}" = x"no"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-fopenmp'" >&5 +printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-fopenmp'... " >&6; } + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" + PKG_LIBS="${PKG_LIBS} -fopenmp" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + can_use_openmp="no" + fi + fi + + if test x"${can_use_openmp}" = x"no"; then + if test x"${SYSMACHINE}" = x"arm64"; then + HOMEBREW_PREFIX=/opt/homebrew + else + HOMEBREW_PREFIX=/usr/local + fi + if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp" >&5 +printf %s "checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp... " >&6; } + LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" + PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + can_use_openmp="no" + fi + fi fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 @@ -3362,9 +3381,22 @@ fi # if macOS cd "${owd}" rm -rf "${BUILDDIR}" +# Overall summary +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5 +printf %s "checking for OpenMP... " >&6; } +if test x"${can_use_openmp}" = x"yes"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found and suitable" >&5 +printf "%s\n" "found and suitable" >&6; } + arma_have_openmp="#define ARMA_USE_OPENMP 1" + openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: missing so no OpenMP acceleration" >&5 +printf "%s\n" "missing so no OpenMP acceleration" >&6; } + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + openmp_flag="" +fi - -## now use all these +## Now use all these ARMA_HAVE_OPENMP="${arma_have_openmp}" OPENMP_FLAG="${openmp_flag}" diff --git a/configure.ac b/configure.ac index a28652c9..d16a9662 100644 --- a/configure.ac +++ b/configure.ac @@ -28,23 +28,14 @@ AC_LANG(C++) AC_REQUIRE_CPP AC_PROG_CXX -AC_MSG_CHECKING([what system we are on]) -#SYSKERNEL=$(uname -s) -#SYSMACHINE=$(uname -m) -#SYSOS=$(uname -o) -#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}]) ## Rely on Sys.info() from R for cross-compilation cases +AC_MSG_CHECKING([what system we are on]) SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])') SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["machine"]])') AC_MSG_RESULT([running ${SYSKERNEL} on ${SYSMACHINE}]) -## Is R already configured to compile things using OpenMP without -## any extra hand-holding? -#openmp_already_works="no" - -## default to not even thinking about OpenMP as Armadillo wants a pragma -## variant available if and only if C++11 is used with g++ 5.4 or newer +## Default to not assuming OpenMP, but then test a variety of setups can_use_openmp="no" ## Ensure TMPDIR is set. @@ -73,17 +64,12 @@ if test x"${SYSKERNEL}" = x"Linux"; then ## Check if R is configured to compile OpenMP programs out-of-the-box. if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs]) - "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" else AC_MSG_RESULT([no]) - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi @@ -91,20 +77,14 @@ if test x"${SYSKERNEL}" = x"Linux"; then ## If needed, check if R is configured to compile OpenMP programs using -fopenmp if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp]) - PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" - can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" else AC_MSG_RESULT([no]) - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi fi @@ -119,22 +99,55 @@ if test x"${SYSKERNEL}" = x"Darwin"; then ## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp']) - PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) - #openmp_already_works="yes" - arma_have_openmp="#define ARMA_USE_OPENMP 1" can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" else AC_MSG_RESULT([no]) - #openmp_already_works="no" - arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" can_use_openmp="no" fi + fi + + ## Check if R is configured to compile OpenMP programs using -fopenmp (cf data.table #6409) + if test x"${can_use_openmp}" = x"no"; then + AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-fopenmp']) + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" + PKG_LIBS="${PKG_LIBS} -fopenmp" + else + AC_MSG_RESULT([no]) + can_use_openmp="no" + fi + fi + + if test x"${can_use_openmp}" = x"no"; then + if test x"${SYSMACHINE}" = x"arm64"; then + HOMEBREW_PREFIX=/opt/homebrew + else + HOMEBREW_PREFIX=/usr/local + fi + if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then + AC_MSG_CHECKING([whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp]) + LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + can_use_openmp="yes" + # keep any entries user may have set + PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" + PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + else + AC_MSG_RESULT([no]) + can_use_openmp="no" + fi + fi fi else AC_MSG_RESULT([no]) @@ -144,39 +157,19 @@ fi # if macOS cd "${owd}" rm -rf "${BUILDDIR}" -dnl ## Additional Apple check -dnl AC_MSG_CHECKING([for macOS]) -dnl RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])') -dnl if test x"${RSysinfoName}" = x"Darwin"; then -dnl AC_MSG_RESULT([found]) -dnl AC_MSG_CHECKING([for macOS Apple compiler]) -dnl apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm') -dnl if test x"${apple_compiler}" = x"1"; then -dnl AC_MSG_RESULT([found]) -dnl AC_MSG_WARN([OpenMP unavailable and turned off.]) -dnl can_use_openmp="no" -dnl fi -dnl else -dnl AC_MSG_RESULT([not found]) -dnl fi - -dnl if test x"${can_use_openmp}" = x"yes"; then -dnl AC_MSG_CHECKING([for OpenMP]) -dnl ## if R has -fopenmp we should be good -dnl allldflags=$(${R_HOME}/bin/R CMD config --ldflags) -dnl hasOpenMP=$(echo ${allldflags} | grep -- -fopenmp) -dnl if test x"${hasOpenMP}" = x""; then -dnl AC_MSG_RESULT([missing]) -dnl arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" -dnl openmp_flag="" -dnl else -dnl AC_MSG_RESULT([found and suitable]) -dnl arma_have_openmp="#define ARMA_USE_OPENMP 1" -dnl openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' -dnl fi -dnl fi - -## now use all these +# Overall summary +AC_MSG_CHECKING([for OpenMP]) +if test x"${can_use_openmp}" = x"yes"; then + AC_MSG_RESULT([found and suitable]) + arma_have_openmp="#define ARMA_USE_OPENMP 1" + openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)' +else + AC_MSG_RESULT([missing so no OpenMP acceleration]) + arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" + openmp_flag="" +fi + +## Now use all these AC_SUBST([ARMA_HAVE_OPENMP], ["${arma_have_openmp}"]) AC_SUBST([OPENMP_FLAG], ["${openmp_flag}"]) AC_SUBST([PKG_CXXFLAGS], ["${PKG_CXXFLAGS}"]) diff --git a/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h b/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h deleted file mode 100644 index ea766987..00000000 --- a/inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h +++ /dev/null @@ -1,40 +0,0 @@ - -// RcppArmadilloConfigGenerated.h: Autoconf-updated file for LAPACK and OpenMP choices -// -// Copyright (C) 2013 - 2025 Dirk Eddelbuettel -// 2025 James J. Balamuta -// -// This file is part of RcppArmadillo. -// -// RcppArmadillo is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// RcppArmadillo is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with RcppArmadillo. If not, see . - -#ifndef RcppArmadillo__RcppArmadilloConfigGenerated__h -#define RcppArmadillo__RcppArmadilloConfigGenerated__h - -// 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 - #define ARMA_USE_OPENMP 1 - #endif -#endif - -#endif From df0be7b8de817bbb0c9be21f0e835ac95d974e26 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 11:19:22 -0600 Subject: [PATCH 6/8] Generalizing configure openmp treatment following data.table: part 5 --- configure | 8 +++++--- configure.ac | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 18e7d93c..62702891 100755 --- a/configure +++ b/configure @@ -3357,14 +3357,16 @@ printf "%s\n" "no" >&6; } if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp" >&5 printf %s "checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp... " >&6; } - LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" + LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + PKG_CXXFLAGS="${PKG_CXXFLAGS} ${LIBOMP_INCLUDE}" PKG_LIBS="${PKG_LIBS} ${LIBOMP_LINK}" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } can_use_openmp="yes" # keep any entries user may have set - PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" - PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + PKG_CXXFLAGS="${PKG_CXXFLAGS} ${LIBOMP_INCLUDE}" + PKG_LIBS="${PKG_LIBS} ${LIBOMP_LINK}" else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } diff --git a/configure.ac b/configure.ac index d16a9662..6cb34ebe 100644 --- a/configure.ac +++ b/configure.ac @@ -136,13 +136,15 @@ if test x"${SYSKERNEL}" = x"Darwin"; then fi if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then AC_MSG_CHECKING([whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp]) - LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 + LIBOMP_INCLUDE="-I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" + LIBOMP_LINK="-L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + PKG_CXXFLAGS="${PKG_CXXFLAGS} ${LIBOMP_INCLUDE}" PKG_LIBS="${PKG_LIBS} ${LIBOMP_LINK}" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) can_use_openmp="yes" # keep any entries user may have set - PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp" - PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp" + PKG_CXXFLAGS="${PKG_CXXFLAGS} ${LIBOMP_INCLUDE}" + PKG_LIBS="${PKG_LIBS} ${LIBOMP_LINK}" else AC_MSG_RESULT([no]) can_use_openmp="no" From cf672e57811d6d2e2e665a17990001c53687e952 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 11:22:44 -0600 Subject: [PATCH 7/8] Generalizing configure openmp treatment following data.table: part 6 --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 62702891..f101145f 100755 --- a/configure +++ b/configure @@ -3286,7 +3286,7 @@ printf "%s\n" "no" >&6; } if test x"${can_use_openmp}" = x"no"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5 printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; } - PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } diff --git a/configure.ac b/configure.ac index 6cb34ebe..fc638a09 100644 --- a/configure.ac +++ b/configure.ac @@ -77,7 +77,7 @@ if test x"${SYSKERNEL}" = x"Linux"; then ## If needed, check if R is configured to compile OpenMP programs using -fopenmp if test x"${can_use_openmp}" = x"no"; then AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp]) - PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 + PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) # keep any entries user may have set From 4901e5e398f4995e3f13a78e0abf26e0cc5ab399 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Thu, 20 Nov 2025 11:26:08 -0600 Subject: [PATCH 8/8] Generalizing configure openmp treatment following data.table: part 7 --- configure | 3 ++- configure.ac | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/configure b/configure index f101145f..bdda4baf 100755 --- a/configure +++ b/configure @@ -3290,6 +3290,7 @@ printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6 if test x"$?" = x"0"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } + can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" @@ -3373,7 +3374,7 @@ printf "%s\n" "no" >&6; } can_use_openmp="no" fi fi - fi + fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } diff --git a/configure.ac b/configure.ac index fc638a09..1209d75e 100644 --- a/configure.ac +++ b/configure.ac @@ -80,6 +80,7 @@ if test x"${SYSKERNEL}" = x"Linux"; then PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1 if test x"$?" = x"0"; then AC_MSG_RESULT([yes]) + can_use_openmp="yes" # keep any entries user may have set PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" @@ -150,7 +151,7 @@ if test x"${SYSKERNEL}" = x"Darwin"; then can_use_openmp="no" fi fi - fi + fi else AC_MSG_RESULT([no]) fi # if macOS