C++

Multicore programming with different multi-threading approaches

A few days ago I visited a multicore developers conference in Munich where Dr. Mario Deilmann from Intel held his keynote speech regarding the different multi-threading approaches like Winthreads, POSIX threads, OpenMP, Intel TBB and task oriented concepts. His first conclusion must really be taken into account when you talk about parallel programming: Don't think in threads but in tasks as thread-oriented multi-threading is hard to learn, doesn't scale properly and causes a lot of trouble!

n-bodies: a parallel TBB solution: parallel code: balanced recursive parallelism with parallel_invoke

Last time, after struggling with different lock configurations to reduce synchronization overhead managing the interactions of n-squared bodies, I changed perspectives on the problem by spatially representing the interactions between all the bodies and (re-)discovering in that view a means to group the interactions so that independent threads could work together without having to worry about locking the data.

n-bodies: a parallel TBB solution: parallel code: a fresh look using recursive parallelism

When last I had a chance to play with this code, I experimented with using multiple locks to enable multiple simultaneous (and disjoint) interactions between pairs of bodies.  It helped but performance still didn’t cross the base line using only one thread.  Overhead in the loop could be reduced by using only one scoped lock instead of two, but it would require an array of locks indexed by i, and j.

n-bodies: a parallel TBB solution: parallel code: spreading the “fix” around

Last time I was able to make the n-bodies acceleration code at least thread safe by employing a scoped lock, at a disastrous cost in performance.  If you think about it, it’s a bad way to manage the eight HW threads my test machine has available.  The obvious alternative is to have a lock per body-any thread needing to adjust a pair of bodies would need to acquire each body’s lock before proceeding.  That’s more locking overhead than before-twice as many locks-b

Traversing concurrent_hash_map concurrently

People keep asking how to traverse tbb::concurrent_hash_map concurrently with other operations. But it wouldn’t be worth the blog if there was not any problem. The Reference clearly states that:
Concurrent operations (count, find, insert, and erase) invalidate any existing iterators that point into the table, An exception to this rule is that count and find do not invalidate iterators if no insertions or erasures have occurred after the most recent call to method rehash.

Have we made task_group a little too easy to use?

One of the things that was introduced with the TBB 2.2 release was support for functional parallelism or the high-level task scheduling API, whichever you wish to call it. This was the task_group class which allowed users to spawn tasks, which wrap user functions that could potentially run in parallel, and more functions could be added to the same task group dynamically. The TBB Reference Manual explains task_group using the ubiquitous Fibonacci example. There is another situation where task_group could be a very good fit as well:

Páginas

Suscribirse a C++