How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)
-
Hi, I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach. They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a quad core). I know there is a way I just can find the right property. Gilad. P.S. Please don't write that more threads won't give better output, I already have got a bunch of those.
-
Hi, I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach. They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a quad core). I know there is a way I just can find the right property. Gilad. P.S. Please don't write that more threads won't give better output, I already have got a bunch of those.
-
Well, I believe (but don't quote me on that), that you can create a new
TaskManager
and give it a parametermaxConcurrentThreads
(or such) Is that what you're looking for? -- edited to not be an answer --modified on Friday, January 1, 2010 6:30 PM
Well... this is kinda tricky.. in the System.Threading 2008CTP you could see the TaskManager and it actually had properties for Threads-Per-Cpu under
System.Threading.Tasks.TaskManager.Current.Policy.IdealThreadsPerProcessor
but for some reason it wasn't possible see the default taskManager nor to access those values (read-only) or create a TaskManager of your own. In the 2010 beta there is no TaskManager... hmmm... I couldn't find any similar object that might do the same job. What is going on???
-
Well... this is kinda tricky.. in the System.Threading 2008CTP you could see the TaskManager and it actually had properties for Threads-Per-Cpu under
System.Threading.Tasks.TaskManager.Current.Policy.IdealThreadsPerProcessor
but for some reason it wasn't possible see the default taskManager nor to access those values (read-only) or create a TaskManager of your own. In the 2010 beta there is no TaskManager... hmmm... I couldn't find any similar object that might do the same job. What is going on???
-
Hi, I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach. They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a quad core). I know there is a way I just can find the right property. Gilad. P.S. Please don't write that more threads won't give better output, I already have got a bunch of those.
You can use an overload that takes a
ParallelOptions
parameter and set itsMaxDegreeOfParallelism
property. However, the defaultTaskScheduler
uses the thread pool to decide the number of running threads, so you're not really in control. If you use Tasks instead, you can passTaskCreationOptions.LongRunning
, which spawns a new thread every time. Nick---------------------------------- Be excellent to each other :)
-
Hi, I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach. They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a quad core). I know there is a way I just can find the right property. Gilad. P.S. Please don't write that more threads won't give better output, I already have got a bunch of those.
quote:
var query = from item in source.AsParallel().WithDegreeOfParallelism(10)
where Compute(item) > 42
select item;In cases where a query is performing a significant amount of non-compute-bound work such as File I/O, it might be beneficial to specify a degree of parallelism greater than the number of cores on the machine. from: MSDN[^]
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters