Conversation
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
| ^NEWS\.0\.md$ | ||
| ^README\.md$ | ||
| ^_pkgdown\.yml$ | ||
| ^src/Makevars$ |
There was a problem hiding this comment.
We need to ignore the generated Makevars in both git and the built package, we generate it from src/Makevars.in in the configure script.
| @@ -0,0 +1,2 @@ | |||
| #!/bin/sh | |||
| rm -f src/Makevars | |||
There was a problem hiding this comment.
We need to cleanup the generated file with the cleanup script
| 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; |
There was a problem hiding this comment.
Here we test a simple OpenMP program with what is in SHLIB_OPENMP_CFLAGS to verify that our current compiler supports OpenMP.
| @@ -0,0 +1,5 @@ | |||
| PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS) | |||
There was a problem hiding this comment.
configure will only run on non-Windows, which means that src/Makevars will not be generated there, so we need to supply Makevars.win for windows. But we don't really need to check if OpenMP is supported, because the Rtools compilers all support it.
| 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 |
There was a problem hiding this comment.
Then we replace the placeholder @openmp_cflags@ with either nothing if the compiler doesn't support it or SHLIB_OPENMP_CFLAGS if it does.
Codecov Report
@@ Coverage Diff @@
## master #3984 +/- ##
======================================
Coverage 99.4% 99.4%
======================================
Files 72 72
Lines 13675 13675
======================================
Hits 13594 13594
Misses 81 81Continue to review full report at Codecov.
|
|
@MichaelChirico I added a message linking to the wiki in 576c852, let me know if there is anything else I can do. |
|
Thanks, @jimhester! This looks great. The message is great to see on installation. There is a package startup message too if it detects it wasn't compiled at that point. |
…t even worked before or what changed. #3984 just merged seems likely, but I don't see why. It's more like cc.R was already wrong and its luck ran out. Oh well, moving on. cc() works again now and I checked R CMD INSTALL already still created datatable.so without dot as before.
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
-fopenmpin SHLIB_OPENMP_CFLAGS, as the CRAN compiler toolchain doessupport OpenMP, however the XCode toolchain distributed by Apple does
not support OpenMP, which causes data.table to fail to compile from
source.
Fixes #2161