L. Tierney氏のsnowパッケージでクラスタ計算を行う
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#contents
*L.Tierney氏のsnowパッケージでクラスタ計算を行う (間瀬茂)...
必要に迫られ、計算機クラスタで計算をせざるを得なくなりま...
幸い私は東工大の誇るグリッドスパコン[[TSUBAME:http://www....
並列処理用に[[R:http://www.r-project.org/index.html]]のコ...
ということで、勉強がてら作者[[Luke Tierney:http://homepag...
[[snow:http://homepage.stat.uiowa.edu/~luke/R/cluster/clu...
具体的には apply() 関数の並列処理版関数を使うだけです。最...
*コメント [#o36c68dd]
- MPIクラスタなら広島大学の伊藤さんの[[覚え書き:http://ww...
- 早速の情報ありがとうございます。マルチコアCPUマシン自体...
- 数年前MPI環境で動作する遺伝子配列の相同性検索プログラム...
- RではありませんがGARLI/MrBayesという系統推定プログラム...
- マルチCPUマシンでは基本的にはCPU個数だけRを起動して走ら...
- また、Windowsだと常駐ソフトやプロセスの「優先度」、「プ...
- うちの教官が2.8GHz 8-core Mac Proを購入してくれましたの...
#comment
*(1)R用の簡単なワークステーションネットワーク [#g1373902]
Luke Tierney,~
Department of Statistics and Actuarial Science,~
University of Iowa~
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
ワークステーション集合もしくは Beowulf クラスタ使用に対す...
部分的に [[Python CoW(Cluster of Workstations)パッケージ:...
基づくインタフェイスは極めて単純であることを目指しており...
機構のトップに実装できるようにデザインされている。3種類の...
実装されている。一つは Li と Rossini による
[[rpvm:http://cran.r-project.org/src/contrib/Descriptions...
パッケージ経由で PVM を使う。もう一つは Hao Yu による
[[Rmpi:http://www.stats.uwo.ca/faculty/yu/Rmpi]] パッケー...
使う。今一つは raw ソケットを使うもので PVM や MPI が使え...
このノートはクラスタの開始法、クラスタを用いた計算に対す...
並列ブートストラップ法に対してクラスタを用いる一つの例を...
二つの注意:
-計算を COLOR(red){^C} で中断することは問題を引き起こしや...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
-Rを終了する前にクラスタに対して COLOR(red){stopCluster} ...
きれいにシャットダウンできるようになる。
**クラスタを開始し終了する [#e0c657df]
ワークステーションクラスタの開始は、基底にあるコミュニケ...
クラスタを使用する際の唯一のステップである。
クラスタは COLOR(red){makeCluster} 関数を呼び出すと開始さ...
タイプにより少々異なる。PVM と MPI クラスタはまた、PVM も...
予備的準備的を必要とするかもしれない。
**PVM クラスタを開始する [#i3a40f74]
PVM (Parallel Virtual Machine) クラスタを開始するには、ま...
私は、このためには、私は PVM コンソール COLOR(red){pvm} ...
~
COLOR(blue){<starting PVM using the pvm console>}
luke@itasca cluster% pvm
pvm> add itasca
add itasca
0 successful
HOST DTID
itasca Duplicate host
pvm> add owasso
add owasso
1 successful
HOST DTID
owasso 80000
pvm> conf
conf
2 hosts, 2 data formats
HOST DTID ARCH SPEED ...
itasca 40000 LINUX 1000 0x004...
owasso 80000 DARWIN 1000 0x065...
pvm>
COLOR(red){conf} 命令で示された並列仮想マシン構成は二つの...
i386 Linux が動く COLOR(red){itasca} と Mac OS X が動く C...
からなる。コマンドラインコンソール COLOR(red){pvm} の代わ...
されていればグラフィカルなコンソール COLOR(red){xpvm} を...
COLOR(red){rpvm} パッケージを使って、COLOR(red){rpvm}
パッケージが提供する R 関数を使っても良い。
一旦 PVM が動き出せば、二つの作業ノードからなるクラスタを...
マスターでRを開始し、 [[snow:http://homepage.stat.uiowa.e...
を二つの引数、作業ノード数と COLOR(red){type = "PVM"} で...
~
COLOR(blue){<starting a PVM cluster>}
cl <- makeCluster(2, type = "PVM")
返り値はこれらの二つのプロセスへの参照からなるリストであ...
もし COLOR(red){rpvm}パッケージが利用でき COLOR(red){Rmpi...
現在の既定のクラスタタイプは COLOR(red){"PVM"} であり、従...
引数は省略できる。
COLOR(red){PVM} を使った作業が終了したら、それをシャット...
例えば、COLOR(red){pvm} コンソールで COLOR(red){halt} 命...
**MPI クラスタを開始する [#z2df71b0]
もし MPI 2 プロセスを生み出す(spawn) API をサポートしてい...
のような MPI システムを使っているのなら、ソケットや PVM ...
生成できる。もしプロセス生成機能をサポートしない MPI シス...
必要になる。例えば COLOR(red){lamboot} を使い、最初に MPI...
詳細は使用中の MPI システムに依存する。
MPI の利用が終ったらそれをシャットダウンする(もし使用中の...
LAM-MPI に対しては例えば COLOR(red){lamhalt} を使う。
**生成された MPI クラスタ [#y5136517]
プロセス生成機能をサポートする MPI システムに対する MPI ...
~
COLOR(blue){<starting an MPI cluster with process spawnin...
cl <- makeCluster(2, type = "MPI")
もし COLOR(red){rpvm} が利用不可能だが COLOR(red){Rmpi} ...
現在の既定のクラスタタイプは COLOR(red){"MPI"} であり、引...
は省略できる。
**プロセス生成機能を持たない MPI クラスタ [#scce80a1]
もし使用中の MPI システムがプロセス生成機能を持たないか、...
実行したいのなら、 COLOR(red){Rmpi} をインストールする必...
またインストールした COLOR(red){[[snow:http://homepage.st...
ディレクトリから COLOR(red){RMPISNOW} というシェルスクリ...
アクセス可能なパス)にインストールしておく必要がある。
もし COLOR(red){RMPISNOW} がユーザのパス上にあれば、R を...
~
COLOR(blue){<starting R with mpirun>}
mpirun -np 3 RMPISNOW
これはマスターと二つのワーカプロセスを開始する。クラスタ...
このクラスタへの参照は次のようにして得られる:~
~
COLOR(blue){<obtaining a cluster started with mpirun>}
cl <- getMPIcluster()
最新版の COLOR(red){[[snow:http://homepage.stat.uiowa.edu...
~
COLOR(blue){obtaining a cluster started with mpirun>}
cl <- makeCluster()
もしくは、二つのワーカをを持つクラスタに対しては次のよう...
~
COLOR(blue){<obtaining a cluster started with mpirun>}
cl <- makeCluster(2)
**ソケットクラスタを開始する [#z93c6750]
ソケットクラスタを開始するには命令 COLOR(red){makeCluster...
COLOR(red){type="SOCK"} と使用する計算機のリストを指定す...
~
COLOR(blue){<starting a socket cluster>}
cl <- makeCluster(c("itasca", "owasso"), type = "SOCK")
二つの R プロセスからなるクラスタを開始する。一つは COLOR...
COLOR(red){owasso} という計算機上にある. 返り値はこれら二...
**補足的なクラスタ生成引数 [#leac1cc5]
クラスタ生成関数 COLOR(red){makeCluster} には、ノードを生...
指定する幾つかの追加的な名前付き引数を与えることができる。
最も有用な引数はクラスタタイプに対する COLOR(red){type} ...
アーキテクチャとファイルシステムのレイアウトを持つと仮定...
~
COLOR(red){homogeneous} 引数(異質的(heterogeneous)クラス...
に解説がある)、
そしてワーカからの出力が出力先を指示する COLOR(red){outfi...
既定では、COLOR(red){outfile} は COLOR(red){/dev/null} で...
デバッグ時、特に初期設定の試行中、には出力を適当なファイ...
各クラスタ生成呼び出しに対する追加のクラスタオプションを...
もう一つの方法が、COLOR(red){setDefaultClusterOptions} を...
例えば、既定値が「異質的 MPI クラスタ」と指定するには次の...
setDefaultClusterOptions(type="MPI", homogeneous = FALSE)
**クラスタを停止する [#a44a214f]
クラスタを停止するには次のようにすべきである:~
~
COLOR(blue){<stopping a cluster>}
stopCluster(cl)
ソケットクラスタはそれらを生成したプロセスが終了すると自...
それでも COLOR(red){stopCluster} を呼び出すのが好ましい。
それが生成したプロセスが存在するより前に PVM クラスタを終...
COLOR(red){stopCluster} を使用する代わりに、PVM コンソー...
実行しても良い。使用している MPI システムは同様の機能を持...
例えば、LAM システムに対しては COLOR(red){lamhalt} 命令や...
**異質的(inhomogeneous)システム [#u4830cd7]
クラスタ生成時の既定オプション設定では、 COLOR(red){R} シ...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
システムを前提にしている。COLOR(red){[[snow:http://homepa...
既定の設定が有効であるためには、それがマスタに対する COLO...
ライブラリのどれかに存在することが必要である。
異なったレイアウトのファイルシステムや、異なったアーキテ...
持つような、異質的(inhomogeneous)システムでは幾つかの追加...
ワーカプロセスを実行するのに使われる各計算機毎に、スクリ...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
マスタ計算機とワーカプロセスを実行する各計算機で、環境変...
を COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke...
適切なアーキテクチャに対する COLOR(red){rlecuyer} といっ...
ディレクトリの名前にする。
各計算機の検索パス上に適切なバージョンの COLOR(red){R} が...
現時点では、変数 COLOR(red){R_SNOW_LIB} を空でない値に設...
COLOR(red){homogeneous} クラスタオプションを COLOR(red){F...
さもなければ、それは COLOR(red){TRUE} とされる。
**クラスタを使う [#ma985e60]
***基本的関数 [#tf2854f7]
クラスタを使用するための基本的関数は COLOR(red){clusterCa...
COLOR(red){clusterApply} である。COLOR(red){clusterCall} ...
クラスタの各メンバ上で同一引数で呼び出し、結果をリストで...
並列処理される。例えば、ノードにその名前と計算機タイプを...
~
COLOR(blue){<R session>}
> clusterCall(cl, function() Sys.info()[c("nodename","ma...
[[1]]
nodename machine
"owasso.stat.uiowa.edu" "Power Macintosh"
[[2]]
nodename machine
"itasca" "i686"
有用な COLOR(red){clusterCall} の変種は COLOR(red){cluste...
定義される:~
~
COLOR(blue){<definition of clusterEvalQ>}
clusterEvalQ <- function(cl, expr)
clusterCall(cl, eval, substitute(expr), env=.GlobalE...
これは例えば、各クラスタノードにあるパッケージをロードす...
~
COLOR(blue){<loading a library on all nodes>}
clusterEvalQ(cl, library(boot))
COLOR(red){clusterApply} は COLOR(red){lapply} の変種で、...
呼び出しを実行する。クラスタのノード数はリスト引数中の要...
簡単な例:~
~
COLOR(blue){<R session>}
> clusterApply(cl, 1:2, get("+"), 3)
[[1]]
[1] 4
[[2]]
[1] 5
***乱数発生 [#b77d6617]
既定の乱数発生器は強い相関を持つ可能性が高い:~
~
COLOR(blue){<R session>}
> clusterCall(cl, runif, 3)
[[1]]
[1] 0.08496597 0.35232298 0.60300751
[[2]]
[1] 0.08496597 0.35232298 0.60300751
これを回避する手軽な方法は乱数種であり、
次のようにする:~
~
COLOR(blue){<random seeding of cluster generators>}
clusterApply(cl, runif(length(cl),max=10000000), set.seed)
より良い方法は並列乱数発生器 パッケージを使うことである。...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
http://www.iro.umontreal.ca/%7Elecuyer/myftp/papers/strea...
インタフェイスである。 関数 COLOR(red){clusterSetupRNG} ...
ランダムな種を使う。ヘルプ頁で説明された名前付き引数を使...
~
COLOR(blue){<R session>}
> clusterSetupRNG(cl)
> clusterCall(cl, runif, 3)
[[1]]
[1] 0.749391854 0.007316102 0.152742874
[[2]]
[1] 0.8424790 0.8896625 0.2256776
***ブートストラップの例 [#o009eba3]
COLOR(red){boot} パッケージはデータ COLOR(red){nuclear} ...
COLOR(red){boot} のヘルプ頁に与えられた準備コードは次のよ...
~
COLOR(blue){<bootstrap setup>}
library(boot)
# この例では nuclear データに基づく回帰予測で boot を使...
# この例は Davison and Hinkley (1997) の例6.8 から取っ...
# 統計量に対する2つの追加引数が boot 経由で渡されている...
data(nuclear)
nuke <- nuclear[,c(1,2,5,7,8,10,11)]
nuke.lm <- glm(log(cost)~date+log(cap)+ne+ ct+log(cum....
nuke.diag <- glm.diag(nuke.lm)
nuke.res <- nuke.diag$res*nuke.diag$sd
nuke.res <- nuke.res-mean(nuke.res)
# データ、標準化残さ、当てはめ値を持つ新しいデータフレ...
# ブートストラップで使うために作る。
nuke.data <- data.frame(nuke,resid=nuke.res,fit=fitted...
# 番号32のプラントの日付 73.00 での予測値を得たい。
new.data <- data.frame(cost=1, date=73.00, cap=886, ne...
ct=0, cum.n=11, pt=1)
new.fit <- predict(nuke.lm, new.data)
nuke.fun <- function(dat, inds, i.pred, fit.pred, x.pr...
assign(".inds", inds, envir=.GlobalEnv)
lm.b <- glm(fit+resid[.inds] ~date+log(cap)+ne+ct+
log(cum.n)+pt, data=dat)
pred.b <- predict(lm.b,x.pred)
remove(".inds", envir=.GlobalEnv)
c(coef(lm.b), pred.b-(fit.pred+dat$resid[i.pred]))
}
一つのワークステーションではブートストラップ例は
約30秒かかった。~
~
COLOR(blue){<R session>}
> system.time(nuke.boot <-
+ boot(nuke.data, nuke.fun, R=999, m=1,
+ fit.pred=new.fit, x.pred=new.data))
[1] 26.32 0.71 27.02 0.00 0.00
二つの計算機からなるクラスタ (このときは同一の i686 ノー...
約2倍早かった。~
~
COLOR(blue){<R session>}
> clusterEvalQ(cl, library(boot))
> system.time(cl.nuke.boot <-
+ clusterCall(cl,boot,nuke.data, nuke.fun, R...
+ fit.pred=new.fit, x.pred=new.d...
[1] 0.01 0.00 14.27 0.00 0.00
4台のノードのクラスタでは約6秒であった。~
~
COLOR(blue){<R session>}
> cl <- makeCluster(5)
> clusterEvalQ(cl,library(boot))
> system.time(cl.nuke.boot <-
+ clusterCall(cl,boot,nuke.data, nuke.fun, R...
+ fit.pred=new.fit, x.pred=new.d...
[1] 0.03 0.00 5.58 0.00 0.00
速度を比較するのに使うべき値は三番目の経過時間である。
***高水準関数 [#y5f4eae1]
COLOR(red){clusterApply} を用いた高水準関数は
COLOR(red){parLapply}, COLOR(red){parSapply}, そして COLO...
これらはそれぞれ COLOR(red){lapply}, COLOR(red){sapply}、...
の並列版である。幾つかの例を示す:~
~
COLOR(blue){<higher level examples>}
sum(parApply(cl, matrix(1:100,10), 1, sum))
sum(parApply(cl, matrix(1:10000,100), 1, sum))
COLOR(blue){<higher level examples>}
x <- 1:100/101
system.time(qtukey(x, 2, df=2))
system.time(unlist(parLapply(cl, x, qtukey, 2, df=2)))
解説のために行列積の並列計算の非常に簡単な例をあげる:~
~
COLOR(blue){<higher level examples>}
A <- matrix(rnorm(10000),100)
system.time(A %*% A)
system.time(parMM(cl,A , A))
**コメント [#p8f71ce2]
留意すべき幾つかの注意:
-計算機間の通信速度は計算速度に比べるとかなり遅い。
-この構成では通信は直列化されている。
-大きなサイズの結果を返す R 関数がある。結果を返す前に縮...
-PVM と MPI 版は迷子のジョブを残さないことを確実にすると...
PVM コンソール、もしくは COLOR(red){lamhalt} と COLOR(red...
PVM もしくは LAM-MPI 領域を停止することにより R プロセス...
ソケットを使った実装では、マスタが存在するときはどんな稼...
残すべきではない。しかし、妙な具合でそうなることもあり得...
解説のために行列積の並列計算の非常に簡単な例をあげる:~
~
COLOR(blue){<higher level examples>}
A <- matrix(rnorm(10000),100)
system.time(A %*% A)
system.time(parMM(cl,A , A))
**コメント [#h122a737]
留意すべき幾つかの注意:
-計算機間の通信速度は計算速度に比べるとかなり遅い。
-この構成では通信は直列化されている。
-大きなサイズの結果を返す R 関数がある。結果を返す前に縮...
-PVM と MPI 版は迷子のジョブを残さないことを確実にすると...
PVM コンソール、もしくは COLOR(red){lamhalt} と COLOR(red...
PVM もしくは LAM-MPI 領域を停止することにより R プロセス...
ソケットを使った実装では、マスタが存在するときはどんな稼...
残すべきではない。しかし、妙な具合でそうなることもあり得...
時としてまずいことが起き得、手動による後かたづけが必要に...
**未解決の問題 [#n4028b8f]
***エラー処理 [#f9f57b62]
エラー処理は現在のところ非常に素朴である。ワーカノードで...
COLOR(red){try} 関数を用いて実行される。従って、返り値は...
COLOR(red){try} 関数が返すエラーである。原則としてユーザ...
幾つかのノードがエラーを出し、その他はエラーにならない状...
明らかでなく、問題による。R がより洗練されたエラー処理機...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
できるであろう。
***中断処理 [#v8a1430c]
理想的には、マスタに於ける中断はワーカに伝播すべきで、現...
しかしそうなってはいない。実際、COLOR(red){[[snow:http://...
通信基盤を混乱した状態に陥れ、それ以降現在の R セッション...
一時しのぎの解決策: COLOR(red){[[snow:http://homepage.st...
R が中断に対する処理を制御する機構を持てば、もう少しまし...
実際に中断をワーカノードに伝播させることが可能になるかど...
*(2) snowクラスタでの一様乱数発生 (snowパッケージのヘルプ...
**説明: [#ed469ad7]
SNOWクラスタで使う独立一様乱数ストリームを初期化する。L'E...
**用法: [#pe026850]
clusterSetupRNG (cl, type = "RNGstream", ...)
clusterSetupRNGstream (cl, seed=rep(12345,6), ...)
clusterSetupSPRNG (cl, seed = round(2^32 *runif(1)),
prngkind = "default", para = 0, ....
**引数: [#x373208e]
cl: クラスタオブジェクト
type: 'type="RNGstream"' (既定) は L'Ecuyer の RNG、
'type="SPRNG"' は SPRNG 発生器を使う
...: 背景にある関数(以下の詳細を見よ)へ渡される引数
seed: RNGの種として使われる整数値 (SPRNG) もしくは長...
prngkind: SPRNG で使われる発生法タイプの名前文字列
para: 発生器にたいする追加引数
**詳細: [#b0aaef79]
- COLOR(red){clusterSetupRNG} はその引数値に応じて他の関...
- COLOR(red){clusterSetupSPRNG} は 'rsprng' パッケージを...
- COLOR(red){clusterSetupRNGstream} は 'rlecuyer' パッケ...
- より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/cl...
**例: [#c0470d3d]
## Not run:
clusterSetupSPRNG(cl)
clusterSetupSPRNG(cl, seed=1234)
clusterSetupRNG(cl, seed=rep(1,6))
## End(Not run)
*(3) クラスタレベルのSNOW関数 (snowパッケージのヘルプ文章...
**説明: [#m076b2e2]
SNOWクラスタ上で計算を行う関数。
**用法: [#pcebd8e8]
clusterSplit(cl, seq)
clusterCall(cl, fun, ...)
clusterApply(cl, x, fun, ...)
clusterApplyLB(cl, x, fun, ...)
clusterEvalQ(cl, expr)
clusterExport(cl, list)
**引数: [#j67566fb]
cl: クラスタオブジェクト
fun: 関数もしくは関数名を与える文字列
expr: 評価すべき表現式
seq: 分割されるベクトル
list: エクスポートされる変数名の文字列
x: 配列
...: 標準関数に引き渡される追加引数
**詳細: [#s3698d23]
-これらはクラスタ上で計算を行うための基本的関数である。ス...
-COLOR(red){clusterCall} は関数 'fun' をクラスタ 'cl' の...
-COLOR(red){clusterEvalQ} は各クラスタノードで文字通りの...
-COLOR(red){clusterApply} は関数 'fun' を、最初のクラスタ...
-COLOR(red){clusterApplyLB} は COLOR(red){clusterApply} ...
-COLOR(red){clusterExport} は 'list' 中に名前があるマスタ...
-COLOR(red){clusterSplit} は 'seq' を各クラスタに対する連...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#xd356224]
## Not run:
cl <- makeSOCKcluster(c("localhost","localhost"))
clusterApply(cl, 1:2, get("+"), 3)
clusterEvalQ(cl, library(boot))
x<-1
clusterExport(cl, "x")
clusterCall(cl, function(y) x + y, 2)
## End(Not run)
*(4) [[snow:http://homepage.stat.uiowa.edu/~luke/R/cluste...
**説明: [#cf5fa85b]
SNOWクラスタを開始・停止し、クラスタオプションを設定する...
**用法: [#ddca7af0]
makeCluster(spec, type = getClusterOption("type"), ....
stopCluster(cl)
setDefaultClusterOptions(...)
makeSOCKcluster(names, ..., options = defaultCluster...
makePVMcluster(count, ..., options = defaultClusterO...
makeMPIcluster(count, ..., options = defaultClusterO...
getMPIcluster()
**引数: [#d75681e3]
spec: クラスタ指定
count: 生成するノー度数
names: ノード名の文字列ベクトル
options: クラスタオプションオブジェクト
cl: クラスタオブジェクト
...: クラスタオプション指定
type: クラスタのタイプを指定する文字列
**詳細: [#dbf4bf8f]
-COLOR(red){makeCluster} は指定もしくは既定タイプのクラス...
このベクトル中の各ノードに対してひとつのノードが開始され...
-COLOR(red){stopCluster} はクラスタを適切にシャットダウン...
-COLOR(red){setDefaultClusterOptions} は既定のクラスタオ...
-COLOR(red){homogeneous} オプションは非同質的なクラスタに...
-オプション COLOR(red){outfile} はスレーブノードでの出力...
-関数 COLOR(red){makeSOCKcluster}, COLOR(red){makePVMclus...
-プロセス生成(process spawning)が利用できず、マスタとスレ...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#ifa5cdfd]
## Not run:
cl <- makeCluster(c("localhost","localhost"), type =...
clusterApply(cl, 1:2, get("+"), 3)
## End(Not run)
*(5) 高水準SNOW関数 (snowパッケージのヘルプ文章) [#m13f7f...
**説明: [#b96b7519]
'apply' 関数の並列版と関連関数。
**用法: [#ade1d1f2]
parLapply(cl, x, fun, ...)
parSapply(cl, X, FUN, ..., simplify = TRUE, USE.NAME...
parApply(cl, X, MARGIN, FUN, ...)
parRapply(cl, x, fun, ...)
parCapply(cl, x, fun, ...)
parMM(cl, A, B)
**引数: [#n6ab07c7]
cl: クラスタオブジェクト
fun: 関数もしくは関数名文字列
X: 使用される配列
x: 使用される行列
FUN: 関数もしくは関数名文字列
MARGIN: 使用される次元を指定するベクトル
simplify: 論理値、'sapply' を参照
USE.NAMES: 論理値、'sapply' を参照
...: 標準関数に引き渡される追加引数
A: 行列
B: 行列
**詳細: [#u74bbd47]
-COLOR(red){parLapply}, COLOR(red){parSapply} そして COLO...
-COLOR(red){parRapply} と COLOR(red){parCapply} は行列 'x...
-COLOR(red){parMM} は非常に簡単な行列積の並列版である。説...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#i4d87189]
## Not run:
cl <- makeSOCKcluster(c("localhost","localhost"))
parSapply(cl, 1:20, get("+"), 3)
## End(Not run)
*(6) Rmpi パッケージ情報 [#ecaa7a7b]
[[snow:http://homepage.stat.uiowa.edu/~luke/R/cluster/clu...
と呼ばれるクラスタ構成ソフトへのインタフェイスで、それ自...
**MPI API: [#i41cc0b6]
mpi.abort Abort (quit) all tasks associate...
mpi.allgather Gather data from each process to...
mpi.allgatherv Gather diff size data from each ...
mpi.allreduce Reduce all process's vectors int...
mpi.barrier Block the caller until all group...
mpi.bcast Broadcast a vector (int,double,c...
mpi.cancel Cancel a nonblocking send or recv
mpi.cart.coords Translate a rank to the Cartesia...
mpi.cart.create Create a Cartesian structure of ...
mpi.cartdim.get Get dim information about a Cart...
mpi.cart.get Provide the Cartesian topology a...
mpi.cart.rank Translate a Cartesian topology c...
mpi.cart.shift Shift Cartesian topology in disp...
mpi.comm.disconnect Disconeect and free a comm
mpi.comm.dup Duplicate a comm to a new comm
mpi.comm.free Free a comm
mpi.comm.get.parent Get the parent intercomm
mpi.comm.rank Find the rank (process id) of ma...
mpi.comm.remote.size Find the size of a remote group ...
mpi.comm.size Find the size (total # of master...
mpi.comm.set.errhandler Set comm to error return (no cra...
mpi.comm.spawn Spawn slaves
mpi.comm.test.inter Test if a comm is an intercomm
mpi.dims.create Create a Cartesian dim used by m...
mpi.finalize Exit MPI environment (call MPI_F...
mpi.gather Gather data from each process to...
mpi.gatherv Gather diff data from each proce...
mpi.get.count Get the length of a message for ...
mpi.get.processor.name Get the process (host) name
mpi.info.create Create an info object
mpi.info.free Free an info object
mpi.info.get Get the value from an info objec...
mpi.info.set Set a key/value pair of an info ...
mpi.intercomm.merge Merge a intercomm to a comm
mpi.iprobe Nonblocking use a source and a t...
mpi.irecv Nonblocking receive a vector fro...
mpi.isend Nonblocking send a vector to a s...
mpi.probe Use a source and a tag to set st...
mpi.recv Receive a vector from a specific...
mpi.reduce Reduce all processes's vectors i...
mpi.scatter Opposite of mpi.gather
mpi.scatterv Opposite of mpi.gatherv (diff si...
mpi.send Send a vector to a specific proc...
mpi.sendrecv Send & receive different vectors...
mpi.sendrecv.replace Send & replace a vector in one c...
mpi.test Test if a nonblocking send/recv ...
mpi.testall Test if all nonblocking send/rec...
mpi.testany Test if any nonblocking send/rec...
mpi.testsome Test if some nonblocking send/re...
mpi.test.cancelled Test if a communication is cance...
mpi.universe.size Total number of CPUs available
mpi.wait Wait if a nonblocking send/recv ...
mpi.waitall Wait if all nonblocking send/rec...
mpi.waitany Wait if any nonblocking send/rec...
mpi.waitsome Wait if some nonblocking send/re...
**MPI R 環境の拡張: [#ec18b10c]
lamhosts Hosts id and machine host name mappi...
mpi.allgather.Robj Gather any type of objects to every ...
mpi.any.source A constant for receiving a message f...
mpi.any.tag A constant for receiving a message f...
mpi.bcast.Robj Broadcast an R object to every process
mpi.comm.maxsize Find the length of comm array
mpi.exit MPI_Finalize を呼出し、Rmpi ライブラ...
mpi.gather.Robj Gather any type of object to a root...
mpi.get.sourcetag Get the source and tag for a given s...
mpi.hostinfo Get the host information that the pr...
mpi.init.sprng rsprng ライブラリ中の SPRNG を初期化...
mpi.is.master TRUE if it is a master otherwise FAL...
mpi.isend.Robj Nonblocking send an R object to a sp...
mpi.proc.null Dummy source and destination
mpi.quit MPI_Finalize を呼出し R を終了する
mpi.recv.Robj Receive an R object from a process (...
mpi.realloc.comm Increase comm array to a new size
mpi.realloc.request Increase request array to a new size
mpi.realloc.status Increase status array to a new size
mpi.request.maxsize Find the length of request array
mpi.scatter.Robj Scatter an list to every number
mpi.send.Robj Send an R object to a specific process
mpi.spawn.Rslaves Spawn R slaves. The default R script...
mpi.status.maxsize Find the length of status array
mpichosts finds host names from master Windows...
**MPI slavedaemon.R スクリプト固有の拡張 (インタラクティ...
mpi.apply 配列をスレーブに分配し、それから fu...
mpi.applyLB mpi.apply の負荷均等版
mpi.bcast.Robj2slave Master sends an Robj to all slaves
mpi.bcast.cmd 全てのプロセスにある命令をブロード...
mpi.close.Rslaves mpi.spawn.Rslaves() で起動された全...
mpi.parApply (負荷均等版) 並列 apply 関数
mpi.parCapply (負荷均等版) 列への並列 apply 関数
mpi.parLapply (負荷均等版) 並列 lapply 関数
mpi.parRapply (負荷均等版) 行への並列 apply 関数
mpi.parReplicate ある表現式の反復評価のための mpi.pa...
mpi.parSapply (負荷均等版) 並列 sapply 関数
mpi.parSim (負荷均等版) 並列モンテカルロシミュ...
mpi.remote.exec ある命令をスレーブで遠隔実行し、結...
mpi.setup.rngstream パッケージ rlecuyer の RNDstream を...
mpi.setup.sprng パッケージ rsprng の SPRNG を全ての...
slave.hostinfo 全てのスレーブの rank, comm, host i...
tailslave.log スレーブのログファイルの末尾部分を...
**他の MPI 関数が用いる内部関数 [#b4f4fd00]
bin.nchar Find the length of a binary string
mpi.comm.is.null Test if a comm is NULL (no members)
string Create a string (empty space charac...
*(7) パッケージ rpvm の情報 [#a6686ab6]
パッケージ rpvm はPVM (Parallel Virtual Machine) API への...
**パッケージ 'rpvm' 内の関数の簡易説明一覧 [#afaf087e]
.PVM.barrier Group synchronization
.PVM.bcast Broadcasting the data
.PVM.bufinfo Message buffer infomation
.PVM.config PVMD configuration
.PVM.exit Unregister process from local PVM deam...
.PVM.freebuf Free message buffer
.PVM.gather Gather the data into root
.PVM.getinst Instance number identified by group na...
.PVM.getsbuf Manipulating Message Buffers
.PVM.gettid Task id identified by group name and i...
.PVM.gsize Get the size of the group
.PVM.initsend Initialize send buffer
.PVM.joingroup Join or leave a names group
.PVM.kill pvm プロセスを停止する
.PVM.mcast Multicast data
.PVM.mkbuf Create message buffer
.PVM.mstats Status of host machines
.PVM.mytid Task IDs
.PVM.notify Monitor pvmd
.PVM.nrecv Nonblocking receive
.PVM.probe Probe receive
.PVM.pstats Status of PVM processes
.PVM.recv Blocking receive
.PVM.reduce Reduction
.PVM.scatter Scatter a vector across the group
.PVM.send Send data
.PVM.serialize Serialize R Objects
.PVM.spawn Spawn child tasks
.PVM.tasks Tasks information
.PVM.tidtohost Host id of a task
.PVM.trecv Timeout receive
PVM.options libpvm Options
PVM.pack Packing data
PVM.rapply 並列版 apply 関数
PVM.unpack Unpacking data
PVMD Vitural Machine Control
init.sprng.master SPRNG を初期化する rsprng へのインタフ...
終了行:
#contents
*L.Tierney氏のsnowパッケージでクラスタ計算を行う (間瀬茂)...
必要に迫られ、計算機クラスタで計算をせざるを得なくなりま...
幸い私は東工大の誇るグリッドスパコン[[TSUBAME:http://www....
並列処理用に[[R:http://www.r-project.org/index.html]]のコ...
ということで、勉強がてら作者[[Luke Tierney:http://homepag...
[[snow:http://homepage.stat.uiowa.edu/~luke/R/cluster/clu...
具体的には apply() 関数の並列処理版関数を使うだけです。最...
*コメント [#o36c68dd]
- MPIクラスタなら広島大学の伊藤さんの[[覚え書き:http://ww...
- 早速の情報ありがとうございます。マルチコアCPUマシン自体...
- 数年前MPI環境で動作する遺伝子配列の相同性検索プログラム...
- RではありませんがGARLI/MrBayesという系統推定プログラム...
- マルチCPUマシンでは基本的にはCPU個数だけRを起動して走ら...
- また、Windowsだと常駐ソフトやプロセスの「優先度」、「プ...
- うちの教官が2.8GHz 8-core Mac Proを購入してくれましたの...
#comment
*(1)R用の簡単なワークステーションネットワーク [#g1373902]
Luke Tierney,~
Department of Statistics and Actuarial Science,~
University of Iowa~
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
ワークステーション集合もしくは Beowulf クラスタ使用に対す...
部分的に [[Python CoW(Cluster of Workstations)パッケージ:...
基づくインタフェイスは極めて単純であることを目指しており...
機構のトップに実装できるようにデザインされている。3種類の...
実装されている。一つは Li と Rossini による
[[rpvm:http://cran.r-project.org/src/contrib/Descriptions...
パッケージ経由で PVM を使う。もう一つは Hao Yu による
[[Rmpi:http://www.stats.uwo.ca/faculty/yu/Rmpi]] パッケー...
使う。今一つは raw ソケットを使うもので PVM や MPI が使え...
このノートはクラスタの開始法、クラスタを用いた計算に対す...
並列ブートストラップ法に対してクラスタを用いる一つの例を...
二つの注意:
-計算を COLOR(red){^C} で中断することは問題を引き起こしや...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
-Rを終了する前にクラスタに対して COLOR(red){stopCluster} ...
きれいにシャットダウンできるようになる。
**クラスタを開始し終了する [#e0c657df]
ワークステーションクラスタの開始は、基底にあるコミュニケ...
クラスタを使用する際の唯一のステップである。
クラスタは COLOR(red){makeCluster} 関数を呼び出すと開始さ...
タイプにより少々異なる。PVM と MPI クラスタはまた、PVM も...
予備的準備的を必要とするかもしれない。
**PVM クラスタを開始する [#i3a40f74]
PVM (Parallel Virtual Machine) クラスタを開始するには、ま...
私は、このためには、私は PVM コンソール COLOR(red){pvm} ...
~
COLOR(blue){<starting PVM using the pvm console>}
luke@itasca cluster% pvm
pvm> add itasca
add itasca
0 successful
HOST DTID
itasca Duplicate host
pvm> add owasso
add owasso
1 successful
HOST DTID
owasso 80000
pvm> conf
conf
2 hosts, 2 data formats
HOST DTID ARCH SPEED ...
itasca 40000 LINUX 1000 0x004...
owasso 80000 DARWIN 1000 0x065...
pvm>
COLOR(red){conf} 命令で示された並列仮想マシン構成は二つの...
i386 Linux が動く COLOR(red){itasca} と Mac OS X が動く C...
からなる。コマンドラインコンソール COLOR(red){pvm} の代わ...
されていればグラフィカルなコンソール COLOR(red){xpvm} を...
COLOR(red){rpvm} パッケージを使って、COLOR(red){rpvm}
パッケージが提供する R 関数を使っても良い。
一旦 PVM が動き出せば、二つの作業ノードからなるクラスタを...
マスターでRを開始し、 [[snow:http://homepage.stat.uiowa.e...
を二つの引数、作業ノード数と COLOR(red){type = "PVM"} で...
~
COLOR(blue){<starting a PVM cluster>}
cl <- makeCluster(2, type = "PVM")
返り値はこれらの二つのプロセスへの参照からなるリストであ...
もし COLOR(red){rpvm}パッケージが利用でき COLOR(red){Rmpi...
現在の既定のクラスタタイプは COLOR(red){"PVM"} であり、従...
引数は省略できる。
COLOR(red){PVM} を使った作業が終了したら、それをシャット...
例えば、COLOR(red){pvm} コンソールで COLOR(red){halt} 命...
**MPI クラスタを開始する [#z2df71b0]
もし MPI 2 プロセスを生み出す(spawn) API をサポートしてい...
のような MPI システムを使っているのなら、ソケットや PVM ...
生成できる。もしプロセス生成機能をサポートしない MPI シス...
必要になる。例えば COLOR(red){lamboot} を使い、最初に MPI...
詳細は使用中の MPI システムに依存する。
MPI の利用が終ったらそれをシャットダウンする(もし使用中の...
LAM-MPI に対しては例えば COLOR(red){lamhalt} を使う。
**生成された MPI クラスタ [#y5136517]
プロセス生成機能をサポートする MPI システムに対する MPI ...
~
COLOR(blue){<starting an MPI cluster with process spawnin...
cl <- makeCluster(2, type = "MPI")
もし COLOR(red){rpvm} が利用不可能だが COLOR(red){Rmpi} ...
現在の既定のクラスタタイプは COLOR(red){"MPI"} であり、引...
は省略できる。
**プロセス生成機能を持たない MPI クラスタ [#scce80a1]
もし使用中の MPI システムがプロセス生成機能を持たないか、...
実行したいのなら、 COLOR(red){Rmpi} をインストールする必...
またインストールした COLOR(red){[[snow:http://homepage.st...
ディレクトリから COLOR(red){RMPISNOW} というシェルスクリ...
アクセス可能なパス)にインストールしておく必要がある。
もし COLOR(red){RMPISNOW} がユーザのパス上にあれば、R を...
~
COLOR(blue){<starting R with mpirun>}
mpirun -np 3 RMPISNOW
これはマスターと二つのワーカプロセスを開始する。クラスタ...
このクラスタへの参照は次のようにして得られる:~
~
COLOR(blue){<obtaining a cluster started with mpirun>}
cl <- getMPIcluster()
最新版の COLOR(red){[[snow:http://homepage.stat.uiowa.edu...
~
COLOR(blue){obtaining a cluster started with mpirun>}
cl <- makeCluster()
もしくは、二つのワーカをを持つクラスタに対しては次のよう...
~
COLOR(blue){<obtaining a cluster started with mpirun>}
cl <- makeCluster(2)
**ソケットクラスタを開始する [#z93c6750]
ソケットクラスタを開始するには命令 COLOR(red){makeCluster...
COLOR(red){type="SOCK"} と使用する計算機のリストを指定す...
~
COLOR(blue){<starting a socket cluster>}
cl <- makeCluster(c("itasca", "owasso"), type = "SOCK")
二つの R プロセスからなるクラスタを開始する。一つは COLOR...
COLOR(red){owasso} という計算機上にある. 返り値はこれら二...
**補足的なクラスタ生成引数 [#leac1cc5]
クラスタ生成関数 COLOR(red){makeCluster} には、ノードを生...
指定する幾つかの追加的な名前付き引数を与えることができる。
最も有用な引数はクラスタタイプに対する COLOR(red){type} ...
アーキテクチャとファイルシステムのレイアウトを持つと仮定...
~
COLOR(red){homogeneous} 引数(異質的(heterogeneous)クラス...
に解説がある)、
そしてワーカからの出力が出力先を指示する COLOR(red){outfi...
既定では、COLOR(red){outfile} は COLOR(red){/dev/null} で...
デバッグ時、特に初期設定の試行中、には出力を適当なファイ...
各クラスタ生成呼び出しに対する追加のクラスタオプションを...
もう一つの方法が、COLOR(red){setDefaultClusterOptions} を...
例えば、既定値が「異質的 MPI クラスタ」と指定するには次の...
setDefaultClusterOptions(type="MPI", homogeneous = FALSE)
**クラスタを停止する [#a44a214f]
クラスタを停止するには次のようにすべきである:~
~
COLOR(blue){<stopping a cluster>}
stopCluster(cl)
ソケットクラスタはそれらを生成したプロセスが終了すると自...
それでも COLOR(red){stopCluster} を呼び出すのが好ましい。
それが生成したプロセスが存在するより前に PVM クラスタを終...
COLOR(red){stopCluster} を使用する代わりに、PVM コンソー...
実行しても良い。使用している MPI システムは同様の機能を持...
例えば、LAM システムに対しては COLOR(red){lamhalt} 命令や...
**異質的(inhomogeneous)システム [#u4830cd7]
クラスタ生成時の既定オプション設定では、 COLOR(red){R} シ...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
システムを前提にしている。COLOR(red){[[snow:http://homepa...
既定の設定が有効であるためには、それがマスタに対する COLO...
ライブラリのどれかに存在することが必要である。
異なったレイアウトのファイルシステムや、異なったアーキテ...
持つような、異質的(inhomogeneous)システムでは幾つかの追加...
ワーカプロセスを実行するのに使われる各計算機毎に、スクリ...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
マスタ計算機とワーカプロセスを実行する各計算機で、環境変...
を COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke...
適切なアーキテクチャに対する COLOR(red){rlecuyer} といっ...
ディレクトリの名前にする。
各計算機の検索パス上に適切なバージョンの COLOR(red){R} が...
現時点では、変数 COLOR(red){R_SNOW_LIB} を空でない値に設...
COLOR(red){homogeneous} クラスタオプションを COLOR(red){F...
さもなければ、それは COLOR(red){TRUE} とされる。
**クラスタを使う [#ma985e60]
***基本的関数 [#tf2854f7]
クラスタを使用するための基本的関数は COLOR(red){clusterCa...
COLOR(red){clusterApply} である。COLOR(red){clusterCall} ...
クラスタの各メンバ上で同一引数で呼び出し、結果をリストで...
並列処理される。例えば、ノードにその名前と計算機タイプを...
~
COLOR(blue){<R session>}
> clusterCall(cl, function() Sys.info()[c("nodename","ma...
[[1]]
nodename machine
"owasso.stat.uiowa.edu" "Power Macintosh"
[[2]]
nodename machine
"itasca" "i686"
有用な COLOR(red){clusterCall} の変種は COLOR(red){cluste...
定義される:~
~
COLOR(blue){<definition of clusterEvalQ>}
clusterEvalQ <- function(cl, expr)
clusterCall(cl, eval, substitute(expr), env=.GlobalE...
これは例えば、各クラスタノードにあるパッケージをロードす...
~
COLOR(blue){<loading a library on all nodes>}
clusterEvalQ(cl, library(boot))
COLOR(red){clusterApply} は COLOR(red){lapply} の変種で、...
呼び出しを実行する。クラスタのノード数はリスト引数中の要...
簡単な例:~
~
COLOR(blue){<R session>}
> clusterApply(cl, 1:2, get("+"), 3)
[[1]]
[1] 4
[[2]]
[1] 5
***乱数発生 [#b77d6617]
既定の乱数発生器は強い相関を持つ可能性が高い:~
~
COLOR(blue){<R session>}
> clusterCall(cl, runif, 3)
[[1]]
[1] 0.08496597 0.35232298 0.60300751
[[2]]
[1] 0.08496597 0.35232298 0.60300751
これを回避する手軽な方法は乱数種であり、
次のようにする:~
~
COLOR(blue){<random seeding of cluster generators>}
clusterApply(cl, runif(length(cl),max=10000000), set.seed)
より良い方法は並列乱数発生器 パッケージを使うことである。...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
http://www.iro.umontreal.ca/%7Elecuyer/myftp/papers/strea...
インタフェイスである。 関数 COLOR(red){clusterSetupRNG} ...
ランダムな種を使う。ヘルプ頁で説明された名前付き引数を使...
~
COLOR(blue){<R session>}
> clusterSetupRNG(cl)
> clusterCall(cl, runif, 3)
[[1]]
[1] 0.749391854 0.007316102 0.152742874
[[2]]
[1] 0.8424790 0.8896625 0.2256776
***ブートストラップの例 [#o009eba3]
COLOR(red){boot} パッケージはデータ COLOR(red){nuclear} ...
COLOR(red){boot} のヘルプ頁に与えられた準備コードは次のよ...
~
COLOR(blue){<bootstrap setup>}
library(boot)
# この例では nuclear データに基づく回帰予測で boot を使...
# この例は Davison and Hinkley (1997) の例6.8 から取っ...
# 統計量に対する2つの追加引数が boot 経由で渡されている...
data(nuclear)
nuke <- nuclear[,c(1,2,5,7,8,10,11)]
nuke.lm <- glm(log(cost)~date+log(cap)+ne+ ct+log(cum....
nuke.diag <- glm.diag(nuke.lm)
nuke.res <- nuke.diag$res*nuke.diag$sd
nuke.res <- nuke.res-mean(nuke.res)
# データ、標準化残さ、当てはめ値を持つ新しいデータフレ...
# ブートストラップで使うために作る。
nuke.data <- data.frame(nuke,resid=nuke.res,fit=fitted...
# 番号32のプラントの日付 73.00 での予測値を得たい。
new.data <- data.frame(cost=1, date=73.00, cap=886, ne...
ct=0, cum.n=11, pt=1)
new.fit <- predict(nuke.lm, new.data)
nuke.fun <- function(dat, inds, i.pred, fit.pred, x.pr...
assign(".inds", inds, envir=.GlobalEnv)
lm.b <- glm(fit+resid[.inds] ~date+log(cap)+ne+ct+
log(cum.n)+pt, data=dat)
pred.b <- predict(lm.b,x.pred)
remove(".inds", envir=.GlobalEnv)
c(coef(lm.b), pred.b-(fit.pred+dat$resid[i.pred]))
}
一つのワークステーションではブートストラップ例は
約30秒かかった。~
~
COLOR(blue){<R session>}
> system.time(nuke.boot <-
+ boot(nuke.data, nuke.fun, R=999, m=1,
+ fit.pred=new.fit, x.pred=new.data))
[1] 26.32 0.71 27.02 0.00 0.00
二つの計算機からなるクラスタ (このときは同一の i686 ノー...
約2倍早かった。~
~
COLOR(blue){<R session>}
> clusterEvalQ(cl, library(boot))
> system.time(cl.nuke.boot <-
+ clusterCall(cl,boot,nuke.data, nuke.fun, R...
+ fit.pred=new.fit, x.pred=new.d...
[1] 0.01 0.00 14.27 0.00 0.00
4台のノードのクラスタでは約6秒であった。~
~
COLOR(blue){<R session>}
> cl <- makeCluster(5)
> clusterEvalQ(cl,library(boot))
> system.time(cl.nuke.boot <-
+ clusterCall(cl,boot,nuke.data, nuke.fun, R...
+ fit.pred=new.fit, x.pred=new.d...
[1] 0.03 0.00 5.58 0.00 0.00
速度を比較するのに使うべき値は三番目の経過時間である。
***高水準関数 [#y5f4eae1]
COLOR(red){clusterApply} を用いた高水準関数は
COLOR(red){parLapply}, COLOR(red){parSapply}, そして COLO...
これらはそれぞれ COLOR(red){lapply}, COLOR(red){sapply}、...
の並列版である。幾つかの例を示す:~
~
COLOR(blue){<higher level examples>}
sum(parApply(cl, matrix(1:100,10), 1, sum))
sum(parApply(cl, matrix(1:10000,100), 1, sum))
COLOR(blue){<higher level examples>}
x <- 1:100/101
system.time(qtukey(x, 2, df=2))
system.time(unlist(parLapply(cl, x, qtukey, 2, df=2)))
解説のために行列積の並列計算の非常に簡単な例をあげる:~
~
COLOR(blue){<higher level examples>}
A <- matrix(rnorm(10000),100)
system.time(A %*% A)
system.time(parMM(cl,A , A))
**コメント [#p8f71ce2]
留意すべき幾つかの注意:
-計算機間の通信速度は計算速度に比べるとかなり遅い。
-この構成では通信は直列化されている。
-大きなサイズの結果を返す R 関数がある。結果を返す前に縮...
-PVM と MPI 版は迷子のジョブを残さないことを確実にすると...
PVM コンソール、もしくは COLOR(red){lamhalt} と COLOR(red...
PVM もしくは LAM-MPI 領域を停止することにより R プロセス...
ソケットを使った実装では、マスタが存在するときはどんな稼...
残すべきではない。しかし、妙な具合でそうなることもあり得...
解説のために行列積の並列計算の非常に簡単な例をあげる:~
~
COLOR(blue){<higher level examples>}
A <- matrix(rnorm(10000),100)
system.time(A %*% A)
system.time(parMM(cl,A , A))
**コメント [#h122a737]
留意すべき幾つかの注意:
-計算機間の通信速度は計算速度に比べるとかなり遅い。
-この構成では通信は直列化されている。
-大きなサイズの結果を返す R 関数がある。結果を返す前に縮...
-PVM と MPI 版は迷子のジョブを残さないことを確実にすると...
PVM コンソール、もしくは COLOR(red){lamhalt} と COLOR(red...
PVM もしくは LAM-MPI 領域を停止することにより R プロセス...
ソケットを使った実装では、マスタが存在するときはどんな稼...
残すべきではない。しかし、妙な具合でそうなることもあり得...
時としてまずいことが起き得、手動による後かたづけが必要に...
**未解決の問題 [#n4028b8f]
***エラー処理 [#f9f57b62]
エラー処理は現在のところ非常に素朴である。ワーカノードで...
COLOR(red){try} 関数を用いて実行される。従って、返り値は...
COLOR(red){try} 関数が返すエラーである。原則としてユーザ...
幾つかのノードがエラーを出し、その他はエラーにならない状...
明らかでなく、問題による。R がより洗練されたエラー処理機...
COLOR(red){[[snow:http://homepage.stat.uiowa.edu/~luke/R/...
できるであろう。
***中断処理 [#v8a1430c]
理想的には、マスタに於ける中断はワーカに伝播すべきで、現...
しかしそうなってはいない。実際、COLOR(red){[[snow:http://...
通信基盤を混乱した状態に陥れ、それ以降現在の R セッション...
一時しのぎの解決策: COLOR(red){[[snow:http://homepage.st...
R が中断に対する処理を制御する機構を持てば、もう少しまし...
実際に中断をワーカノードに伝播させることが可能になるかど...
*(2) snowクラスタでの一様乱数発生 (snowパッケージのヘルプ...
**説明: [#ed469ad7]
SNOWクラスタで使う独立一様乱数ストリームを初期化する。L'E...
**用法: [#pe026850]
clusterSetupRNG (cl, type = "RNGstream", ...)
clusterSetupRNGstream (cl, seed=rep(12345,6), ...)
clusterSetupSPRNG (cl, seed = round(2^32 *runif(1)),
prngkind = "default", para = 0, ....
**引数: [#x373208e]
cl: クラスタオブジェクト
type: 'type="RNGstream"' (既定) は L'Ecuyer の RNG、
'type="SPRNG"' は SPRNG 発生器を使う
...: 背景にある関数(以下の詳細を見よ)へ渡される引数
seed: RNGの種として使われる整数値 (SPRNG) もしくは長...
prngkind: SPRNG で使われる発生法タイプの名前文字列
para: 発生器にたいする追加引数
**詳細: [#b0aaef79]
- COLOR(red){clusterSetupRNG} はその引数値に応じて他の関...
- COLOR(red){clusterSetupSPRNG} は 'rsprng' パッケージを...
- COLOR(red){clusterSetupRNGstream} は 'rlecuyer' パッケ...
- より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/cl...
**例: [#c0470d3d]
## Not run:
clusterSetupSPRNG(cl)
clusterSetupSPRNG(cl, seed=1234)
clusterSetupRNG(cl, seed=rep(1,6))
## End(Not run)
*(3) クラスタレベルのSNOW関数 (snowパッケージのヘルプ文章...
**説明: [#m076b2e2]
SNOWクラスタ上で計算を行う関数。
**用法: [#pcebd8e8]
clusterSplit(cl, seq)
clusterCall(cl, fun, ...)
clusterApply(cl, x, fun, ...)
clusterApplyLB(cl, x, fun, ...)
clusterEvalQ(cl, expr)
clusterExport(cl, list)
**引数: [#j67566fb]
cl: クラスタオブジェクト
fun: 関数もしくは関数名を与える文字列
expr: 評価すべき表現式
seq: 分割されるベクトル
list: エクスポートされる変数名の文字列
x: 配列
...: 標準関数に引き渡される追加引数
**詳細: [#s3698d23]
-これらはクラスタ上で計算を行うための基本的関数である。ス...
-COLOR(red){clusterCall} は関数 'fun' をクラスタ 'cl' の...
-COLOR(red){clusterEvalQ} は各クラスタノードで文字通りの...
-COLOR(red){clusterApply} は関数 'fun' を、最初のクラスタ...
-COLOR(red){clusterApplyLB} は COLOR(red){clusterApply} ...
-COLOR(red){clusterExport} は 'list' 中に名前があるマスタ...
-COLOR(red){clusterSplit} は 'seq' を各クラスタに対する連...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#xd356224]
## Not run:
cl <- makeSOCKcluster(c("localhost","localhost"))
clusterApply(cl, 1:2, get("+"), 3)
clusterEvalQ(cl, library(boot))
x<-1
clusterExport(cl, "x")
clusterCall(cl, function(y) x + y, 2)
## End(Not run)
*(4) [[snow:http://homepage.stat.uiowa.edu/~luke/R/cluste...
**説明: [#cf5fa85b]
SNOWクラスタを開始・停止し、クラスタオプションを設定する...
**用法: [#ddca7af0]
makeCluster(spec, type = getClusterOption("type"), ....
stopCluster(cl)
setDefaultClusterOptions(...)
makeSOCKcluster(names, ..., options = defaultCluster...
makePVMcluster(count, ..., options = defaultClusterO...
makeMPIcluster(count, ..., options = defaultClusterO...
getMPIcluster()
**引数: [#d75681e3]
spec: クラスタ指定
count: 生成するノー度数
names: ノード名の文字列ベクトル
options: クラスタオプションオブジェクト
cl: クラスタオブジェクト
...: クラスタオプション指定
type: クラスタのタイプを指定する文字列
**詳細: [#dbf4bf8f]
-COLOR(red){makeCluster} は指定もしくは既定タイプのクラス...
このベクトル中の各ノードに対してひとつのノードが開始され...
-COLOR(red){stopCluster} はクラスタを適切にシャットダウン...
-COLOR(red){setDefaultClusterOptions} は既定のクラスタオ...
-COLOR(red){homogeneous} オプションは非同質的なクラスタに...
-オプション COLOR(red){outfile} はスレーブノードでの出力...
-関数 COLOR(red){makeSOCKcluster}, COLOR(red){makePVMclus...
-プロセス生成(process spawning)が利用できず、マスタとスレ...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#ifa5cdfd]
## Not run:
cl <- makeCluster(c("localhost","localhost"), type =...
clusterApply(cl, 1:2, get("+"), 3)
## End(Not run)
*(5) 高水準SNOW関数 (snowパッケージのヘルプ文章) [#m13f7f...
**説明: [#b96b7519]
'apply' 関数の並列版と関連関数。
**用法: [#ade1d1f2]
parLapply(cl, x, fun, ...)
parSapply(cl, X, FUN, ..., simplify = TRUE, USE.NAME...
parApply(cl, X, MARGIN, FUN, ...)
parRapply(cl, x, fun, ...)
parCapply(cl, x, fun, ...)
parMM(cl, A, B)
**引数: [#n6ab07c7]
cl: クラスタオブジェクト
fun: 関数もしくは関数名文字列
X: 使用される配列
x: 使用される行列
FUN: 関数もしくは関数名文字列
MARGIN: 使用される次元を指定するベクトル
simplify: 論理値、'sapply' を参照
USE.NAMES: 論理値、'sapply' を参照
...: 標準関数に引き渡される追加引数
A: 行列
B: 行列
**詳細: [#u74bbd47]
-COLOR(red){parLapply}, COLOR(red){parSapply} そして COLO...
-COLOR(red){parRapply} と COLOR(red){parCapply} は行列 'x...
-COLOR(red){parMM} は非常に簡単な行列積の並列版である。説...
-より詳しくは [[URL:http://www.stat.uiowa.edu/~luke/R/clu...
**例: [#i4d87189]
## Not run:
cl <- makeSOCKcluster(c("localhost","localhost"))
parSapply(cl, 1:20, get("+"), 3)
## End(Not run)
*(6) Rmpi パッケージ情報 [#ecaa7a7b]
[[snow:http://homepage.stat.uiowa.edu/~luke/R/cluster/clu...
と呼ばれるクラスタ構成ソフトへのインタフェイスで、それ自...
**MPI API: [#i41cc0b6]
mpi.abort Abort (quit) all tasks associate...
mpi.allgather Gather data from each process to...
mpi.allgatherv Gather diff size data from each ...
mpi.allreduce Reduce all process's vectors int...
mpi.barrier Block the caller until all group...
mpi.bcast Broadcast a vector (int,double,c...
mpi.cancel Cancel a nonblocking send or recv
mpi.cart.coords Translate a rank to the Cartesia...
mpi.cart.create Create a Cartesian structure of ...
mpi.cartdim.get Get dim information about a Cart...
mpi.cart.get Provide the Cartesian topology a...
mpi.cart.rank Translate a Cartesian topology c...
mpi.cart.shift Shift Cartesian topology in disp...
mpi.comm.disconnect Disconeect and free a comm
mpi.comm.dup Duplicate a comm to a new comm
mpi.comm.free Free a comm
mpi.comm.get.parent Get the parent intercomm
mpi.comm.rank Find the rank (process id) of ma...
mpi.comm.remote.size Find the size of a remote group ...
mpi.comm.size Find the size (total # of master...
mpi.comm.set.errhandler Set comm to error return (no cra...
mpi.comm.spawn Spawn slaves
mpi.comm.test.inter Test if a comm is an intercomm
mpi.dims.create Create a Cartesian dim used by m...
mpi.finalize Exit MPI environment (call MPI_F...
mpi.gather Gather data from each process to...
mpi.gatherv Gather diff data from each proce...
mpi.get.count Get the length of a message for ...
mpi.get.processor.name Get the process (host) name
mpi.info.create Create an info object
mpi.info.free Free an info object
mpi.info.get Get the value from an info objec...
mpi.info.set Set a key/value pair of an info ...
mpi.intercomm.merge Merge a intercomm to a comm
mpi.iprobe Nonblocking use a source and a t...
mpi.irecv Nonblocking receive a vector fro...
mpi.isend Nonblocking send a vector to a s...
mpi.probe Use a source and a tag to set st...
mpi.recv Receive a vector from a specific...
mpi.reduce Reduce all processes's vectors i...
mpi.scatter Opposite of mpi.gather
mpi.scatterv Opposite of mpi.gatherv (diff si...
mpi.send Send a vector to a specific proc...
mpi.sendrecv Send & receive different vectors...
mpi.sendrecv.replace Send & replace a vector in one c...
mpi.test Test if a nonblocking send/recv ...
mpi.testall Test if all nonblocking send/rec...
mpi.testany Test if any nonblocking send/rec...
mpi.testsome Test if some nonblocking send/re...
mpi.test.cancelled Test if a communication is cance...
mpi.universe.size Total number of CPUs available
mpi.wait Wait if a nonblocking send/recv ...
mpi.waitall Wait if all nonblocking send/rec...
mpi.waitany Wait if any nonblocking send/rec...
mpi.waitsome Wait if some nonblocking send/re...
**MPI R 環境の拡張: [#ec18b10c]
lamhosts Hosts id and machine host name mappi...
mpi.allgather.Robj Gather any type of objects to every ...
mpi.any.source A constant for receiving a message f...
mpi.any.tag A constant for receiving a message f...
mpi.bcast.Robj Broadcast an R object to every process
mpi.comm.maxsize Find the length of comm array
mpi.exit MPI_Finalize を呼出し、Rmpi ライブラ...
mpi.gather.Robj Gather any type of object to a root...
mpi.get.sourcetag Get the source and tag for a given s...
mpi.hostinfo Get the host information that the pr...
mpi.init.sprng rsprng ライブラリ中の SPRNG を初期化...
mpi.is.master TRUE if it is a master otherwise FAL...
mpi.isend.Robj Nonblocking send an R object to a sp...
mpi.proc.null Dummy source and destination
mpi.quit MPI_Finalize を呼出し R を終了する
mpi.recv.Robj Receive an R object from a process (...
mpi.realloc.comm Increase comm array to a new size
mpi.realloc.request Increase request array to a new size
mpi.realloc.status Increase status array to a new size
mpi.request.maxsize Find the length of request array
mpi.scatter.Robj Scatter an list to every number
mpi.send.Robj Send an R object to a specific process
mpi.spawn.Rslaves Spawn R slaves. The default R script...
mpi.status.maxsize Find the length of status array
mpichosts finds host names from master Windows...
**MPI slavedaemon.R スクリプト固有の拡張 (インタラクティ...
mpi.apply 配列をスレーブに分配し、それから fu...
mpi.applyLB mpi.apply の負荷均等版
mpi.bcast.Robj2slave Master sends an Robj to all slaves
mpi.bcast.cmd 全てのプロセスにある命令をブロード...
mpi.close.Rslaves mpi.spawn.Rslaves() で起動された全...
mpi.parApply (負荷均等版) 並列 apply 関数
mpi.parCapply (負荷均等版) 列への並列 apply 関数
mpi.parLapply (負荷均等版) 並列 lapply 関数
mpi.parRapply (負荷均等版) 行への並列 apply 関数
mpi.parReplicate ある表現式の反復評価のための mpi.pa...
mpi.parSapply (負荷均等版) 並列 sapply 関数
mpi.parSim (負荷均等版) 並列モンテカルロシミュ...
mpi.remote.exec ある命令をスレーブで遠隔実行し、結...
mpi.setup.rngstream パッケージ rlecuyer の RNDstream を...
mpi.setup.sprng パッケージ rsprng の SPRNG を全ての...
slave.hostinfo 全てのスレーブの rank, comm, host i...
tailslave.log スレーブのログファイルの末尾部分を...
**他の MPI 関数が用いる内部関数 [#b4f4fd00]
bin.nchar Find the length of a binary string
mpi.comm.is.null Test if a comm is NULL (no members)
string Create a string (empty space charac...
*(7) パッケージ rpvm の情報 [#a6686ab6]
パッケージ rpvm はPVM (Parallel Virtual Machine) API への...
**パッケージ 'rpvm' 内の関数の簡易説明一覧 [#afaf087e]
.PVM.barrier Group synchronization
.PVM.bcast Broadcasting the data
.PVM.bufinfo Message buffer infomation
.PVM.config PVMD configuration
.PVM.exit Unregister process from local PVM deam...
.PVM.freebuf Free message buffer
.PVM.gather Gather the data into root
.PVM.getinst Instance number identified by group na...
.PVM.getsbuf Manipulating Message Buffers
.PVM.gettid Task id identified by group name and i...
.PVM.gsize Get the size of the group
.PVM.initsend Initialize send buffer
.PVM.joingroup Join or leave a names group
.PVM.kill pvm プロセスを停止する
.PVM.mcast Multicast data
.PVM.mkbuf Create message buffer
.PVM.mstats Status of host machines
.PVM.mytid Task IDs
.PVM.notify Monitor pvmd
.PVM.nrecv Nonblocking receive
.PVM.probe Probe receive
.PVM.pstats Status of PVM processes
.PVM.recv Blocking receive
.PVM.reduce Reduction
.PVM.scatter Scatter a vector across the group
.PVM.send Send data
.PVM.serialize Serialize R Objects
.PVM.spawn Spawn child tasks
.PVM.tasks Tasks information
.PVM.tidtohost Host id of a task
.PVM.trecv Timeout receive
PVM.options libpvm Options
PVM.pack Packing data
PVM.rapply 並列版 apply 関数
PVM.unpack Unpacking data
PVMD Vitural Machine Control
init.sprng.master SPRNG を初期化する rsprng へのインタフ...
ページ名: