Skip to content

Commit

Permalink
Improve performance tips in readme (#69)
Browse files Browse the repository at this point in the history
* improve performance tips

* update
  • Loading branch information
david-cortes authored May 25, 2021
1 parent 08609e6 commit 23c97c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,24 @@ _Note: the optimized matrix operations which `rparse` used to offer have been mo

# Installation

Most of the algorithms benefit from OpenMP and many of them could utilize high-performance implementation of BLAS. If you want make maximum out of the package please read the section below carefuly.
Most of the algorithms benefit from OpenMP and many of them could utilize high-performance implementations of BLAS. If you want to make the maximum out of this package, please read the section below carefully.

It is recommended to:

1. Use high-performance BLAS (such as OpenBLAS, MKL, Apple Accelerate).
1. Add proper compiler optimizations in your `~/.R/Makevars`. For example on recent processors (with AVX support) and complier with OpenMP support following lines could be a good option:
1. Add proper compiler optimizations in your `~/.R/Makevars`. For example on recent processors (with AVX support) and compiler with OpenMP support, the following lines could be a good option:
```txt
CXX11FLAGS += -O3 -march=native -mavx -fopenmp -ffast-math
CXXFLAGS += -O3 -march=native -mavx -fopenmp -ffast-math
CXX11FLAGS += -O3 -march=native -fopenmp
CXXFLAGS += -O3 -march=native -fopenmp
```
If you are on **Mac** follow instructions [here](https://github.com/coatless/r-macos-rtools). After installation of `clang4` additionally put `PKG_CXXFLAGS += -DARMA_USE_OPENMP` line to your `~/.R/Makevars`. After that install `rsparse` in a usual way.
If you are on **Mac** follow the instructions [here](https://github.com/coatless/r-macos-rtools). After installation of `clang4`, additionally put a `PKG_CXXFLAGS += -DARMA_USE_OPENMP` line in your `~/.R/Makevars`. After that, install `rsparse` in the usual way.
On Linux, it's enough to just create this file if it doesn't exist (`~/.R/Makevars`).
If using OpenBLAS, it is highly recommended to use the `openmp` variant rather than the `pthreads` variant. On Linux, it is usually available as a separate package in typical distribution package managers (e.g. for Debian, it can be obtained by installing `libopenblas-openmp-dev`, which is not the default version), and if there are multiple BLASes installed, can be set as the default through the [Debian alternatives system](https://wiki.debian.org/DebianScience/LinearAlgebraLibraries) - which can also be used [for MKL](https://stackoverflow.com/a/49842944/5941695).
By default, R for Windows comes with unoptimized BLAS and LAPACK libraries, and `rsparse` will prefer using Armadillo's replacements instead. In order to use BLAS, **install `rsparse` from source** (not from CRAN), removing the option `-DARMA_DONT_USE_BLAS` from `src/Makevars.win` and ideally adding `-march=native` (under `PKG_CXXFLAGS`). See [this tutorial](https://github.com/david-cortes/R-openblas-in-windows) for instructions on getting R for Windows to use OpenBLAS. Alternatively, Microsoft's MRAN distribution for Windows comes with MKL.
# Materials
Expand Down
3 changes: 2 additions & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PKG_CXXFLAGS = -I../inst/include/ @OPENMP_FLAG@ -DARMA_32BIT_WORD
PKG_CPPFLAGS = -DARMA_32BIT_WORD -I../inst/include/
PKG_CXXFLAGS = @OPENMP_FLAG@
PKG_LIBS = @OPENMP_FLAG@ @FLOAT_LIBS@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

CXX_STD = CXX11
3 changes: 2 additions & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
R_SCMD = ${R_HOME}/bin${R_ARCH_BIN}/Rscript -e
FLOAT_LIBS = $(shell ${R_SCMD} "float:::ldflags()")

PKG_CXXFLAGS = -I../inst/include/ $(SHLIB_OPENMP_CXXFLAGS) -DARMA_32BIT_WORD -DARMA_DONT_USE_BLAS -DARMA_NO_DEBUG
PKG_CPPFLAGS = -I../inst/include/ -DARMA_32BIT_WORD -DARMA_DONT_USE_BLAS -DARMA_NO_DEBUG
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(FLOAT_LIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

CXX_STD = CXX11

0 comments on commit 23c97c6

Please sign in to comment.