複数の do ブロックを also で並べると並列処理される treeSum(t : TreeLeaf) = 0 treeSum(t : TreeNode) = do
var accum := 0
do
accum += treeSum(t.left)
also do
accum += treeSum(t.right)
also do
accum += t.datum
end
accum end お、これは面白い。
リダクションは定義された演算子が総和のみに使われているなら自動的に判定してくれるらしい
for i ← 1:10 do sum += i end これは OpenMP とか HPF の流れか。 あとは generator とかいう生成式を定義するやつが目新しいけど、一般アプリケーションには使いどころが難しそう。
treeSum(t : TreeLeaf) = 0 treeSum(t : TreeNode) = do var accum := 0 do accum += treeSum(t.left) also do accum += treeSum(t.right) also do accum += t.datum end accum end
13.15.1 Reduction Variables (中略) We say that a variable l is a reduction variable reduced using the reduction operator ⊙ for a particular for loop if it satisfies the following conditions:
Every assignment to l within the loop body uses the same reduction operator ⊙, and the value of l is not otherwise read or written.
The variable l is not a free variable of a fn expression or a method in an object expression whic
並列化まわりをざっと。 (スコア:2, 参考になる)
for i ← 1:10 do print(i) end
(factorial(100), factorial(500), factorial(1000))
ふむふむ。昨今支持の広がっている、配列を並列化単位にしようという流儀ですね。
atomic式
x=0; y=0
(atomic do x+=1; y+=1 end, z=x+y)
二行目はタプルなので並列化されるけれど、
zは第一項はatomicなので z=0 か z=2 であり z=1 になることはないと。
複数の do ブロックを also で並べると並列処理される
treeSum(t : TreeLeaf) = 0
treeSum(t : TreeNode) = do
var accum := 0
do
accum += treeSum(t.left)
also do
accum += treeSum(t.right)
also do
accum += t.datum
end
accum
end
お、これは面白い。
関数・メソッド呼び出しは並列になる
myString.replace("foo", "few")
引数が並列に評価されて、myString が評価されて、replace 本体が実行されるのかな。
メソッド名は ID だけれど、関数の場合は式で、
arctan(y,x)
arctan,y,x 全てが並列に評価されるようだ。
このあたりは関数型言語や論理型言語の並列化に似てますね。
リダクションは定義された演算子が総和のみに使われているなら自動的に判定してくれるらしい
for i ← 1:10 do sum += i end
これは OpenMP とか HPF の流れか。
あとは generator とかいう生成式を定義するやつが目新しいけど、一般アプリケーションには使いどころが難しそう。
Re:並列化まわりをざっと。 (スコア:0)
この(仕様書に書いてある)例、間違ってないか?
+= がatomic operationでないと正しく動かないのだけど、仕様書に
はatomicであるとは書いておらず、かつsyntax sugarと書いてある。
for文と同様に、各スレッド
Re:並列化まわりをざっと。 (スコア:0)
勇気を持つ人ってすごいですね.私にはまねできません.
Re:並列化まわりをざっと。 (スコア:0)
Re:並列化まわりをざっと。 (スコア:0)
するという処理があればOKだけど
そういう処理のことを Reduction といいます。