Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Task Priority In TBB

Barak_H_Intel
Employee
926 Views
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?
0 Kudos
1 Solution
jimdempseyatthecove
Honored Contributor III
926 Views
Quoting - barakhr
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?

When the long low priority task has I/O statements (or other statements that suspend execution) then as Bartolome suggests create an additional thread (not part of TBB pool).

When the long low priority task is completely compute bound then you have two additional options.

1) When the reason for having low priority to this task is for the purpose of permitting other applications to interceed with priority, then when the task starts (top of execute() function) lower your priority. And at bottom of function, restore your priority.

2) When the reason for having low priority task is for the purpose of permitting other tasks in your application to have more run time then you are getting boxed into a corner.
2a) When the other tasks will vary in numbers of threads required (at times using less than number of hardware threads) then oversubscribe the TBB thread pool by one thread and use option 1.
2b) When other tasks will consume computational resources then use other option to create non-TBB thread.
2c) when not running your long low priority task, schedule a NULL task that runs like your long low priority task (lowers priority at start, restores at end) and which performs a loop with Sleep(0) and test for requirement to run long low priority task.

The goal is effective thread subscription.

Jim Dempsey

View solution in original post

0 Kudos
4 Replies
Bartlomiej
New Contributor I
926 Views
It can hardly be done as task scheduling in TBB is non-preemptive.
I'd suggest combining TBB with some other technique, e.g. Pthreads or Bost threads. One of the threads runs the TBB scheduler and the other one is the low-priority server.

0 Kudos
jimdempseyatthecove
Honored Contributor III
927 Views
Quoting - barakhr
Hi,

How to implement aLong ,low priority task in TBB?

In my application i havesome process tasks ,
and1 very long task that sholud run in the bacground until finished.

The long task should be in low priority and interupted when a process task needs to run.

How do i set the priority of the task?

Can anyone help?

When the long low priority task has I/O statements (or other statements that suspend execution) then as Bartolome suggests create an additional thread (not part of TBB pool).

When the long low priority task is completely compute bound then you have two additional options.

1) When the reason for having low priority to this task is for the purpose of permitting other applications to interceed with priority, then when the task starts (top of execute() function) lower your priority. And at bottom of function, restore your priority.

2) When the reason for having low priority task is for the purpose of permitting other tasks in your application to have more run time then you are getting boxed into a corner.
2a) When the other tasks will vary in numbers of threads required (at times using less than number of hardware threads) then oversubscribe the TBB thread pool by one thread and use option 1.
2b) When other tasks will consume computational resources then use other option to create non-TBB thread.
2c) when not running your long low priority task, schedule a NULL task that runs like your long low priority task (lowers priority at start, restores at end) and which performs a loop with Sleep(0) and test for requirement to run long low priority task.

The goal is effective thread subscription.

Jim Dempsey
0 Kudos
Barak_H_Intel
Employee
926 Views

Thanks for your help,

My case is (2) - Low and high priority tasks in one application,
it's a video processing application with "Process" thread that must be finished ina desired time frame,
And the longlow priority task needs to work "only when time is available" ,
I need the ability to interupt it when new frame arrives.


I hoped that therewill bea solutioninsideTBB ,
i'll have to use something else to prioritze my threads.

thanks,
Barak

0 Kudos
vu64
Beginner
926 Views
Quoting - barakhr

Thanks for your help,

My case is (2) - Low and high priority tasks in one application,
it's a video processing application with "Process" thread that must be finished ina desired time frame,
And the longlow priority task needs to work "only when time is available" ,
I need the ability to interupt it when new frame arrives.


I hoped that therewill bea solutioninsideTBB ,
i'll have to use something else to prioritze my threads.

thanks,
Barak


Use Boost.Threads for native threads when you have to. The API is easy and most of it has been incoporated into the C++0x standard.
0 Kudos
Reply