Touch Dreams

More on Concurrency vs Parallelism

Sunday Dec 21, 2008

A reader asked why concurrency programming is not a super-set of parallel programming since the parallel entities are also concurrent. Well, it is just like black-white vs color photography. Though black and white are two colors, the techniques in taking good black-white pictures are different from those for color pictures. One need to think and see differently in terms of contrast, texture, lighting and even composition.

Now back to our programming world. Recently while I was working on the OpenMP profiling, I fixed a concurrency bug that was related to asynchronous signals and had nothing to do with parallelism. I used a data structure to store the OpenMP context of a thread. Since an OpenMP context can be described in a tuple <current parallel region, current task region, OpenMP state, user callstack>, the data structure has several 64-bit long fields. One challenge is to update the context data structure atomically, i.e. when my program needs to report the OpenMP context, it should report a consistent context. For example, it should not report a thread is in a new parallel region but is still in an old task region. The atomicity here has nothing to do with parallelism here - the context data is thread private, so there is no sharing between different threads and there is no data race. The atomicity issue happens when a profiling signal (SIGPROF) comes while the program is in the middle of updating the fields of the context data structure. At the signal handler, the program needs to report the context and need to report them consistently. In the end, I had to crafted a way to update all the fields atomically (asynchronously safe) without masking out the SIGPROF.

Here is another interesting discussion on concurrency vs parallelism. I checked the manual. The exact wording used is "The maximum number of active threads per multiprocessor is 768".

[2] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

[Trackback] 说实话在翻译POSA的时候,我不想用这两个词:并发、并行,而宁愿保留原文。但是对于一本讲分布式计算的书,如果我如此固执,里面会多出大量的英文——虽然现在已经是很多了。实际上,我在译文中也做了灵活的处理...

Posted by 勇敢的鸵鸟 on January 30, 2009 at 06:51 AM PST #

Thanks for your information, i have read it, very good!

Posted by tiffany & co Bracelet on November 12, 2009 at 10:44 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed