views:

172

answers:

3

I am actually on my project on compiler with SMP, and want to code with pthreads and heard about many parallel things open mpi and so on, So to start with how this thread is allocated to core while calling pthread,Is there any way to give threads to different cores by pthreads?

+1  A: 

Check out a pthreads tutorial such as this. But in general I would recommend using a higher level library than pthreads as it will be simpler/more systematic to use them. For example, Boost::Threads or Intel TBB.

Amit Kumar
A: 

The system will assign the threads to available cores, and move them around if there's free resources elsewhere.

The OS usually does a far better job than me in assigning resources, but if you really want to, most OSs have a way of assigning/restricting threads to a particular core/processors. On linux, use sched_setaffinity

nos
A: 

The simplest answer is yes -- in general different threads will likely run on different cores, automatically without having to specify where the threads run.

It seems like you need an intro/primer on multi-threaded programming in general before diving into a specific threading library/way of thinking. Before doing anything else, read the section "What is a thread" from Amit above, then start looking at either the specifics of POSIX threads, Windows threads, TBB, Boost Threads, or any other library/wrapper looks interesting to you.

J Teller