Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)

How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)

Scheduled Pinned Locked Moved C#
csharpasp-nettutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gilad Kapelushnik
    wrote on last edited by
    #1

    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.

    L N E 3 Replies Last reply
    0
    • G Gilad Kapelushnik

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Well, I believe (but don't quote me on that), that you can create a new TaskManager and give it a parameter maxConcurrentThreads (or such) Is that what you're looking for? -- edited to not be an answer --

      modified on Friday, January 1, 2010 6:30 PM

      G 1 Reply Last reply
      0
      • L Lost User

        Well, I believe (but don't quote me on that), that you can create a new TaskManager and give it a parameter maxConcurrentThreads (or such) Is that what you're looking for? -- edited to not be an answer --

        modified on Friday, January 1, 2010 6:30 PM

        G Offline
        G Offline
        Gilad Kapelushnik
        wrote on last edited by
        #3

        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???

        L 1 Reply Last reply
        0
        • G Gilad Kapelushnik

          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???

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Aaah breaking API changes! They do not make me happy. I'm sorry, but I really have no clue then.. :(

          1 Reply Last reply
          0
          • G Gilad Kapelushnik

            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.

            N Offline
            N Offline
            Nicholas Butler
            wrote on last edited by
            #5

            You can use an overload that takes a ParallelOptions parameter and set its MaxDegreeOfParallelism property. However, the default TaskScheduler 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 pass TaskCreationOptions.LongRunning, which spawns a new thread every time. Nick

            ---------------------------------- Be excellent to each other :)

            1 Reply Last reply
            0
            • G Gilad Kapelushnik

              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.

              E Offline
              E Offline
              Eric Dahlvang
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups