3

I am developing time-demanding simulations in C++ targeting Intel x86_64 machines. After researching a little, I found two interesting libraries to enable parallelization:

As stated in docs, they both target parallelism on multicore processors but still haven't figured which one is the best. AFAIK Cilkplus simply implements three keywords for an easier parallelism (which causes GCC to be recompiled to support these keywords); while TBB is just a library to promote a better parallel development.

Which one would you recommend?

Consider that I am having many many many problems installing CilkPlus (still trying and still screaming). So I was wondering, should I go check TBB first? Is Cilkplus better than TBB? What would you recommend?

Are they compatible?

Should I accomplish installing CilkPlus (still praying for this), would it be possible to use TBB together with it? Can they work together? Is there anyone who did experience sw develpment with both CiclkPlus and TBB? Would you recommend working with them together?

Thankyou

Community
  • 1
  • 1
Andry
  • 16,172
  • 27
  • 138
  • 246
  • 3
    I have used `TBB` before and I'm happy with it. It has good docs and the forum is active. It's not rare to see the library developers answering the questions. Give it a try. (I never used `cilkplus` so I can't talk about it) – Adri C.S. Oct 08 '13 at 08:10
  • @AdriC.S.: Hello again :) Well ok, what about installation? Did you have problems? Was it smooth or, at least, didn't take 3 days... – Andry Oct 08 '13 at 08:12
  • 1
    I worked with it both in `Ubuntu` and Windows. You can download the packages via the package manager in Ubuntu or you can build the sources yourself. In that case, it shouldn't be a problem. In Windows I built `TBB` with the `cygwin` environment. – Adri C.S. Oct 08 '13 at 08:20
  • Well, to be precise I built `TBB` with `MinGW`. – Adri C.S. Oct 08 '13 at 08:32
  • So @Andry, how did `TBB` behave? – Adri C.S. Oct 08 '13 at 14:05
  • Oh yeah, just downloaded the lib... a bit surprised they do not provide an installer... I mean a script placing stuff in lib and include dirs in the system, but managed to build a simple example and make it work. I just threw away Cilk and now I am going for TBB. Thanks btw. – Andry Oct 08 '13 at 14:12
  • @AdriC.S. Post your comments as an answer, after all you helped me moving on and things went almost smoothly... – Andry Oct 08 '13 at 14:13
  • This link also could help: [Intel TBB and Cilk+ compare](https://www.threadingbuildingblocks.org/compare) – wbk Dec 16 '13 at 21:34

5 Answers5

5

Here are some FAQ type of information to the question in the original post.

Cilk Plus vs. TBB vs. Intel OpenMP

In short it depends what type of parallelization you are trying to implement and how your application is coded.

Eugene Roeder
  • 219
  • 2
  • 7
3

I can answer this question in context to TBB. The pros of using TBB are:

  • No compiler support needed to run the code.
  • Generic C++ algorithms of TBB lets user create their own objects and map them to thread as task.
  • User doesn't need to worry about thread management. The built in task scheduler automatically detects the number of possible hardware threads. However user can chose to fix the number of threads for performance studies.
  • Flow graphs for creating tasks that respect dependencies easily lets user exploit functional as well as data parallelism.
  • TBB is naturally scalable obviating the need for code modification when migrating to larger systems.
  • Active forum and documentation being continually updated.
  • with intel compilers, latest version of tbb performs really well.

The cons can be

  • Low user base in the open source community making it difficult to find examples

  • examples in documentations are very basic and in older versions they are even wrong. However the Intel forum is always ready to extend support to resolve issues.

  • the abstraction in the template classes are very high making the learning curve very steep.

  • the overhead of creating tasks is high. User has to make sure that the problem size is large enough for the partitioner to create tasks of optimal grain size.

    I have not worked with cilk either, but it's apparent that if at all there are users in the two domain, the majority is that of TBB. It's likely if Intel pushes for TBB by it's updated document and free support, the user community in TBB grows

Community
  • 1
  • 1
ggulgulia
  • 2,720
  • 21
  • 31
  • Is there any evidence where TBB runs poorly on any other processor? It's open-source, go and find how it does so. I bet you'll find nothing – Anton Sep 01 '17 at 15:42
  • 1
    no evidence but it's from my experience using TBB with AMD processor. I admit I may be wrong about TBB being slower on other processors as I realized the SIMD support in the particular processor of AMD I have in my system is particularly very poor.. I am removing my last point – ggulgulia Sep 08 '17 at 07:55
2

They can be used in complement to each other (CILK and TBB). Usually, thats the best. But from my experience you will use TBB the most. TBB and CILK will scale automatically with the number of cores. (by creating a tree of tasks, and then using recursion at run-time).

  • TBB is a runtime library for C++, that uses programmer defined Task Patterns, instead of threads. TBB will decide - at run-time - on the optimal number of threads, tasks granularity and performance oriented scheduling (Automatic load balancing through tasks stealing, Cache efficiency and memory reusing). Create tasks recursively (for a tree this is logarithmic in number of tasks).

  • CILK(plus) is a C/C++ language extension requires compiler support. Code may not be portable to different compilers and operating systems. It supports fork-join parallelism. Also, it is extremely easy to parallelize recursive algorithms. Lastly, it has a few tools (spawn, sync), with which you can parallelize a code very easily. (not a lot of rewrite is needed!).


Other differences, that might be interesting:
a) CILK's random work stealing schedule for countering "waiting" processes.
a) TBB steals from the most heavily loaded process.

Snowman
  • 1,503
  • 1
  • 17
  • 39
  • 1
    Whar do you mean cilk does no scale? It perfectly does – Anton Oct 27 '15 at 18:28
  • I changed it. I have not used CILK, that much, mainly learnt about it, and that's what my prof said back then. So If you say it scales, I believe you. – Snowman Oct 28 '15 at 17:46
1

Is there a reason you can't use the pre-built GCC binaries we make available at https://www.cilkplus.org/download#gcc-development-branch ? It's built from the cilkplus_4-8_branch, and should be reasonably current.

Which solution you choose is up to you. Cilk provides a very natural way to express recursive algorithms, and its child-stealing scheduler can be very cache friendly if you use cache-oblivious algorithms. If you have questions about Cilk Plus, you'll get the best response to them in the Intel Cilk Plus forum at http://software.intel.com/en-us/forums/intel-cilk-plus/.

Cilk Plus and TBB are aware of each other, so they should play well together if you mix them. Instead of getting a combinatorial explosion of threads you'll get at most the number of threads in the TBB thread pool plus the number of Cilk worker threads. Which usually means you'll get 2P threads (where P is the number of cores) unless you change the defaults with library calls or environment variables. You can use the vectorization features of Cilk Plus with either threading library.

- Barry Tannenbaum
  Intel Cilk Plus developer
Adam
  • 16,808
  • 7
  • 52
  • 98
0

So, as a request from the OP:

I have used TBB before and I'm happy with it. It has good docs and the forum is active. It's not rare to see the library developers answering the questions. Give it a try. (I never used cilkplus so I can't talk about it).

I worked with it both in Ubuntu and Windows. You can download the packages via the package manager in Ubuntu or you can build the sources yourself. In that case, it shouldn't be a problem. In Windows I built TBB with MinGW under the cygwin environment.

As for the compatibility issues, there shouldn't be none. TBB works fine with Boost.Thread or OpenMP, for example; it was designed so it could be mixed with other threading solutions.

Adri C.S.
  • 2,909
  • 5
  • 36
  • 63