Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ altdoc/freeze.rds
_quarto/*
!_quarto/_freeze/
.DS_Store

# Configure script outputs
config.log
src/Makevars
58 changes: 58 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -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 <<EOF > test-omp.cpp
#include <omp.h>
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
4 changes: 4 additions & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DSTRICT_R_HEADERS
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)

Loading