by
Anonymous Coward
on 2007年01月16日 18時05分
(#1092660)
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
Re:並列化まわりをざっと。 (スコア:0)
+= がatomic operationでないと正しく動かないのだけど、仕様書に
はatomicであるとは書いておらず、かつsyntax sugarと書いてある。
for文と同様に、各スレッド毎にローカルなaccumを確保してjoin時に値を合計
するという処理があればOKだけど、そんなことをしている気配も(仕様書には)
見えない。
Re:並列化まわりをざっと。 (スコア:0)
勇気を持つ人ってすごいですね.私にはまねできません.
Re:並列化まわりをざっと。 (スコア:0)
Re:並列化まわりをざっと。 (スコア:0)
するという処理があればOKだけど
そういう処理のことを Reduction といいます。