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

Why is TBB this Hard?

jobin007007
Beginner
569 Views
I am a fairly seasoned programmer but not an expert. I find TBB to be very hard and trying to understand has been taking a lot of time. I am wondering if its worth using it because of its complexity. Some of the concepts are easier than other but overall it is hard to implement.
Tools like .NET etc make programming easier. TBB seem to be going in the opposite direction?
Do you may disagree. Any comments?
0 Kudos
9 Replies
robert_jay_gould
Beginner
569 Views
Quoting - jobin007007
I am a fairly seasoned programmer but not an expert. I find TBB to be very hard and trying to understand has been taking a lot of time. I am wondering if its worth using it because of its complexity. Some of the concepts are easier than other but overall it is hard to implement.
Tools like .NET etc make programming easier. TBB seem to be going in the opposite direction?
Do you may disagree. Any comments?

I disagree, TBB's API is no harder than the STL or Boost libraries. It's about as trivial as Modern Templated C++ Generic Programming can be (however, I'll accept C++'s Generic Programming is not inherently trivial at all).

Unfortunately I think you are asking an apple to be an orange. If TBB was a compiler and runtime like CILK, then you could compare it with .NET, but its across-platformstandard C++ conforming library, with no precompilingor special runtimes, just like an STL or Boost library.

Now on a side note, I find cumbersome having to write my function objects outside of my call spots, but that's C++'s fault, same happens if you want a custom sort algorithm in STL. But the issue is fixed with Lambdas (if your compiler supports Lambda's, GCC will support it some day, maybe).

0 Kudos
Alexey-Kukanov
Employee
569 Views
Quoting - jobin007007
I find TBB to be very hard and trying to understand has been taking a lot of time. I am wondering if its worth using it because of its complexity. Some of the concepts are easier than other but overall it is hard to implement.

Would you mind telling us what exactly you found hard and taking a lot of time?
Maybe you started to learn TBB from a hard side (such as direct use of tasks).
0 Kudos
in4tunio
Beginner
569 Views
Quoting - jobin007007
I am a fairly seasoned programmer but not an expert. I find TBB to be very hard and trying to understand has been taking a lot of time. I am wondering if its worth using it because of its complexity. Some of the concepts are easier than other but overall it is hard to implement.
Tools like .NET etc make programming easier. TBB seem to be going in the opposite direction?
Do you may disagree. Any comments?

I find it strange that you say this. Probably the C++ language is complex, and correct parallel programming too is. But I find TBB simpler than other options in C++ (like directly using pthreads). TBB quite systematically handles many issues: scaling on to variable number of processors in the future, cache affinity, correct synchronization, etc without losing efficiency.
0 Kudos
jobin007007
Beginner
569 Views

Well, i probably find it hard because Im an engineer not a programmer. I need the program to work for me easily..not me working to make the program work. I bought the book by james reinder. paralle_for wasnt bad after spending a couple of hours. then i went to the next part and it just got complex and i couldnt understand the concepts. From what research I did and reading other posts, I agree that paralled programming isnt easier in C++ if you want to do a good job. My case is that, why doesnt somebody make it easier.

for example..why not make something like this to implement paralle_for.

parallel_for(int s=0;s<10000;s++,grainsize)
{
Do parallel thing here.

}

Its good to understand whats going on in the background..but unless youre like an advanced programmer, i see no need to understand whats going on in the background. If you want to you can read about it.

Is it possible to implement something like this instead of creating the operator() function etc.?

0 Kudos
RafSchietekat
Valued Contributor III
569 Views
TBB is intended to run on standard C++ (a great advantage!), which unfortunately rules out most forms of syntax "sugar". Some of them are available by combining TBB with OpenMP (just write the serial form and add some #pragma's), which should work well for loops and stuff (or so I've been told), so you might decide to go that way (see thread "OMP vs TBB"). Some (lambda support!) will become available when the new C++ standard arrives to your development environment, but I wouldn't start holding my breath just yet. Intel also has a project that builds on top of TBB, but I don't know any details.

Meanwhile, there's a lot more to exploiting parallelism well than just taking the syntax hurdle, so don't worry about it too much, try to adapt example code instead of internalising the specifications, and just communicate how the documentation could be tuned tofacilitate the transition.

0 Kudos
pvonkaenel
New Contributor III
569 Views
Quoting - jobin007007

Well, i probably find it hard because Im an engineer not a programmer. I need the program to work for me easily..not me working to make the program work. I bought the book by james reinder. paralle_for wasnt bad after spending a couple of hours. then i went to the next part and it just got complex and i couldnt understand the concepts. From what research I did and reading other posts, I agree that paralled programming isnt easier in C++ if you want to do a good job. My case is that, why doesnt somebody make it easier.

for example..why not make something like this to implement paralle_for.

parallel_for(int s=0;s<10000;s++,grainsize)
{
Do parallel thing here.

}

Its good to understand whats going on in the background..but unless youre like an advanced programmer, i see no need to understand whats going on in the background. If you want to you can read about it.

Is it possible to implement something like this instead of creating the operator() function etc.?


Based on the format of your desired example, you might want want to take a look at OpenMP. Note that OpenMP is built into the compiler, so you will need to have a compiler that supports it - such as VS2008 orIntel C++. A simple example may look like the following:

#pragma omp parallel for
for (int s = 0; s < 10000; s++)
{
do parallel work here
}

0 Kudos
jobin007007
Beginner
569 Views
Quoting - pvonkaenel

Based on the format of your desired example, you might want want to take a look at OpenMP. Note that OpenMP is built into the compiler, so you will need to have a compiler that supports it - such as VS2008 orIntel C++. A simple example may look like the following:

#pragma omp parallel for
for (int s = 0; s < 10000; s++)
{
do parallel work here
}


Why didnt TBB use syntax like OpenMP then? Is TBB better? Somebody should do BenchMarks!
I am using Visual Studio 2008. I didnt know that OpenMp was build into it. Thanks

0 Kudos
robert_jay_gould
Beginner
569 Views
Quoting - jobin007007

Why didnt TBB use syntax like OpenMP then? Is TBB better? Somebody should do BenchMarks!
I am using Visual Studio 2008. I didnt know that OpenMp was build into it. Thanks


The reason TBB didn't use the syntax of OMP is because OMP isn't standard C or C++, its a custom language extension. TBB is pure C++, no custom extensions required.

TBB among tons of other things provides thread-safe containers, the pipeline pattern, and platform independent threads, mutexes (locks), and atomics. It also has a scheduler that is smarter than OpenMP's, so it can squeeze out more performance in certain scenarios.

Also TBB is more extensible than OMP, so you can develop complex concurrent processing patterns with TBB, but you're almost stuck entirely with parallelizing loops using OMP.

Finally another small perk I can think about is TBB gets some extra performance for free from the C++ compiler, that you'd have to manually sqeeze out using OMP.

Overall OMP is much easier than TBB, but TBB gives you much more power. However considering your background as someone just coming into the concurrency field, OMP might be a better choice for you right now. But after you get your feet wet, and begin to grok concurrency you'll probably find TBB a much better solution to concurrency than OMP.
0 Kudos
jobin007007
Beginner
569 Views

The reason TBB didn't use the syntax of OMP is because OMP isn't standard C or C++, its a custom language extension. TBB is pure C++, no custom extensions required.

TBB among tons of other things provides thread-safe containers, the pipeline pattern, and platform independent threads, mutexes (locks), and atomics. It also has a scheduler that is smarter than OpenMP's, so it can squeeze out more performance in certain scenarios.

Also TBB is more extensible than OMP, so you can develop complex concurrent processing patterns with TBB, but you're almost stuck entirely with parallelizing loops using OMP.

Finally another small perk I can think about is TBB gets some extra performance for free from the C++ compiler, that you'd have to manually sqeeze out using OMP.

Overall OMP is much easier than TBB, but TBB gives you much more power. However considering your background as someone just coming into the concurrency field, OMP might be a better choice for you right now. But after you get your feet wet, and begin to grok concurrency you'll probably find TBB a much better solution to concurrency than OMP.

Thanks.
0 Kudos
Reply