Skip to content

Commit 5578acc

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

File tree

5 files changed

+106
-52
lines changed

5 files changed

+106
-52
lines changed

.github/workflows/ci.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515
matrix:
1616
include:
1717
- { name: container, os: ubuntu-latest, container: rocker/r2u4ci }
18-
- { name: macos, os: macos-latest }
18+
- { name: macos, os: macos-latest, openmp: yes }
19+
- { name: macos, os: macos-latest, openmp: no }
1920
#- { name: ubuntu, os: ubuntu-latest }
2021

2122

@@ -31,6 +32,26 @@ jobs:
3132
with:
3233
dev_version: 'TRUE'
3334

35+
- name: OpenMP for macOS
36+
if: ${{ matrix.os == 'macos-latest' && matrix.openmp == 'yes' }}
37+
run: |
38+
curl -fsSL https://raw.githubusercontent.com/coatless-shell/openmp/main/install-openmp.sh | bash -s -- --yes
39+
mkdir -p ~/.R
40+
cat <<EOF > ~/.R/Makevars
41+
CPPFLAGS += -Xclang -fopenmp
42+
LDFLAGS += -lomp
43+
EOF
44+
45+
- name: Show config on macOS
46+
if: ${{ matrix.os == 'macos-latest' && matrix.openmp == 'yes' }}
47+
run: |
48+
cat ~/.R/Makevars
49+
echo -n "R CMD config CXX: "; R CMD config CXX
50+
echo -n "R CMD config CPPFLAGS: "; R CMD config CPPFLAGS
51+
echo -n "R CMD config LDFLAGS: "; R CMD config LDFLAGS
52+
echo -n "R CMD config SHLIB_CXXLD: "; R CMD config SHLIB_CXXLD
53+
echo -n "R CMD config SHLIB_CXXLDFLAGS: "; R CMD config SHLIB_CXXLDFLAGS
54+
3455
- name: Configure
3556
run: ./configure; cat src/Makevars
3657

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: RcppArmadillo
22
Type: Package
33
Title: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library
4-
Version: 15.2.2-0
4+
Version: 15.2.2-0.1
55
Date: 2025-11-20
66
Authors@R: c(person("Dirk", "Eddelbuettel", role = c("aut", "cre"), email = "[email protected]",
77
comment = c(ORCID = "0000-0001-6419-907X")),

configure

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ PACKAGE_URL=''
610610

611611
ac_subst_vars='LTLIBOBJS
612612
LIBOBJS
613+
PKG_LIBS
614+
PKG_CXXFLAGS
613615
OPENMP_FLAG
614616
ARMA_HAVE_OPENMP
615617
CXXCPP
@@ -3269,19 +3271,18 @@ EOF
32693271

32703272
if test x"${SYSKERNEL}" = x"Linux"; then
32713273

3272-
## Check if R is configured to compile programs using OpenMP out-of-the-box.
3274+
## Check if R is configured to compile OpenMP programs out-of-the-box.
32733275
if test x"${can_use_openmp}" = x"no"; then
32743276
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can already compile OpenMP programs" >&5
32753277
printf %s "checking whether R CMD SHLIB can already compile OpenMP programs... " >&6; }
32763278

3277-
## Execute R CMD SHLIB.
32783279
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
32793280
if test x"$?" = x"0"; then
32803281
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
32813282
printf "%s\n" "yes" >&6; }
32823283
openmp_already_works="yes"
32833284
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3284-
##FIXME can_use_openmp="yes"
3285+
can_use_openmp="yes"
32853286
else
32863287
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
32873288
printf "%s\n" "no" >&6; }
@@ -3291,19 +3292,21 @@ printf "%s\n" "no" >&6; }
32913292
fi
32923293
fi
32933294

3294-
## If needed, check if R is configured to compile programs using OpenMP with -fopenmp
3295+
## If needed, check if R is configured to compile OpenMP programs using -fopenmp
32953296
if test x"${can_use_openmp}" = x"no"; then
32963297
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP via -fopenmp" >&5
32973298
printf %s "checking whether R CMD SHLIB can compile OpenMP via -fopenmp... " >&6; }
32983299

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
3300+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
33013301
if test x"$?" = x"0"; then
33023302
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
33033303
printf "%s\n" "yes" >&6; }
33043304
openmp_already_works="yes"
33053305
arma_have_openmp="#define ARMA_USE_OPENMP 1"
33063306
can_use_openmp="yes"
3307+
# keep any entries user may have set
3308+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp"
3309+
PKG_LIBS="${PKG_LIBS} -fopenmp"
33073310
else
33083311
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
33093312
printf "%s\n" "no" >&6; }
@@ -3314,33 +3317,37 @@ printf "%s\n" "no" >&6; }
33143317
fi
33153318
fi
33163319

3320+
if test x"${SYSKERNEL}" = x"Darwin"; then
33173321

3322+
## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp
3323+
if test x"${can_use_openmp}" = x"no"; then
3324+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'" >&5
3325+
printf %s "checking whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'... " >&6; }
3326+
3327+
PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
3328+
if test x"$?" = x"0"; then
3329+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3330+
printf "%s\n" "yes" >&6; }
3331+
openmp_already_works="yes"
3332+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
3333+
can_use_openmp="yes"
3334+
# keep any entries user may have set
3335+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp"
3336+
PKG_LIBS="${PKG_LIBS} -lomp"
3337+
else
3338+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
3339+
printf "%s\n" "no" >&6; }
3340+
openmp_already_works="no"
3341+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
3342+
can_use_openmp="no"
3343+
fi
3344+
fi
3345+
fi
33183346

33193347
## Go back home.
33203348
cd "${owd}"
33213349
rm -rf "${BUILDDIR}"
33223350

3323-
## Additional Apple check
3324-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for macOS" >&5
3325-
printf %s "checking for macOS... " >&6; }
3326-
RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()["sysname"])')
3327-
if test x"${RSysinfoName}" = x"Darwin"; then
3328-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found" >&5
3329-
printf "%s\n" "found" >&6; }
3330-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for macOS Apple compiler" >&5
3331-
printf %s "checking for macOS Apple compiler... " >&6; }
3332-
apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm')
3333-
if test x"${apple_compiler}" = x"1"; then
3334-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found" >&5
3335-
printf "%s\n" "found" >&6; }
3336-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: OpenMP unavailable and turned off." >&5
3337-
printf "%s\n" "$as_me: WARNING: OpenMP unavailable and turned off." >&2;}
3338-
can_use_openmp="no"
3339-
fi
3340-
else
3341-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: not found" >&5
3342-
printf "%s\n" "not found" >&6; }
3343-
fi
33443351

33453352
if test x"${can_use_openmp}" = x"yes"; then
33463353
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OpenMP" >&5
@@ -3366,6 +3373,10 @@ ARMA_HAVE_OPENMP="${arma_have_openmp}"
33663373

33673374
OPENMP_FLAG="${openmp_flag}"
33683375

3376+
PKG_CXXFLAGS="${PKG_CXXFLAGS}"
3377+
3378+
PKG_LIBS="${PKG_LIBS}"
3379+
33693380
ac_config_files="$ac_config_files inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h src/Makevars"
33703381

33713382
cat >confcache <<\_ACEOF

configure.ac

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ EOF
6868

6969
if test x"${SYSKERNEL}" = x"Linux"; then
7070

71-
## Check if R is configured to compile programs using OpenMP out-of-the-box.
71+
## Check if R is configured to compile OpenMP programs out-of-the-box.
7272
if test x"${can_use_openmp}" = x"no"; then
7373
AC_MSG_CHECKING([whether R CMD SHLIB can already compile OpenMP programs])
7474

75-
## Execute R CMD SHLIB.
7675
"${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >/dev/null 2>&1
7776
if test x"$?" = x"0"; then
7877
AC_MSG_RESULT([yes])
7978
openmp_already_works="yes"
8079
arma_have_openmp="#define ARMA_USE_OPENMP 1"
81-
##FIXME can_use_openmp="yes"
80+
can_use_openmp="yes"
8281
else
8382
AC_MSG_RESULT([no])
8483
openmp_already_works="no"
@@ -87,12 +86,11 @@ if test x"${SYSKERNEL}" = x"Linux"; then
8786
fi
8887
fi
8988

90-
## If needed, check if R is configured to compile programs using OpenMP with -fopenmp
89+
## If needed, check if R is configured to compile OpenMP programs using -fopenmp
9190
if test x"${can_use_openmp}" = x"no"; then
9291
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP via -fopenmp])
9392

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
93+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -fopenmp" PKG_LIBS="${PKG_LIBS} -fopen" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
9694
if test x"$?" = x"0"; then
9795
AC_MSG_RESULT([yes])
9896
openmp_already_works="yes"
@@ -110,27 +108,49 @@ if test x"${SYSKERNEL}" = x"Linux"; then
110108
fi
111109
fi
112110

111+
if test x"${SYSKERNEL}" = x"Darwin"; then
113112

113+
## Check if R is configured to compile OpenMP programs using -Xclang -fopenmp
114+
if test x"${can_use_openmp}" = x"no"; then
115+
AC_MSG_CHECKING([whether R CMD SHLIB can compile OpenMP programs using '-Xclang -fopenmp'])
116+
117+
PKG_CXXFLAGS=-Xclang -fopenmp PKG_LIBS="${PKG_LIBS} -lomp" "${R_HOME}/bin/R" CMD SHLIB -fopenmp test-omp.cpp >/dev/null 2>&1
118+
if test x"$?" = x"0"; then
119+
AC_MSG_RESULT([yes])
120+
openmp_already_works="yes"
121+
arma_have_openmp="#define ARMA_USE_OPENMP 1"
122+
can_use_openmp="yes"
123+
# keep any entries user may have set
124+
PKG_CXXFLAGS="${PKG_CXXFLAGS} -Xclang -fopenmp"
125+
PKG_LIBS="${PKG_LIBS} -lomp"
126+
else
127+
AC_MSG_RESULT([no])
128+
openmp_already_works="no"
129+
arma_have_openmp="#define ARMA_DONT_USE_OPENMP 1"
130+
can_use_openmp="no"
131+
fi
132+
fi
133+
fi
114134

115135
## Go back home.
116136
cd "${owd}"
117137
rm -rf "${BUILDDIR}"
118138

119-
## Additional Apple check
120-
AC_MSG_CHECKING([for macOS])
121-
RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
122-
if test x"${RSysinfoName}" = x"Darwin"; then
123-
AC_MSG_RESULT([found])
124-
AC_MSG_CHECKING([for macOS Apple compiler])
125-
apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm')
126-
if test x"${apple_compiler}" = x"1"; then
127-
AC_MSG_RESULT([found])
128-
AC_MSG_WARN([OpenMP unavailable and turned off.])
129-
can_use_openmp="no"
130-
fi
131-
else
132-
AC_MSG_RESULT([not found])
133-
fi
139+
dnl ## Additional Apple check
140+
dnl AC_MSG_CHECKING([for macOS])
141+
dnl RSysinfoName=$("${R_HOME}/bin/Rscript" --vanilla -e 'cat(Sys.info()[["sysname"]])')
142+
dnl if test x"${RSysinfoName}" = x"Darwin"; then
143+
dnl AC_MSG_RESULT([found])
144+
dnl AC_MSG_CHECKING([for macOS Apple compiler])
145+
dnl apple_compiler=$($CXX --version 2>&1 | grep -i -c -e 'apple llvm')
146+
dnl if test x"${apple_compiler}" = x"1"; then
147+
dnl AC_MSG_RESULT([found])
148+
dnl AC_MSG_WARN([OpenMP unavailable and turned off.])
149+
dnl can_use_openmp="no"
150+
dnl fi
151+
dnl else
152+
dnl AC_MSG_RESULT([not found])
153+
dnl fi
134154

135155
if test x"${can_use_openmp}" = x"yes"; then
136156
AC_MSG_CHECKING([for OpenMP])
@@ -151,5 +171,7 @@ fi
151171
## now use all these
152172
AC_SUBST([ARMA_HAVE_OPENMP], ["${arma_have_openmp}"])
153173
AC_SUBST([OPENMP_FLAG], ["${openmp_flag}"])
174+
AC_SUBST([PKG_CXXFLAGS], ["${PKG_CXXFLAGS}"])
175+
AC_SUBST([PKG_LIBS], ["${PKG_LIBS}"])
154176
AC_CONFIG_FILES([inst/include/RcppArmadillo/config/RcppArmadilloConfigGenerated.h src/Makevars])
155177
AC_OUTPUT

src/Makevars.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## -*- mode: makefile; -*-
22
PKG_CPPFLAGS = -I../inst/include -DARMA_USE_CURRENT
3-
PKG_CXXFLAGS = @OPENMP_FLAG@
4-
PKG_LIBS= @OPENMP_FLAG@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
3+
PKG_CXXFLAGS = @PKG_CXXFLAGS@ @OPENMP_FLAG@
4+
PKG_LIBS= @PKG_LIBS@ @OPENMP_FLAG@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

0 commit comments

Comments
 (0)