*Raとjit[#w1556118]

Rを拡張したRaシステムとjitパッケージを使って、Rの処理を高速化する。~
RaはRのコアとは別のRaコアで動いているRである。~
おもしろそうなので、少し追跡する。~
#ref(Ra.JPG)~
RaがRを乗っ取った?~
#ref(Ra2.JPG)~
bin-raを見よ!~
*R掲示板より引用 [#v4d439f5]
Ra システム & jit  (Just in time compiler) [#me1606df]
> (2008-03-08 (土) 12:30:02)~
~
パッケージ jit。少し気になる、Tierney 氏の R byte compiler みたいなもの? R をこの機能用に拡張したという [[Raシステム:http://www.milbo.users.sonic.net/ra/]]の元で動くそうだ。~
  
 The Ra Extension to R
 Ra is functionally identical to R but provides just-in-time  
 compilation of loops and arithmetic expressions in loops. This usually  
 makes Ra arithmetic much faster than R. Ra will also typically run 
 faster than standard R even when just-in-time compilation is not enabled.
 An example
 
    jit(1)                     # turn on just-in-time compilation
    for(i in 1:na)             # example convolution code 
      for(j in 1:nb)
        ab[i + j] <- ab[i + j] + a[i] * b[j]
 
 With na and nb bigger than about 100, the loop runs about 30 times 
 faster. With na and nb equal to 10, the loop runs about 10 times 
 faster. See here for timing details.
  
 The R code is compiled to byte code which is executed internally by 
 an interpreter in C.
 
//
- 面白い取り組み方法ですね。RaってR advance って感じでしょうか。jitがどれくらい効くのか色々試してみようと思います。(日本語RでもRaはそのまま動いています) -- [[okinawa]] &new{2008-03-09 (日) 11:11:59};
- [[Rコード最適化のコツと実例集]]の最初にある説明用コードで試してみました。(MacBookCore2Duo2G,VMWareFusion&Win2000)  結果:純正R2.6.2=5.58sec  Ra(R2.6.2)=0.58sec 純正R2.6.2(ベクトル化)=0.22sec Ra(R2.6.2)(ベクトル化)=0.18sec でベクトル化しても高速化されるようです。plotなどの描画関係の関数は利用できないようで、jitを停止「 jit(0) 」にしたあとplotさせるときちんと動きます。 -- [[okinawa]] &new{2008-03-09 (日) 15:35:40};
- 早速の使用報告ありがとうございます。こうした取り組みが将来的にR本体に取り込まれれば良いですね。 -- [[ものぐさな元記事投稿者]] &new{2008-03-09 (日) 19:05:28};
- 使ってみて、私もそう思いました。(^_^) -- [[okinawa]] &new{2008-03-10 (月) 08:23:21};

*Raを利用した高速化例(WinXpSP2 Core2Duo2.4G 1GRAM) [#a26b4c28]

「意味のあるときは常に、意味の無いときも常にベクトル化を心がけよ」から引用~
(1)Loop利用(遅い場合)~
 x <- runif(1000000)
 test1 <- function () { # 百万個の数の指数を個別に計算
             res <- numeric(1000000)
             for (i in 1:1000000) res[i] <- exp(x[i])
             res}
 system.time(test1())
 > system.time(test1())
   ユーザ   システム       経過  
      3.73       0.00       3.73 

(2)ベクトル
 system.time(res <- exp(x)) 
 > system.time(res <- exp(x)) 
   ユーザ   システム       経過  
      0.11       0.00       0.11 

(3)jit化
 library(jit)
 x <- runif(1000000)
 test1 <- function () { # 百万個の数の指数を個別に計算
             jit(1)
             res <- numeric(1000000)
             for (i in 1:1000000) res[i] <- exp(x[i])
             res}
 system.time(test1())
 jit(0)
 > system.time(test1())
   ユーザ   システム       経過  
      0.27       0.00       0.26 
ベクトル演算まではいかないが、かなり高速化されている。

*jitの制限らしきもの [#qfbdece6]
windows()はjitできないらしい~
 library(jit)
 jit(1)
 x<-rnorm(1:100)
 plot(x)
 Warning: jitting is now disabled
 以下にエラー windows() : cannot use internal routine gsetVar when jitting

これならOK~
 library(jit)
 plot.new()
 jit(1)
 x<-rnorm(1:100)
 plot(x)
 jit(0)
jitしてもしなくてもplotの速度は変わらない。(あたりまえか)~

*コメント欄 [#y0ed184f]
#comment(below)
- Ra&jitは基本的にfor()のLoop部分を高速化するようです。どうしてもベクトル演算化できないものに利用するのでしょうね。 -- [[okinawa]] &new{2008-03-31 (月) 18:11:06};

*リンク [#ye65cac8]
Ra:http://www.milbo.users.sonic.net/ra/~
[[R掲示板]]

[[okinawa]]
[[okinawa]]~

アクセス数:
&counter;
人

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS