Skip to content

Commit

Permalink
Detect OpenMP support
Browse files Browse the repository at this point in the history
This detects support for OpenMP and only includes the compiler flags for
it if OpenMP is supported.

This solves the common case on macOS, because R on macOS ships with
`-fopenmp` in SHLIB_OPENMP_CFLAGS, as the CRAN compiler toolchain _does_
support OpenMP, however the XCode toolchain distributed by Apple _does
 not_ support OpenMP, which causes data.table to fail to compile from
 source.

Fixes Rdatatable#2161
  • Loading branch information
jimhester committed Oct 21, 2019
1 parent b8dd0db commit 4626160
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -15,6 +15,7 @@
^NEWS\.0\.md$
^README\.md$
^_pkgdown\.yml$
^src/Makevars$

^\.RData$
^\.Rhistory$
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ Rplots.pdf
*-Ex.R
data.table_*.tar.gz
data.table.Rcheck
src/Makevars

# Emacs IDE files
.emacs.desktop
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Expand Up @@ -6,6 +6,10 @@

## NEW FEATURES

* Compiler support for OpenMP is now detected during installation, which allows
data.table to compile even if the users' toolchain differs from CRANs, as is
common on macOS. (#2161, @jimhester)

## BUG FIXES

## NOTES
Expand Down
2 changes: 2 additions & 0 deletions cleanup
@@ -0,0 +1,2 @@
#!/bin/sh
rm -f src/Makevars
19 changes: 18 additions & 1 deletion configure
Expand Up @@ -50,5 +50,22 @@ fi

version=`pkg-config --modversion zlib`
echo "zlib ${version} is available ok"
exit 0

# Find R compilers
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS`

# Test if we have a OPENMP compatible compiler
echo "#include <omp.h>\nint main () { return omp_get_num_threads (); }" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} ${SHLIB_OPENMP_CFLAGS} -E -xc - >/dev/null 2>&1 || R_NO_OPENMP=1;

# Write to Makevars
if [ $R_NO_OPENMP ]; then
sed -e "s|@openmp_cflags@||" src/Makevars.in > src/Makevars
else
echo "OpenMP supported"
sed -e "s|@openmp_cflags@|\$(SHLIB_OPENMP_CFLAGS)|" src/Makevars.in > src/Makevars
fi


exit 0
7 changes: 2 additions & 5 deletions src/Makevars → src/Makevars.in
@@ -1,9 +1,6 @@

PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) -lz
PKG_CFLAGS = @openmp_cflags@
PKG_LIBS = @openmp_cflags@ -lz

all: $(SHLIB)
mv $(SHLIB) datatable$(SHLIB_EXT)
if [ "$(OS)" != "Windows_NT" ] && [ `uname -s` = 'Darwin' ]; then install_name_tool -id datatable$(SHLIB_EXT) datatable$(SHLIB_EXT); fi


5 changes: 5 additions & 0 deletions src/Makevars.win
@@ -0,0 +1,5 @@
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) -lz

all: $(SHLIB)
mv $(SHLIB) datatable$(SHLIB_EXT)

0 comments on commit 4626160

Please sign in to comment.