From 0485b0128a3932a1d0ea5b0bac30105072a84aa9 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sun, 26 Oct 2025 17:13:26 -0700 Subject: [PATCH 1/2] add configure script for OpenMP support - adapted from data.table --- configure | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Makevars.in | 4 ++++ 2 files changed, 62 insertions(+) create mode 100755 configure create mode 100644 src/Makevars.in diff --git a/configure b/configure new file mode 100755 index 00000000..587aff85 --- /dev/null +++ b/configure @@ -0,0 +1,58 @@ +#!/usr/bin/env sh + +# Find R compilers +CC=`${R_HOME}/bin/R CMD config CC` +CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS` +CXX=`${R_HOME}/bin/R CMD config CXX` +CXXFLAGS=`${R_HOME}/bin/R CMD config CXXFLAGS` + +# Test if we have OpenMP support +cat < test-omp.cpp +#include +int main() { + return omp_get_num_threads(); +} +EOF + +detect_openmp () { + if [ "$(uname)" = "Darwin" ]; then + # Test for macOS OpenMP support + printf "%s" "* checking if R installation supports OpenMP with \"-Xclang -fopenmp\" ... " + if CPPFLAGS="${CPPFLAGS} -Xclang -fopenmp" PKG_LIBS="-lomp" "${R_HOME}/bin/R" CMD SHLIB test-omp.cpp >> config.log 2>&1; then + echo "yes" + export R_OPENMP_ENABLED=1 + return + else + echo "no" + fi + fi + + if [ "$(uname)" = "Linux" ]; then + # Test for Linux OpenMP support + printf "%s" "* checking if R installation supports OpenMP with \"-fopenmp\" ... " + if ${CXX} ${CXXFLAGS} -fopenmp test-omp.cpp >> config.log 2>&1; then + echo "yes" + export R_OPENMP_ENABLED=1 + return + else + echo "no" + fi + fi + + # No OpenMP support found + export R_OPENMP_ENABLED=0 +} + +detect_openmp +rm -f test-omp.* a.out + +# Generate Makevars from template based on OpenMP detection +if [ "${R_OPENMP_ENABLED}" = "0" ]; then + echo "*** OpenMP not supported! fixest will run single-threaded." + sed -e "s/\$(SHLIB_OPENMP_CXXFLAGS)//g" src/Makevars.in > src/Makevars +else + # Keep the template as-is (OpenMP variables will be expanded by R) + cp src/Makevars.in src/Makevars +fi + +exit 0 diff --git a/src/Makevars.in b/src/Makevars.in new file mode 100644 index 00000000..4fc90886 --- /dev/null +++ b/src/Makevars.in @@ -0,0 +1,4 @@ + +PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DSTRICT_R_HEADERS +PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) + From 22aa2e989f6bf60f38caef473d5d906354962db7 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Sun, 26 Oct 2025 17:13:46 -0700 Subject: [PATCH 2/2] ignore config build log --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 65318205..81896181 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ altdoc/freeze.rds _quarto/* !_quarto/_freeze/ .DS_Store + +# Configure script outputs +config.log +src/Makevars