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

Is there a way to check whether a task_schedular_init object is available in the current thread ?

Rob_Ottenhoff
New Contributor I
400 Views

Hi All,

Or must I do this administation myself ?

Regards,

Rob

0 Kudos
5 Replies
RafSchietekat
Valued Contributor III
400 Views
A thread can have multiple active task_scheduler_init instances, so if you don't know just add a new one.

0 Kudos
Rob_Ottenhoff
New Contributor I
400 Views
Quoting - Raf Schietekat
A thread can have multiple active task_scheduler_init instances, so if you don't know just add a new one.

Hi Raf,

That seemes rather wasteful: I want to check this in a function which can be called from different threads. The function is part of a video tracking system, so it can be called millions of times. If I have to add a task_scheduler_init instance for every call...

Regards,

Rob

0 Kudos
Dmitry_Vyukov
Valued Contributor I
400 Views
Quoting - Rob Ottenhoff

That seemes rather wasteful: I want to check this in a function which can be called from different threads. The function is part of a video tracking system, so it can be called millions of times. If I have to add a task_scheduler_init instance for every call...

constructor of task_scheduler_init object will do exactly what you want to do. I.e. check whether scheduler already initialized for current thread, and, if yes, just exit.

0 Kudos
RafSchietekat
Valued Contributor III
400 Views
Why do you need a task_scheduler_init if the code does so little that you are concerned about its cost? Ifthe codeonly uses, e.g., atomics and containers, you don't need task_scheduler_init, but maybe a microbenchmark might help you decide whether you need to worry about this.

0 Kudos
Rob_Ottenhoff
New Contributor I
400 Views
Quoting - Raf Schietekat
Why do you need a task_scheduler_init if the code does so little that you are concerned about its cost? Ifthe codeonly uses, e.g., atomics and containers, you don't need task_scheduler_init, but maybe a microbenchmark might help you decide whether you need to worry about this.

Hi Raf,

Thank for your answer, it is most helpful. The behavior of the constructor was not clear to me from the documentation.

I need the task_scheduler_init class to use parallel_reduce. It makes a loop that evaluates the particles in a particle filter parallel. The loop was a performance bottleneck found with a profiler.

Thanks,

Rob

0 Kudos
Reply