0

I am trying to run my program in more than one core. I have 12 cores in my desktop and want the computer to use 1,2,3,4,......,11,12 one by one and want to test how the program performs in different number of cores. I tried using -t4 or -t 4 after the executable like.

./a.out -t4 

but I cannot make sure whether its using exactly 4 or not. Can anyone please help me out understand this or point me in right direction.

pokche
  • 1,141
  • 12
  • 36
  • you want to set core affinity? http://stackoverflow.com/questions/8486314/setting-processor-affinity-with-c-that-will-run-on-linux and http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html – thang Feb 01 '13 at 00:35
  • thank you thang for the link .. you see I am using threads and want those threads to use cores from 1 - 12. I heard that we can do that using command line in linux like -t4 for four cores .. – pokche Feb 01 '13 at 00:52
  • you can't really absolutely control which core you're running on, but inside your program when you're creating the threads, you can set the affinity for specific core (i think the api is sched_setaffinity). i think this is something that needs to be done in your code, not at the command line. your code can take a command input to control the # of threads/cores. – thang Feb 01 '13 at 00:54
  • Thank you much*100 thang .. for pointing me to right direction :) – pokche Feb 01 '13 at 01:49

2 Answers2

3

Your program has to be multi-threaded to use several cores of your machines.

This means that the actual code of the program has to be aware of threads and use them efficiently.

You cannot simply ask a program to run on a given number of threads.

You have to use a thread library such as pthread to spawn threads and distribute work over them.

Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • *You cannot simply ask a program to run on a given number of threads.* ah, not yet anyway! – thang Feb 01 '13 at 00:36
  • I am currently using a multi- threaded program .. I uses huge number of threads .. So I wanted to test with all cores to find how many number of cores is best .. – pokche Feb 01 '13 at 00:49
  • Do you use a threadpool ? Then you can configure the number of threads of the threadpool via the given parameter. – Intrepidd Feb 01 '13 at 08:44
0

You should check out the libnuma library.

You can either set which cores you want different threads to run on programmatically or by running it with a command line option. Here's a link to some detailed documentation: http://www.halobates.de/numaapi3.pdf

jmf
  • 1