R open with MKLを使ってみる

  • R open はMicrosoft が提供する、いわゆるRであって
    • よく使うRのパッケージがデフォルトでインストールされ(インストールされるパッケージリスト)(大規模行列とか、リサンプリング、分類など、大規模データ用のものをそろえているようだ)
    • 数値計算ライブラリと連携し(Intel MKL(Math Kernel Library)が入ってくる。BLASLAPACK、ScaLAPACK(英語版)、スパースソルバー(疎行列)、FFT、ベクトル演算
    • (並列環境なら)並列用の道具も提供してくれるもの
  • 他にもRと連携する解析プラットフォームはあるけれど、インストールなどは、Rのインストールができる人なら、だれでもできるレベル
  • こちらから、R openとMKLとをダウンロードし、R openを先に、MKLを後にインストールする。インストーラに従うだけ
  • どういう計算がどれくらい速くなるかはこちらベンチマーク記事を(大規模行列演算が、並列にしなくても数倍から数十倍になるようだ)
  • 以下は、自分でもやってみた結果
install.packages("rbenchmark")
library(rbenchmark)
set.seed(121212)
test.fx <- function(n=100){
	M <- matrix(rnorm(n^2),n,n)
	eigen(M)
}

rbenchmark::benchmark(test.fx())

### R open with MKL
> rbenchmark::benchmark(test.fx())
test replications elapsed relative user.self sys.self user.child
1 test.fx() 100 3.66 1 6.82 0.47 NA
sys.child
1 NA

### Regular R
> rbenchmark::benchmark(test.fx())
test replications elapsed relative user.self sys.self user.child
1 test.fx() 100 4.24 1 4.23 0 NA
sys.child
1 NA

set.seed(121212)
test.fx2 <- function(n=100){
	M <- matrix(rnorm(n^2),n,n)
	M2 <- matrix(rnorm(n^2),n,n)
	M %*% M2
}

rbenchmark::benchmark(test.fx2())

### R open with MKL
> rbenchmark::benchmark(test.fx2())
test replications elapsed relative user.self sys.self user.child
1 test.fx2() 100 0.92 1 1.67 0.15 NA
sys.child
1 NA

### Regular R
> rbenchmark::benchmark(test.fx2())
test replications elapsed relative user.self sys.self user.child
1 test.fx2() 100 1.01 1 1.01 0 NA
sys.child
1 NA

set.seed(121212)
test.fx2 <- function(n=100){
	M <- matrix(rnorm(n^2),n,n)
	M2 <- matrix(rnorm(n^2),n,n)
	M %*% M2
}

rbenchmark::benchmark(test.fx2(500))

### R open with MKL
> rbenchmark::benchmark(test.fx2(500))
test replications elapsed relative user.self sys.self user.child
1 test.fx2(500) 100 23.62 1 44.18 2.45 NA
sys.child
1 NA

### Regular R
> rbenchmark::benchmark(test.fx2(500))
test replications elapsed relative user.self sys.self user.child
1 test.fx2(500) 100 45.49 1 45.04 0.04 NA
sys.child
1 NA

set.seed(121212)
test.fx3 <- function(n=1000,m=500){
	A <- matrix(rnorm(n*m),n,m)
	b <- 1:n
	solve(qr(A, LAPACK = TRUE), b)
}

rbenchmark::benchmark(test.fx3())

### R open with MKL
> rbenchmark::benchmark(test.fx3())
test replications elapsed relative user.self sys.self user.child
1 test.fx3() 100 36.46 1 67.52 3.65 NA
sys.child
1 NA

### Regular R
> rbenchmark::benchmark(test.fx3())
test replications elapsed relative user.self sys.self user.child
1 test.fx3() 100 96.14 1 93.52 0.47 NA
sys.child
1 NA