vignettes/Installation_and_configuration.Rmd
Installation_and_configuration.Rmd
Currently, the develop version can be installed using the command.
remotes::install_github("davidbolin/ngme2", ref = "devel")
For Mac OS X system, the default C++ compiler in OS X has does not support OpenMP.
➜ clang -fopenmp hello.cpp
clang: error: unsupported option '-fopenmp'
In order to make use of OpenMP to enable multi-threading in OS X, we need to use compilers which supports OpneMP.
The macOS default Apple Clang compiler doesn’t support OpenMP. To
enable OpenMP functionality in packages like ngme2
, we need
to:
brew install llvm libomp
mkdir -p ~/.R
~/.R/Makevars
:# Use Homebrew LLVM's clang compiler (supports OpenMP)
CC=/opt/homebrew/opt/llvm/bin/clang
CXX=/opt/homebrew/opt/llvm/bin/clang++
CXX11=/opt/homebrew/opt/llvm/bin/clang++
CXX14=/opt/homebrew/opt/llvm/bin/clang++
CXX17=/opt/homebrew/opt/llvm/bin/clang++
CXX20=/opt/homebrew/opt/llvm/bin/clang++
# Add OpenMP flags
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
# Include and library paths for LLVM and OpenMP
CFLAGS += -I/opt/homebrew/opt/llvm/include
CXXFLAGS += -I/opt/homebrew/opt/llvm/include
LDFLAGS += -L/opt/homebrew/opt/llvm/lib -L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++
After making these changes, reinstall the ngme2
package
to take advantage of the OpenMP functionality for parallel
processing.
remotes::install_github("davidbolin/ngme2", ref = "devel")
Most Linux distributions come with GCC/G++ compilers that already support OpenMP. If not, you can install the development tools package for your distribution.
For Debian/Ubuntu-based systems:
sudo apt-get update
sudo apt-get install r-base-dev build-essential libopenblas-dev liblapack-dev gfortran
For Red Hat/Fedora-based systems:
If you want to customize the OpenMP settings, you can create a
~/.R/Makevars
file:
# From within R
install.packages("remotes")
remotes::install_github("davidbolin/ngme2", ref = "devel")
Windows installation is generally simpler as the standard R tools for Windows already include appropriate C++ compilers with OpenMP support.
Download and install the version of Rtools that corresponds to your R version from: https://cran.r-project.org/bin/windows/Rtools/
For R 4.0.0 and newer, use Rtools40 or newer.
During installation: - Make sure to select the option to add Rtools to your system PATH - Install the toolchain components
From your R console, check if Rtools is properly installed:
Sys.which("make")
# Should return the path to the make executable
# From within R
install.packages("remotes")
remotes::install_github("davidbolin/ngme2", ref = "devel")
If you need to customize the OpenMP behavior, you can create a
.Renviron
file in your user directory:
# Open R and run:
file.edit("~/.Renviron")
# Add the following line to control the number of OpenMP threads:
OMP_NUM_THREADS=4
This will limit OpenMP to using 4 threads. Adjust the number according to your system’s capabilities.
To verify that OpenMP is working correctly with ngme2
,
you can run a simple test:
~/.R/Makevars
configuration.LDFLAGS
.