Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Exposing the Task Scheduler

Shankar1
Beginner
103 Views
I have been evaluating the use of TBB for quite some time and i have a question about the use
of Task sheduler. As I understand TBB aims at hiding the complexity of threading and task scheduling
from the user completely.So I assume that this is the reason why the Task scheduler is not exposed
extensively to the user.

By exposing the task scheduler, I mean to be possible to define tasks ( by classes deriving from tbb::task
and overriding execute method) and be able to queue these tasks to the scheduler for execution.

For example,
// Defining a Task required of user
TaskA : tbb::task{

void execute(){
// Some Algorithm
}

};

TaskA taskA;
task_scheduler scheduler;
scheduler.QueueTask( taskA);

Can thepresent TBB scheduler be used in this way or is it possible that the scheduler be tweaked to be used
this way too? I would be interested to know the implications of this.
0 Kudos
2 Replies
Alexey_K_Intel3
Employee
103 Views
Yes TBB can be used this way right now, though the syntax to do that is somewhat different. One example how it can be done is:
TaskA& taskA = *new (allocate_root()) TaskA;
spawn_root_and_wait(taskA);

Study the TBB Refefence manual for more details about the direct use of tasks.
AJ13
New Contributor I
103 Views
Quoting - Shankar
I have been evaluating the use of TBB for quite some time and i have a question about the use
of Task sheduler. As I understand TBB aims at hiding the complexity of threading and task scheduling
from the user completely.So I assume that this is the reason why the Task scheduler is not exposed
extensively to the user.

By exposing the task scheduler, I mean to be possible to define tasks ( by classes deriving from tbb::task
and overriding execute method) and be able to queue these tasks to the scheduler for execution.

For example,
// Defining a Task required of user
TaskA : tbb::task{

void execute(){
// Some Algorithm
}

};

TaskA taskA;
task_scheduler scheduler;
scheduler.QueueTask( taskA);

Can thepresent TBB scheduler be used in this way or is it possible that the scheduler be tweaked to be used
this way too? I would be interested to know the implications of this.

Why would you want to do this now?

Technically, you can override the scheduler by returning the next task to execute from the call to execute(). So you can do the queue you want just by creating a task that will return the next task from a queue after it's executed itself.

AJ
Reply