并行Fsharp与并行C ++

时间:2017-05-28 15:07:10

标签: c++ parallel-processing f#

我复制粘贴了此example的并行部分。我测量了i3处理器的时间,测量值为37563ms。我在Fsharp中重写了相同的程序,就像这样

 let rec fib x = if x<2 then x else fib(x-1)+fib(x-2)
 let time_call f = 
 let b=System.Environment.TickCount in
 let x = f() in
 System.Environment.TickCount-b

 let fibs() =
  Async.Parallel[for i in [24;26;41;42]->async{return fib   i}]|>Async.RunSynchronously

 [<EntryPoint>]
 let main argv = 
 printfn "%A" (time_call fibs)
 0 // return an integer exit code

我测量的时间是4735毫秒。我做错了什么或者Fsharp并行编程要快得多吗?

1 个答案:

答案 0 :(得分:4)

fibs / f是示例中的值,而不是函数。在fibs开始之前计算main

你想要例如。

let x = printfn "%A" (f()) in

let fibs() =