From 0b8f2d65487c8bbcd412524d7a67fe6d80e80ecb Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Mon, 4 May 2020 21:36:28 -0700 Subject: [PATCH] check for systems pre-configured to use OpenMP --- .gitignore | 2 ++ configure | 86 +++++++++++++++++++++++++++++++++++----------------- configure.ac | 43 ++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 1af2ed19..c19301f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .Rproj.user .Rhistory .RData +inst/include/RcppArmadilloConfigGenerated.h +src/Makevars src/*.o src/*.so src/*.dll diff --git a/configure b/configure index 9ab1037a..c905be81 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for RcppArmadillo 0.9.850.1.0.1. +# Generated by GNU Autoconf 2.69 for RcppArmadillo 0.9.860.2.0. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -576,8 +576,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='RcppArmadillo' PACKAGE_TARNAME='rcpparmadillo' -PACKAGE_VERSION='0.9.850.1.0.1' -PACKAGE_STRING='RcppArmadillo 0.9.850.1.0.1' +PACKAGE_VERSION='0.9.860.2.0' +PACKAGE_STRING='RcppArmadillo 0.9.860.2.0' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -613,7 +613,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -685,7 +684,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -938,15 +936,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1084,7 +1073,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1197,7 +1186,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures RcppArmadillo 0.9.850.1.0.1 to adapt to many kinds of systems. +\`configure' configures RcppArmadillo 0.9.860.2.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1237,7 +1226,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1259,7 +1247,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of RcppArmadillo 0.9.850.1.0.1:";; + short | recursive ) echo "Configuration of RcppArmadillo 0.9.860.2.0:";; esac cat <<\_ACEOF @@ -1339,7 +1327,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -RcppArmadillo configure 0.9.850.1.0.1 +RcppArmadillo configure 0.9.860.2.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1431,7 +1419,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by RcppArmadillo $as_me 0.9.850.1.0.1, which was +It was created by RcppArmadillo $as_me 0.9.860.2.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -1785,7 +1773,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -z "${R_HOME}"; then as_fn_error $? "Could not determine R_HOME." "$LINENO" 5 fi + ## Use R to set CXX and CXXFLAGS +R=${R_HOME}/bin/R CXX=$(${R_HOME}/bin/R CMD config CXX) CXXFLAGS=$("${R_HOME}/bin/R" CMD config CXXFLAGS) @@ -2439,12 +2429,6 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - -## 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="" - -## Check the C++ compiler using the CXX value set ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -2702,6 +2686,45 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + +## 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" + +## Check if R is configured to compile programs using OpenMP out-of-the-box. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether R can compile programs using OpenMP already" >&5 +$as_echo_n "checking whether R can compile programs using OpenMP already... " >&6; } + +owd=$(pwd) +cd "${TMPDIR}" + +cat < test-omp.cpp +#include +int main() { + return omp_get_num_threads(); +} +EOF + +"${R}" CMD SHLIB test-omp.cpp >/dev/null 2>&1 +if test x"$?" = x"0"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + openmp_already_works="yes" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + +cd "${owd}" + +if test x"${openmp_already_works}" = x"no"; then + +## Check the C++ compiler using the CXX value set + ## If it is g++, we have GXX set so let's examine it if test "${GXX}" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether g++ version is sufficient" >&5 @@ -2798,6 +2821,8 @@ else $as_echo "no" >&6; } fi +fi # if test x"${openmp_already_works}" = x"no" + ## Check for suitable LAPACK_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: checking LAPACK_LIBS" >&5 $as_echo_n "checking LAPACK_LIBS... " >&6; } @@ -2827,9 +2852,14 @@ fi ## Default the OpenMP flag to the empty string. ## If and only if OpenMP is found, expand to $(SHLIB_OPENMP_CXXFLAGS) openmp_flag="" + ## Set the fallback, by default it is nope arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" +if test x"${openmp_already_works}" = x"yes"; then + arma_have_openmp="#define ARMA_USE_OPENMP 1" +fi + if test x"${can_use_openmp}" = x"yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5 $as_echo_n "checking for OpenMP... " >&6; } @@ -3400,7 +3430,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by RcppArmadillo $as_me 0.9.850.1.0.1, which was +This file was extended by RcppArmadillo $as_me 0.9.860.2.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -3453,7 +3483,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -RcppArmadillo config.status 0.9.850.1.0.1 +RcppArmadillo config.status 0.9.860.2.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index d087ce9e..8ea9be8e 100644 --- a/configure.ac +++ b/configure.ac @@ -19,20 +19,52 @@ AC_INIT(RcppArmadillo, m4_esyscmd_s([awk -e '/^Version:/ {print $2}' DESCRIPTION if test -z "${R_HOME}"; then AC_MSG_ERROR([Could not determine R_HOME.]) fi + ## Use R to set CXX and CXXFLAGS +R=${R_HOME}/bin/R CXX=$(${R_HOME}/bin/R CMD config CXX) CXXFLAGS=$("${R_HOME}/bin/R" CMD config CXXFLAGS) ## We are using C++ AC_LANG(C++) AC_REQUIRE_CPP +AC_PROG_CXX + +## 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="" +can_use_openmp="no" + +## Check if R is configured to compile programs using OpenMP out-of-the-box. +AC_MSG_CHECKING([whether R can compile programs using OpenMP already]) + +owd=$(pwd) +cd "${TMPDIR}" + +cat < test-omp.cpp +#include +int main() { + return omp_get_num_threads(); +} +EOF + +"${R}" CMD SHLIB test-omp.cpp >/dev/null 2>&1 +if test x"$?" = x"0"; then + AC_MSG_RESULT([yes]) + openmp_already_works="yes" +else + AC_MSG_RESULT([no]) +fi + +cd "${owd}" + +if test x"${openmp_already_works}" = x"no"; then ## Check the C++ compiler using the CXX value set -AC_PROG_CXX + ## If it is g++, we have GXX set so let's examine it if test "${GXX}" = yes; then AC_MSG_CHECKING([whether g++ version is sufficient]) @@ -107,6 +139,8 @@ else AC_MSG_RESULT([no]) fi +fi # if test x"${openmp_already_works}" = x"no" + ## Check for suitable LAPACK_LIBS AC_MSG_CHECKING([LAPACK_LIBS]) @@ -132,9 +166,14 @@ fi ## Default the OpenMP flag to the empty string. ## If and only if OpenMP is found, expand to $(SHLIB_OPENMP_CXXFLAGS) openmp_flag="" + ## Set the fallback, by default it is nope arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1" +if test x"${openmp_already_works}" = x"yes"; then + arma_have_openmp="#define ARMA_USE_OPENMP 1" +fi + if test x"${can_use_openmp}" = x"yes"; then AC_MSG_CHECKING([for OpenMP]) ## if R has -fopenmp we should be good