ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I am using SuSE Linux on a SGI Altix 3700 and am having trouble with my C multi-threaded program.
I am attempting to assign each thread to a different CPU. I have been successful in using cpuset_pin() to assign a cpu to the current process, but not an individual thread. i have looked into using an 'affinity mask' but have had no luck. Any help or comments are appreciated!
Thank you Jim, Unfortunately I am using pthread_create() and not fork(). I think that might be where I am having problems integrating those techniques. Any other suggestions?
I'm no expert on processor allocation in pthreads, and this might be a dead end, but David R. Butenhof's book Programming with POSIX Threads mentions the pthread_attr_setscope call to set a thread's contention scope attribute. David says:
Quote:
Pthreads provides the thread scope attribute so that you can specify whether each thread you create should have process or system contention scope. Pthreads systems may choose to support PTHREAD_SCOPE_PROCESS, PTHREAD_SCOPE_SYSTEM, or both. If you try to create a thread with a scope that is not supported by the system, pthread_attr_setscope will return ENOTSUP.
The second control is allocation domain. An allocation domain is the set of processors within the system for which threads may compete. A system may have one or more allocation domains, each containing one or more processors. ... On a multiprocessor, each allocation domain may contain from one processor to the number of processors in the system.
There is no Pthreads interface to set a thread's allocation domain. The POSIX.14 (Multiprocessor Profile) working group considered proposing standard interfaces, but the effort was halted by the prospect of dealing with the wide range of hardware architectures and existing software interfaces. Despite the lack of a standard, any system supporting multiprocessors will have interfaces to affect the allocation domain of a thread.
So the yellow brick road ahead of you is a long, long yellow brick road.
Thanks, you have confirmed some of my previous suspicions. I have used the system's own commands to control the allocation domain of the cpus and have toyed with the scope settings. I think I will have to go another avenue (or brick road).
I have looked into OpenMP as a solution....comments?
You've probably already read the OpenMP FAQ, but if you haven't, it seems that you can use OpenMP or pthreads, but not in the same program. If you're willing to make the switch to OpenMP, it looks promising.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.