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.
That’s why we need to install another compiler which supports OpenMP.
Here I use homebrew
for installing llvm clang compiler
using the following scripts. (Check here homebrew or you can just run the following
command to install homebrew
.)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If successful, you should be able to see the following prompt.
➜ brew install llvm
...
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib/c++ -Wl,-rpath,/usr/local/opt/llvm/lib/c++"
llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have llvm first in your PATH, run:
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
For compilers to find llvm you may need to set:
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
To make the llvm clang default compiler, we need to update the PATH variable, and then reopen the terminal to make it work:
➜ echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
Now we should be able to use the llvm clang with OpenMP support. Let’s test it:
➜ clang -fopenmp hello.cpp
In my case, the llvm lib and
include folder are already added into the default clang
search path. (You can check the search path by run commands like
clang hello.cpp -v
, otherwise you may need to include
mannually by -L
and -I
, you can also export it
as system variable as suggested, then use makefile to compile).
Next if we want to use OpenMP in our R code (maybe exported it as R
function using Rcpp package), we should make sure R to call our new
compiler, not the original one. To do this, we can mannually set the
Makeconf
file (makefile configuration for R) in
$R_HOME/etc/Makeconf.
Here you can check the R_HOME address using R.home()
in
R termnial.
R.home()
## [1] "/opt/R/4.4.1/lib/R"
In my case, the R called compiler is still the default clang, so I explicitly replace it. Replace the configuration lines with following (where llvm clang is installed):
CC = /usr/local/opt/llvm/bin/clang
CXX = /usr/local/opt/llvm/bin/clang++
CXX11 = $(CXX)
CXX14 = $(CXX)
CXX17 = $(CXX)
CXX20 = $(CXX)
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
Now you should be able to use OpenMP facility (multiple chain
estimation) in ngme2
.