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

CPU not used at 100%

diedler_f_
Beginner
4,536 Views

Hi everyone,

I wonder if there is not a bug inside TTB library. I explain:

I have a long computation for 1 000 000 objects. For this, I use parralel_for paradigm like this:

size_t size = 1000000;
tbb::parallel_for(tbb::blocked_range<size_t>(0, size),
        [&](const tbb::blocked_range<size_t>& r) {
            for (size_t i=r.begin(); i != r.end(); ++i)
            {
                //long computation here
            }
}

When I launch the program, sometimes my 8 cores work at 100% => That's great !

But sometimes, I have a loss of "powerful" for my threads (i will provide a graphic chart of my CPU usage it will be clearer to understand).

Can you explain why ? Thanks :)

PS: I use Windows 10 with an Intel i7 (8 cores)

 

0 Kudos
26 Replies
jimdempseyatthecove
Honored Contributor III
1,340 Views

Alex,

From little I know about TBB, TBB (I assume) recently switched to using C++11 std::thread, and more importantly std::condition_variable. The std::condition_variable has both notify_one() and notify_all() (whereas former pthread did not have notify_all). Using non-TBB threading, I have experienced similar problems of which I am suspecting that notify_all() is not doing its job, but may be waking up one, or less than all, waiting thread(s), leaving the others to wakeup on the timed wait timer expiration. Note, this is an unfounded suspicion on my part since the TBB scheduler is opaque.

"The logic is OS agnostic and pretty simple" would not be immune to this symptom should TBB be using std::condition_variable::notify_all().

Does TBB use notify_all?

Jim Dempsey

0 Kudos
diedler_f_
Beginner
1,340 Views

Just a message to go up this topic. Maybe put a pin on this topic ?

I am looking forward seeing a fix for this problem because I really need threads in my application. Otherwise, I will code my owm thread pool.

Thanks a lot

0 Kudos
Alexey-Kukanov
Employee
1,340 Views

Hi Diedler,

We do not confirm any issue with CPU usage in TBB. As Alex mentioned above, we tried to reproduce it on several machines, and see no CPU usage problem. I personally tried the attached code on my Win10 laptop (2 cores, 4 threads) and did not see the behavior you described.

The code is derived from yours at the message #8 above. I also added a variant that does not use TBB but C++11 threads instead (see USE_TBB macro). I used VS2015 for compilation. Please try it in your environment and see if there is any difference in behavior for TBB & C++11 threads.

Updated: also tried with TDM MinGW-w64 5.1 - no issues either.

0 Kudos
diedler_f_
Beginner
1,340 Views

Hi Alexey,

I test your program on my Laptop with the same issue. But I have an idea : I noticed the CPU Clock falls down randomly during the bench. That 's explain the CPU usage graph in the message #8. Maybe I have to disable an option in the BIOS but I don't know which option...

I also tried on another Laptop with a CPU Intel Core 17-7700HQ @2.80Ghz and no problem ! The CPU Clock does not fall and all the settings are by default.

So you are right, it is not an issue in TBB library. If you have any idea ?

Thanks

 

0 Kudos
Alexey-Kukanov
Employee
1,340 Views

I'd suggest to look for some options related to Intel(R) Turbo Boost Technology. Also find some tool to look at CPU temperature - as far as I understand, modern power-saving technologies may automatically drop CPU frequency if it becomes too hot.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,340 Views

Alexey,

It would seem odd that the MS Performance Monitor would count clock ticks during thread runtime, and then use that against the estimated Turbo-Boost speed. But maybe that is what they do. To me, CPU performance is:

The ratio of all threads busy time to all threads idle time.

not

The ratio of all threads at maximum Turbo-Boost time to all threads at idle time.

Though I can see how the two can get goofed up. Note, there used to be a similar issue a while back when Turbo Boost (anti-Turbo down throttle) was introduced. The fix was to use a fixed timer (memory bus clock if I recall). Maybe this quirk came back for that platform/version of Windows.

Jim Dempsey

0 Kudos
Reply