Skip to content

Commit dc51b12

Browse files
committed
Generalizing configure openmp treatment following data.table: part 1
1 parent e49b8ce commit dc51b12

File tree

3 files changed

+155
-33
lines changed

3 files changed

+155
-33
lines changed

configure

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,13 +3225,26 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
32253225
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
32263226

32273227

3228+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what system we are on" >&5
3229+
printf %s "checking what system we are on... " >&6; }
3230+
#SYSKERNEL=$(uname -s)
3231+
#SYSMACHINE=$(uname -m)
3232+
#SYSOS=$(uname -o)
3233+
#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}])
3234+
## Rely on Sys.info() from R for cross-compilation cases
3235+
SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])')
3236+
SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["machine"])')
3237+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: running ${SYSKERNEL} on ${SYSMACHINE}" >&5
3238+
printf "%s\n" "running ${SYSKERNEL} on ${SYSMACHINE}" >&6; }
3239+
3240+
32283241
## Is R already configured to compile things using OpenMP without
32293242
## any extra hand-holding?
32303243
#openmp_already_works="no"
32313244

32323245
## default to not even thinking about OpenMP as Armadillo wants a pragma
32333246
## variant available if and only if C++11 is used with g++ 5.4 or newer
3234-
#can_use_openmp="no"
3247+
can_use_openmp="no"
32353248

32363249
## Ensure TMPDIR is set.
32373250
{ 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()))")
32403253
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${TMPDIR}" >&5
32413254
printf "%s\n" "${TMPDIR}" >&6; }
32423255

3243-
## Check if R is configured to compile programs using OpenMP out-of-the-box.
3244-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile programs using OpenMP" >&5
3245-
printf %s "checking whether R CMD SHLIB can already compile programs using OpenMP... " >&6; }
3246-
32473256
## Create private directory in TMPDIR.
32483257
BUILDDIR="${TMPDIR}/rcpparmadillo-$$-$RANDOM"
32493258
mkdir -p "${BUILDDIR}"
@@ -3258,22 +3267,55 @@ int main() {
32583267
}
32593268
EOF
32603269

3261-
## Execute R CMD SHLIB.
3262-
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
3263-
if test x"$?" = x"0"; then
3264-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3270+
if test x"${SYSKERNEL}" = x"Linux"; then
3271+
3272+
## Check if R is configured to compile programs using OpenMP out-of-the-box.
3273+
if test x"${can_use_openmp}" = x"no"; then
3274+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5
3275+
printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; }
3276+
3277+
## Execute R CMD SHLIB.
3278+
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
3279+
if test x"$?" = x"0"; then
3280+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
32653281
printf "%s\n" "yes" >&6; }
3266-
openmp_already_works="yes"
3267-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3268-
can_use_openmp="yes"
3269-
else
3270-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
3282+
openmp_already_works="yes"
3283+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3284+
##FIXME can_use_openmp="yes"
3285+
else
3286+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
3287+
printf "%s\n" "no" >&6; }
3288+
openmp_already_works="no"
3289+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
3290+
can_use_openmp="no"
3291+
fi
3292+
fi
3293+
3294+
## If needed, check if R is configured to compile programs using OpenMP with -fopenmp
3295+
if test x"${can_use_openmp}" = x"no"; then
3296+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5
3297+
printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; }
3298+
3299+
## Execute R CMD SHLIB.
3300+
PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
3301+
if test x"$?" = x"0"; then
3302+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3303+
printf "%s\n" "yes" >&6; }
3304+
openmp_already_works="yes"
3305+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3306+
can_use_openmp="yes"
3307+
else
3308+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
32713309
printf "%s\n" "no" >&6; }
3272-
openmp_already_works="no"
3273-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
3274-
can_use_openmp="no"
3310+
openmp_already_works="no"
3311+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
3312+
can_use_openmp="no"
3313+
fi
3314+
fi
32753315
fi
32763316

3317+
3318+
32773319
## Go back home.
32783320
cd "${owd}"
32793321
rm -rf "${BUILDDIR}"

configure.ac

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,30 @@ AC_LANG(C++)
2828
AC_REQUIRE_CPP
2929
AC_PROG_CXX
3030

31+
AC_MSG_CHECKING([what system we are on])
32+
#SYSKERNEL=$(uname -s)
33+
#SYSMACHINE=$(uname -m)
34+
#SYSOS=$(uname -o)
35+
#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}])
36+
## Rely on Sys.info() from R for cross-compilation cases
37+
SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
38+
SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["machine"]])')
39+
AC_MSG_RESULT([running ${SYSKERNEL} on ${SYSMACHINE}])
40+
41+
3142
## Is R already configured to compile things using OpenMP without
3243
## any extra hand-holding?
3344
#openmp_already_works="no"
3445

3546
## default to not even thinking about OpenMP as Armadillo wants a pragma
3647
## variant available if and only if C++11 is used with g++ 5.4 or newer
37-
#can_use_openmp="no"
48+
can_use_openmp="no"
3849

3950
## Ensure TMPDIR is set.
4051
AC_MSG_CHECKING([whether we have a suitable tempdir])
4152
TMPDIR=$("${R_HOME}/bin/R" --vanilla --slave -e "cat(dirname(tempdir()))")
4253
AC_MSG_RESULT([${TMPDIR}])
4354

44-
## Check if R is configured to compile programs using OpenMP out-of-the-box.
45-
AC_MSG_CHECKING([whether R CMD SHLIB can already compile programs using OpenMP])
46-
4755
## Create private directory in TMPDIR.
4856
BUILDDIR="${TMPDIR}/rcpparmadillo-$$-$RANDOM"
4957
mkdir -p "${BUILDDIR}"
@@ -58,20 +66,52 @@ int main() {
5866
}
5967
EOF
6068

61-
## Execute R CMD SHLIB.
62-
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
63-
if test x"$?" = x"0"; then
64-
AC_MSG_RESULT([yes])
65-
openmp_already_works="yes"
66-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
67-
can_use_openmp="yes"
68-
else
69-
AC_MSG_RESULT([no])
70-
openmp_already_works="no"
71-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
72-
can_use_openmp="no"
69+
if test x"${SYSKERNEL}" = x"Linux"; then
70+
71+
## Check if R is configured to compile programs using OpenMP out-of-the-box.
72+
if test x"${can_use_openmp}" = x"no"; then
73+
AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs])
74+
75+
## Execute R CMD SHLIB.
76+
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
77+
if test x"$?" = x"0"; then
78+
AC_MSG_RESULT([yes])
79+
openmp_already_works="yes"
80+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
81+
##FIXME can_use_openmp="yes"
82+
else
83+
AC_MSG_RESULT([no])
84+
openmp_already_works="no"
85+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
86+
can_use_openmp="no"
87+
fi
88+
fi
89+
90+
## If needed, check if R is configured to compile programs using OpenMP with -fopenmp
91+
if test x"${can_use_openmp}" = x"no"; then
92+
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp])
93+
94+
## Execute R CMD SHLIB.
95+
PKG_CXXFLAGS=-fopenmp PKG_LIBS=-fopen "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
96+
if test x"$?" = x"0"; then
97+
AC_MSG_RESULT([yes])
98+
openmp_already_works="yes"
99+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
100+
can_use_openmp="yes"
101+
# keep any entries user may have set
102+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
103+
PKG_LIBS="${PKG_LIBS} -fopenmp"
104+
else
105+
AC_MSG_RESULT([no])
106+
openmp_already_works="no"
107+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
108+
can_use_openmp="no"
109+
fi
110+
fi
73111
fi
74112

113+
114+
75115
## Go back home.
76116
cd "${owd}"
77117
rm -rf "${BUILDDIR}"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
// RcppArmadilloConfigGenerated.h: Autoconf-updated file for LAPACK and OpenMP choices
3+
//
4+
// Copyright (C) 2013 - 2025 Dirk Eddelbuettel
5+
// 2025 James J. Balamuta
6+
//
7+
// This file is part of RcppArmadillo.
8+
//
9+
// RcppArmadillo is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// RcppArmadillo is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef RcppArmadillo__RcppArmadilloConfigGenerated__h
23+
#define RcppArmadillo__RcppArmadilloConfigGenerated__h
24+
25+
// macOS special case as discussed in https://github.com/RcppCore/RcppArmadillo/issues/493
26+
#if !defined(ARMA_USE_OPENMP)
27+
#if defined(__APPLE__) && defined(_OPENMP)
28+
// User has OpenMP available, but check if they want it disabled
29+
#ifndef RCPPARMADILLO_MACOS_DISABLE_OPENMP
30+
#define ARMA_USE_OPENMP 1
31+
#else
32+
#define ARMA_DONT_USE_OPENMP 1
33+
#endif
34+
#else
35+
// from configure test for OpenMP based on how R is configured
36+
#define ARMA_USE_OPENMP 1
37+
#endif
38+
#endif
39+
40+
#endif

0 commit comments

Comments
 (0)