According to this post , it seems that there is no way to limit the number of threads globally in the final version of Parallel Extensions. An alternative to what Brian offers would be to use PLINQ (which works with parallel sequences) instead of functions that work with arrays.
This can be done using the module PSeqfrom F # PowerPack . It provides features like PSeq.map, PSeq.filterand many others that work with parallel sequences (which can also be well composed using pipelining). For parallel sequences, you can use the WithDegreeOfParallelism extension method to indicate behavior.
You can implement a wrapper function for it:
[EDIT: it already exists!]
let withDegreeOfParallelism n (pq:ParallelQuery<_>) =
pq.WithDegreeOfParallelsm(n)
And then write:
let res =
data |> PSeq.map (fun n -> ...)
|> PSeq.withDegreeOfParallelism ParallelOptions.MaxDegreeOfParallelism
|> Array.ofSeq
This may have a different performance, because it is implemented differently than the functions in the module Array.Parallel, but it certainly depends on your scenario.
source
share