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

Measurements and task_scheduler_init

Martin_K_9
Beginner
1,619 Views

Hi

I am doing some measurement with TBB. I noticed that the first call to tbb::parallel_for is slow. I thought, this might come from the task scheduler initialization that is executed the first time a tbb algorithm is called. And yes it had an influence but I don't realy understand the behaviour.

Inserting

[cpp]task_scheduler_init();[/cpp]

before the first call to tbb::parallel_for is made reduces the time needed for the first call to tbb::parallel_for.

However when I insert:

[cpp]task_scheduler_init init;[/cpp]

the time for the first call to tbb::parallel_for is even shorter but I couldn't get any speedup during the measurement (further calls to tbb::parallel_for)

Is this behavior explainable and what should I call before the measurements to get meaningful results. The used test file is attached.

Thanks for any hints

0 Kudos
21 Replies
Wooyoung_K_Intel
Employee
231 Views

    task_scheduler_init();

If you used the above to initialize tbb scheduler, I would like to ask you to verify that the application actually created the expected number of threads. In the past, we were bitten by the same issue several time. The cause was the compiler was too smart, it destroyed the object as soon as it is intialized. Take a look at for example the section 'Explicit Instantiation of Temporaries' in here

0 Kudos
Reply