【发布时间】:2015-06-30 17:59:34
【问题描述】:
open System
open System.Diagnostics
open System.Threading.Tasks
open System.Collections
let computation input =
input|> Array.map (fun x-> sqrt(float x))|> ignore
let computation1 (input:int[]) =
input|> Array.map (fun x-> Convert.ToString(x,2)) |> ignore
let abc p =
for i in 1..50000 do
[|for i in 1..100000 -> i|]
|> computation
Parallel.For(0,100,fun x->abc 0) |>ignore
嗨, 在上述程序中,如果我在“abc()”中使用“computation()”运行应用程序,我会看到 CPU 利用率为 70-80%。
但是在“abc()”中使用“computation1()”的相同代码,我看到的 CPU 利用率只有 20%,而且我看到很多(一半的内核) 核心处于空闲状态。
有人知道这种行为吗?
我的 CPU 规格: Intel Xeon CPU @3.40Hz 启用超线程 核心总数:2 个 CPU,每个 8 个核心 = 16 HT 的总核心数 = 2*16 = 32
【问题讨论】:
-
1 大不同 - string 是 ref 类型,int 是 value 类型。第一个的缓存位置和内存带宽要好得多。
-
文体观点:为什么您使用 Parallel.For 而不是 Array.Parallel.map?