write these three lines in ur function, it will bind that particular thread
to (id)th processor wher

void func(int id)
{
        unsigned long mask;
        mask = 1<<id;
        pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask);
}

main()
{
        pthread_t *thread;
        thread = (pthread_t*)malloc(8*sizeof(pthread_t));
        int ret;
        for (i = 0; i < n; i++)  ret = pthread_create(&thread[i], NULL,
(void*(*)(void*))func, (void*)i);
        for (i = 0; i < n; i++)  pthread_join(thread[i], NULL);
        return 0;
}

this fucntion will bind ith thread with ith processor.

u can set the mulitple bits of mask that will allow to run particular
thread only on that set of processor.

suppose mask = 101001;
that will allow to run the that particular thread only on 1st, 4th, 6th
processor. if there is 6 processor(core) on ur system.

u can use the TOP command to see the utilization of every core.
Run any highly compute intesive problem (like matrix multiplication) create
as many threads in as many processor in ur system. and the run the program.
open another terminal type top and u can see the utilization of every core
is about 99 to 100%. ;)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to