LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2007, 04:23 PM   #1
311_linux
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Rep: Reputation: 0
Pthread - Multiple CPU assignment


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!

- chris
 
Old 03-22-2007, 11:59 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
example code here:
http://www-128.ibm.com/developerwork...-affinity.html
 
Old 03-23-2007, 03:44 PM   #3
311_linux
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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?
 
Old 03-23-2007, 08:08 PM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.

Hope this helps in some minor way.
 
Old 03-24-2007, 10:35 AM   #5
311_linux
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wjevans_7d1@yahoo.co
Hope this helps in some minor way.
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?

All thanks in advance!
 
Old 03-24-2007, 12:26 PM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.

Good luck.
 
Old 03-25-2007, 10:10 AM   #7
311_linux
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks, OpenMP seems much easier and very promising! I just need to get it install on the machine I am working with now. I have looked into GOMP.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
libtest.a uses pthread: user of libtest.a should not link pthread again debulu Programming 2 01-31-2007 09:23 PM
Multiple Boxes to Combine CPU-Power wwnexc Linux - Networking 6 01-24-2006 10:36 AM
how do I force a pthread to give up the cpu? [c++, linux] dougtheslug Programming 3 12-06-2005 04:39 PM
CPU Spikes with Multiple Programs / "Choppy" Behavior sk505 Linux - Software 1 08-04-2005 11:18 PM
Switching off a CPU of a multiple CPU machine kravisudhakar Linux - General 1 12-26-2003 10:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration