1

I am trying to run a multiple threads program on a 4 core processor, and I want each thread to run on a different core.

How can I do that? Because right now I see that they all running on the same core.

(I'm using Linux OS and my code was wrriten on c.)

2
  • The OS should automatically allocate threads to get the best performance. If more than one thread is doing significant work, then the threads should get scheduled across all available cores, unless told otherwise. Can you determine how much CPU usage the threads cause on each core etc?
    – khabraken
    Commented May 25, 2011 at 15:30
  • Are you sure your program actually has multiple threads? As Spectre said the threads should automatically get allocated to different cores.
    – Mokubai
    Commented May 25, 2011 at 21:30

1 Answer 1

4

Process schedulers make processes have an affinity towards a specific CPU. You've already loaded a bunch of stuff into cache, you may as well keep using this 'hot' cache.

You may be getting all the threads on this same core, since you already have the program loaded here.

I did find this: pthread_setaffinity_np. It seems clumsy, but i hope it's of some use.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.