Skip to content

Commit f9904f3

Browse files
committed
Generalizing configure openmp treatment following data.table: part 4
1 parent b0ca0d2 commit f9904f3

File tree

3 files changed

+114
-129
lines changed

3 files changed

+114
-129
lines changed

configure

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,25 +3227,16 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
32273227
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
32283228

32293229

3230+
## Rely on Sys.info() from R for cross-compilation cases
32303231
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what system we are on" >&5
32313232
printf %s "checking what system we are on... " >&6; }
3232-
#SYSKERNEL=$(uname -s)
3233-
#SYSMACHINE=$(uname -m)
3234-
#SYSOS=$(uname -o)
3235-
#AC_MSG_RESULT([${SYSKERNEL} ${SYSMACHINE} ${SYSOS}])
3236-
## Rely on Sys.info() from R for cross-compilation cases
32373233
SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])')
32383234
SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["machine"])')
32393235
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: running ${SYSKERNEL} on ${SYSMACHINE}" >&5
32403236
printf "%s\n" "running ${SYSKERNEL} on ${SYSMACHINE}" >&6; }
32413237

32423238

3243-
## Is R already configured to compile things using OpenMP without
3244-
## any extra hand-holding?
3245-
#openmp_already_works="no"
3246-
3247-
## default to not even thinking about OpenMP as Armadillo wants a pragma
3248-
## variant available if and only if C++11 is used with g++ 5.4 or newer
3239+
## Default to not assuming OpenMP, but then test a variety of setups
32493240
can_use_openmp="no"
32503241

32513242
## Ensure TMPDIR is set.
@@ -3279,19 +3270,14 @@ printf "%s\n" "yes" >&6; }
32793270
if test x"${can_use_openmp}" = x"no"; then
32803271
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5
32813272
printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; }
3282-
32833273
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
32843274
if test x"$?" = x"0"; then
32853275
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
32863276
printf "%s\n" "yes" >&6; }
3287-
#openmp_already_works="yes"
3288-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
32893277
can_use_openmp="yes"
32903278
else
32913279
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
32923280
printf "%s\n" "no" >&6; }
3293-
#openmp_already_works="no"
3294-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
32953281
can_use_openmp="no"
32963282
fi
32973283
fi
@@ -3300,22 +3286,16 @@ printf "%s\n" "no" >&6; }
33003286
if test x"${can_use_openmp}" = x"no"; then
33013287
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5
33023288
printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; }
3303-
33043289
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
33053290
if test x"$?" = x"0"; then
33063291
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
33073292
printf "%s\n" "yes" >&6; }
3308-
#openmp_already_works="yes"
3309-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3310-
can_use_openmp="yes"
33113293
# keep any entries user may have set
33123294
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
33133295
PKG_LIBS="${PKG_LIBS} -fopenmp"
33143296
else
33153297
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
33163298
printf "%s\n" "no" >&6; }
3317-
#openmp_already_works="no"
3318-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
33193299
can_use_openmp="no"
33203300
fi
33213301
fi
@@ -3334,24 +3314,63 @@ printf "%s\n" "yes" >&6; }
33343314
if test x"${can_use_openmp}" = x"no"; then
33353315
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'" >&5
33363316
printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'... " >&6; }
3337-
33383317
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
33393318
if test x"$?" = x"0"; then
33403319
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
33413320
printf "%s\n" "yes" >&6; }
3342-
#openmp_already_works="yes"
3343-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
33443321
can_use_openmp="yes"
33453322
# keep any entries user may have set
33463323
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp"
33473324
PKG_LIBS="${PKG_LIBS} -lomp"
33483325
else
33493326
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
33503327
printf "%s\n" "no" >&6; }
3351-
#openmp_already_works="no"
3352-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
33533328
can_use_openmp="no"
33543329
fi
3330+
fi
3331+
3332+
## Check if R is configured to compile OpenMP programs using -fopenmp (cf data.table #6409)
3333+
if test x"${can_use_openmp}" = x"no"; then
3334+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-fopenmp'" >&5
3335+
printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-fopenmp'... " >&6; }
3336+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
3337+
if test x"$?" = x"0"; then
3338+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3339+
printf "%s\n" "yes" >&6; }
3340+
can_use_openmp="yes"
3341+
# keep any entries user may have set
3342+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
3343+
PKG_LIBS="${PKG_LIBS} -fopenmp"
3344+
else
3345+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
3346+
printf "%s\n" "no" >&6; }
3347+
can_use_openmp="no"
3348+
fi
3349+
fi
3350+
3351+
if test x"${can_use_openmp}" = x"no"; then
3352+
if test x"${SYSMACHINE}" = x"arm64"; then
3353+
HOMEBREW_PREFIX=/opt/homebrew
3354+
else
3355+
HOMEBREW_PREFIX=/usr/local
3356+
fi
3357+
if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then
3358+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp" >&5
3359+
printf %s "checking whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp... " >&6; }
3360+
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
3361+
if test x"$?" = x"0"; then
3362+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3363+
printf "%s\n" "yes" >&6; }
3364+
can_use_openmp="yes"
3365+
# keep any entries user may have set
3366+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp"
3367+
PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp"
3368+
else
3369+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
3370+
printf "%s\n" "no" >&6; }
3371+
can_use_openmp="no"
3372+
fi
3373+
fi
33553374
fi
33563375
else
33573376
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -3362,9 +3381,22 @@ fi # if macOS
33623381
cd "${owd}"
33633382
rm -rf "${BUILDDIR}"
33643383

3384+
# Overall summary
3385+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5
3386+
printf %s "checking for OpenMP... " >&6; }
3387+
if test x"${can_use_openmp}" = x"yes"; then
3388+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found and suitable" >&5
3389+
printf "%s\n" "found and suitable" >&6; }
3390+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3391+
openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)'
3392+
else
3393+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: missing so no OpenMP acceleration" >&5
3394+
printf "%s\n" "missing so no OpenMP acceleration" >&6; }
3395+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
3396+
openmp_flag=""
3397+
fi
33653398

3366-
3367-
## now use all these
3399+
## Now use all these
33683400
ARMA_HAVE_OPENMP="${arma_have_openmp}"
33693401

33703402
OPENMP_FLAG="${openmp_flag}"

configure.ac

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,14 @@ 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}])
3631
## Rely on Sys.info() from R for cross-compilation cases
32+
AC_MSG_CHECKING([what system we are on])
3733
SYSKERNEL=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
3834
SYSMACHINE=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["machine"]])')
3935
AC_MSG_RESULT([running ${SYSKERNEL} on ${SYSMACHINE}])
4036

4137

42-
## Is R already configured to compile things using OpenMP without
43-
## any extra hand-holding?
44-
#openmp_already_works="no"
45-
46-
## default to not even thinking about OpenMP as Armadillo wants a pragma
47-
## variant available if and only if C++11 is used with g++ 5.4 or newer
38+
## Default to not assuming OpenMP, but then test a variety of setups
4839
can_use_openmp="no"
4940

5041
## Ensure TMPDIR is set.
@@ -73,38 +64,27 @@ if test x"${SYSKERNEL}" = x"Linux"; then
7364
## Check if R is configured to compile OpenMP programs out-of-the-box.
7465
if test x"${can_use_openmp}" = x"no"; then
7566
AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs])
76-
7767
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
7868
if test x"$?" = x"0"; then
7969
AC_MSG_RESULT([yes])
80-
#openmp_already_works="yes"
81-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
8270
can_use_openmp="yes"
8371
else
8472
AC_MSG_RESULT([no])
85-
#openmp_already_works="no"
86-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
8773
can_use_openmp="no"
8874
fi
8975
fi
9076

9177
## If needed, check if R is configured to compile OpenMP programs using -fopenmp
9278
if test x"${can_use_openmp}" = x"no"; then
9379
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp])
94-
9580
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
9681
if test x"$?" = x"0"; then
9782
AC_MSG_RESULT([yes])
98-
#openmp_already_works="yes"
99-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
100-
can_use_openmp="yes"
10183
# keep any entries user may have set
10284
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
10385
PKG_LIBS="${PKG_LIBS} -fopenmp"
10486
else
10587
AC_MSG_RESULT([no])
106-
#openmp_already_works="no"
107-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
10888
can_use_openmp="no"
10989
fi
11090
fi
@@ -119,22 +99,55 @@ if test x"${SYSKERNEL}" = x"Darwin"; then
11999
## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp
120100
if test x"${can_use_openmp}" = x"no"; then
121101
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'])
122-
123102
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp" PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
124103
if test x"$?" = x"0"; then
125104
AC_MSG_RESULT([yes])
126-
#openmp_already_works="yes"
127-
arma_have_openmp="#define ARMA_USE_OPENMP 1"
128105
can_use_openmp="yes"
129106
# keep any entries user may have set
130107
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp"
131108
PKG_LIBS="${PKG_LIBS} -lomp"
132109
else
133110
AC_MSG_RESULT([no])
134-
#openmp_already_works="no"
135-
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
136111
can_use_openmp="no"
137112
fi
113+
fi
114+
115+
## Check if R is configured to compile OpenMP programs using -fopenmp (cf data.table #6409)
116+
if test x"${can_use_openmp}" = x"no"; then
117+
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-fopenmp'])
118+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopenmp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
119+
if test x"$?" = x"0"; then
120+
AC_MSG_RESULT([yes])
121+
can_use_openmp="yes"
122+
# keep any entries user may have set
123+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
124+
PKG_LIBS="${PKG_LIBS} -fopenmp"
125+
else
126+
AC_MSG_RESULT([no])
127+
can_use_openmp="no"
128+
fi
129+
fi
130+
131+
if test x"${can_use_openmp}" = x"no"; then
132+
if test x"${SYSMACHINE}" = x"arm64"; then
133+
HOMEBREW_PREFIX=/opt/homebrew
134+
else
135+
HOMEBREW_PREFIX=/usr/local
136+
fi
137+
if test -e "${HOMEBREW_PREFIX}/opt/libomp"; then
138+
AC_MSG_CHECKING([whether R CMD SHLIB can use libomp at ${HOMEBREW_PREFIX}/opt/libomp])
139+
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
140+
if test x"$?" = x"0"; then
141+
AC_MSG_RESULT([yes])
142+
can_use_openmp="yes"
143+
# keep any entries user may have set
144+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -I${HOMEBREW_PREFIX}/opt/libomp/include -Xclang -fopenmp"
145+
PKG_LIBS="${PKG_LIBS} -L${HOMEBREW_PREFIX}/opt/libomp/lib -lomp"
146+
else
147+
AC_MSG_RESULT([no])
148+
can_use_openmp="no"
149+
fi
150+
fi
138151
fi
139152
else
140153
AC_MSG_RESULT([no])
@@ -144,39 +157,19 @@ fi # if macOS
144157
cd "${owd}"
145158
rm -rf "${BUILDDIR}"
146159

147-
dnl ## Additional Apple check
148-
dnl AC_MSG_CHECKING([for macOS])
149-
dnl RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
150-
dnl if test x"${RSysinfoName}" = x"Darwin"; then
151-
dnl AC_MSG_RESULT([found])
152-
dnl AC_MSG_CHECKING([for macOS Apple compiler])
153-
dnl apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm')
154-
dnl if test x"${apple_compiler}" = x"1"; then
155-
dnl AC_MSG_RESULT([found])
156-
dnl AC_MSG_WARN([OpenMP unavailable and turned off.])
157-
dnl can_use_openmp="no"
158-
dnl fi
159-
dnl else
160-
dnl AC_MSG_RESULT([not found])
161-
dnl fi
162-
163-
dnl if test x"${can_use_openmp}" = x"yes"; then
164-
dnl AC_MSG_CHECKING([for OpenMP])
165-
dnl ## if R has -fopenmp we should be good
166-
dnl allldflags=$(${R_HOME}/bin/R CMD config --ldflags)
167-
dnl hasOpenMP=$(echo ${allldflags} | grep -- -fopenmp)
168-
dnl if test x"${hasOpenMP}" = x""; then
169-
dnl AC_MSG_RESULT([missing])
170-
dnl arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
171-
dnl openmp_flag=""
172-
dnl else
173-
dnl AC_MSG_RESULT([found and suitable])
174-
dnl arma_have_openmp="#define ARMA_USE_OPENMP 1"
175-
dnl openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)'
176-
dnl fi
177-
dnl fi
178-
179-
## now use all these
160+
# Overall summary
161+
AC_MSG_CHECKING([for OpenMP])
162+
if test x"${can_use_openmp}" = x"yes"; then
163+
AC_MSG_RESULT([found and suitable])
164+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
165+
openmp_flag='$(SHLIB_OPENMP_CXXFLAGS)'
166+
else
167+
AC_MSG_RESULT([missing so no OpenMP acceleration])
168+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
169+
openmp_flag=""
170+
fi
171+
172+
## Now use all these
180173
AC_SUBST([ARMA_HAVE_OPENMP], ["${arma_have_openmp}"])
181174
AC_SUBST([OPENMP_FLAG], ["${openmp_flag}"])
182175
AC_SUBST([PKG_CXXFLAGS], ["${PKG_CXXFLAGS}"])

inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)