Is it possible to set ‘MaxDegreeOfParallelism’ (that is maximum number of threads to use) for Array.Parallel module since under the hood it uses Parallel.For?
Is it possible to set ‘MaxDegreeOfParallelism’ (that is maximum number of threads to use)
Share
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 suggests would be to use PLINQ (which works with parallel sequences) instead of functions that work with arrays.
This can be done using the
PSeqmodule from F# PowerPack. It provides functions such asPSeq.map,PSeq.filterand many other that work with parallel sequences (which can be also nicely composed using pipelining). For parallel sequences, you can use the WithDegreeOfParallelism extension method to specify the behavior.You could implement a wrapper function for it:[EDIT: It is already there!]
And then write:
This may have different perfromance, because it is implemented differently than functions in the
Array.Parallelmodule, but this certainly depends on your scenario.