Matlabのparallel toolboxのparforを使う

毎回、使い方を忘れるので、自分用の覚書。

# クラスターでの並列プールの作成
parpool('local',2);
#これはローカル・プロファイルを使用して、2個のワーカーからなる並列プールを作る場合

# 走らせたい処理をparforで書く
parfor i=1:1024
A(i) = sin(i*2*pi/1024);
end
plot(A)

#並列プールのシャットダウン
delete(gcp);

[参考1]
昔はparpoolの代わりにmatlabpoolが使われていた。しかし、matlabpoolは将来のリリースで削除される予定
[参考2]
もう少し実用的な例が http://jp.mathworks.com/help/distcomp/examples/simple-benchmarking-of-parfor-using-blackjack.html

[参照URL]
http://jp.mathworks.com/help/distcomp/parpool.html
http://jp.mathworks.com/help/distcomp/parfor.html
http://jp.mathworks.com/help/distcomp/delete_pool.html
http://jp.mathworks.com/help/distcomp/gcp.html