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 which occurs in the loop body.
The variable l is not an object field.
(中略) At the end of the loop body, the original variable value before the loop and the final variable values from each execution of the loop body are combined together using the reduction operator, in some arbitrarily-determined order.
並列化まわりをざっと。 (スコア: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
Re:並列化まわりをざっと。 (スコア:0)
この(仕様書に書いてある)例、間違ってないか?
+= がatomic operationでないと正しく動かないのだけど、仕様書に
はatomicであるとは書いておらず、かつsyntax sugarと書いてある。
for文と同様に、各スレッド
Re:並列化まわりをざっと。 (スコア:0)
勇気を持つ人ってすごいですね.私にはまねできません.
Re:並列化まわりをざっと。 (スコア:0)