none
How to force single-threaded execution of PPL primitives?

    Question

  • We want to control the number of parallel threads in our library.

    Atm I'm using Concurrency::Scheduler with a custom SchedulerPolicy to set the number of threads. Though it throws an exception if I try to set concurrency limits to 0, effectively preventing me from associating a single-threaded scheduler with the thread.

    Is there any way to enforce single-threaded execution of PPL primitives (parallel_for, parallel_invoke)?


    • Edited by empty`void Wednesday, February 20, 2013 3:03 AM
    Wednesday, February 20, 2013 2:33 AM

Answers

  • Hi empty`void

    Unfortunately there is no easy way to control the thread count in Concurrency Runtime. Setting the concurrency level is not directly related to thread count. For example if your application is blocking cooperatively on a critical section, the run time will create a new thread in an attempt to maintain concurrency level after that thread gets blocked.

    Setting MaxConcurrency to 0 is not valid. You can set it to 1 and in that case if you have no cooperative blocking in the parallel_for (not using critical section, or any other lock) you will run on 2 threads.

    • Marked as answer by empty`void Friday, February 22, 2013 3:22 AM
    Wednesday, February 20, 2013 4:44 PM

All replies

  • Hi empty`void

    Unfortunately there is no easy way to control the thread count in Concurrency Runtime. Setting the concurrency level is not directly related to thread count. For example if your application is blocking cooperatively on a critical section, the run time will create a new thread in an attempt to maintain concurrency level after that thread gets blocked.

    Setting MaxConcurrency to 0 is not valid. You can set it to 1 and in that case if you have no cooperative blocking in the parallel_for (not using critical section, or any other lock) you will run on 2 threads.

    • Marked as answer by empty`void Friday, February 22, 2013 3:22 AM
    Wednesday, February 20, 2013 4:44 PM
  • That's a shame.

    Other parallel frameworks (e.g. OMP, TBB) allow developer to execute primitives in a single thread.

    Friday, February 22, 2013 3:25 AM