views:

563

answers:

4

Hello, I am totally a novice in Multi-Core Programming, but I do know how to program C++.

Now, I am looking around for Multi-Core Programming library. I just want to give it a try, just for fun, and right now, I found 3 APIs, but I am not sure which one should I stick with. Right now, I see Boost's MPI, OpenMP and TBB.

For anyone who have experienced with any of these 3 API (or any other API), could you please tell me the difference between these? Are there any factor to consider, like AMD or Intel architecture?

+1  A: 

I'd suggest you to play with MapReduce for sometime. You can install several virtual machines instances on the same machine, each of which runs a Hadoop instance (Hadoop is a Yahoo! open source implementation of MapReduce). There are a lot of tutorials online for setting up Hadoop.

btw, MPI and OpenMP are not the same thing. OpenMP is for shared memory programming, which generally means, multi-core programming, not parallel programming on several machines.

Yin Zhu
...wait, let me get this right. When we say the term "multi-core programming", we refer to utilizing computer that has more than 1 core, right? Oops, sorry, my bad, my bad, I make a definition mistake in my question.
unknownthreat
Sorry, I am referring to utilizing the multi-core.
unknownthreat
you don't know c++. then what do you know?
Yin Zhu
@Yin Zhu: Sir, you have mistaken. Please reread my post.
unknownthreat
@unknownthreat: There are two types of parallel programming: "multi-core" (usually when people talk about parallel programming this is what they mean) and distributed. The latter means you run the program on multiple *machines*, not just multiple CPU cores on a single machine. @Yin Zhu: The OP was referring to multi-core programming, as the new title suggests, not distributed.
musicfreak
+1  A: 

Depends on your focus. If you are mainly interested in multi threaded programming go with TBB. If you are more interested in process level concurrency then MPI is the way to go.

stonemetal
+5  A: 

Under the hood OpenMP is multi-threaded programming but at a higher level of abstraction than TBB and its ilk. The choice between the two, for parallel programming on a multi-core computer, is approximately the same as the choice between any higher and lower level software within the same domain: there is a trade off between expressivity and controllability.

Intel vs AMD is irrelevant I think.

And your choice ought to depend on what you are trying to achieve; for example, if you want to learn TBB then TBB is definitely the way to go. But if you want to parallelise an existing C++ program in easy steps, then OpenMP is probably a better first choice; TBB will still be around later for you to tackle. I'd probably steer clear of MPI at first unless I was certain that I would be transferring from shared-memory programming (which is mostly what you do on a multi-core) to distributed-memory programming (on clusters or networks). As ever , the technology you choose ought to depend on your requirements.

High Performance Mark
+2  A: 

Hi,

As a starting point I'd suggest OpenMP. With this you can very simply do three basic types of parallelisation: loops, sections, and tasks.

Parallel loops allow you to split loop iterations over multiple threads. So using two threads the first thread would perform the first half of the iteration, the second thread would perform the section half.

#pragma omp parallel for
for (int i=0; i<N; i++) {...}

Sections allow you to statically partition the work over multiple threads. This is useful when there is obvious work that can be performed in parallel. However, it's not a very flexible approach.

#pragma omp parallel sections
{
  #pragma omp section
  {...}
  #pragma omp section
  {...}
}

Tasks are the more flexible approach - these are created dynamically and their execution is performed asynchronously, either by the thread that created them, or by another thread.

#pragma omp task
{...}

OpenMP has several things going for it.

  • Directive based, which means that the compiler does the work of creating and synchronising the threads.

  • Incremental parallelism, meaning that you can focus on just the region of code that you need to parallelise.

  • One source base for serial and parallel code. The OpenMP directives are only recognised by the compiler under compiler flag. So you can use the same source base to generate serial and parallel code. This means that if the parallel code generates a wrong answer you can use the same code base to generate a serial version which you can then use to verify the computation. This means that you can isolate parallelisation errors from errors in the algorithm.

You can find the entire OpenMP spec at http://www.openmp.org/

Regards,

Darryl.

Darryl Gove