は、私は長い間、実行中のタスクを並列化したいParallelisingツリーは、再帰的な手順
let count_change amount =
let first_denomination kinds_of_coins =
match kinds_of_coins with
|1->1
|2->5
|3->10
|4->25
|5->50
let rec cc amount kinds_of_coins =
match (amount,kinds_of_coins) with
|(0,_) -> 1
|(i,j) when i<0 || j=0 -> 0
|(_,_) ->
[cc amount (kinds_of_coins-1) +
cc (amount - (first_denomination kinds_of_coins)) kinds_of_coins]
|> List.fold (+) 0
cc amount 5
次のようにF#でSICPから変更回数の問題を書いて、これは私が
let rec cc amount kinds_of_coins =
match (amount,kinds_of_coins) with
|(0,_) -> 1
|(i,j) when i<0 || j=0 -> 0
|(_,_) ->
[async {return cc amount (kinds_of_coins-1)
+ cc (amount - (first_denomination kinds_of_coins)) kinds_of_coins}]
|> Async.Parallel |> Async.RunSynchronously |> Array.fold (+) 0
これをやったことあります最初の実装よりも数オーダー遅いです。どうすればより効果的に並列化できるのか教えてください。
実際に、深さ優先のトラバーサルは、並列性に関しては、効率面で大きな利点を提供します。 – Noldorin
理由を説明できますか? – leppie