From: Luciano Miguel Ferreira Rocha <email@hidden>
Date: Wed, 21 Dec 2005 01:04:32 +0000
Delivered-to: email@hidden
Delivered-to: email@hidden
Mail-followup-to: Luciano Miguel Ferreira Rocha <email@hidden>, Mac OS X unix Porting <email@hidden>
User-agent: Mutt/1.4.1i
On Tue, Dec 20, 2005 at 07:25:31PM -0500, Ivan S. Kourtev wrote:
> Thanks, Terry. That's all very good advice and I'll take it into
> consideration.
>
> So now my code knows how to find out that the system it is running on
> has N > 1 processors. Say, for example, it is running on a system
> with N = 2 processors so it wants to use a two-thread version of some
> heavily computational routine. This is only going to be efficient if
> the two threads actually use different physical processes.
>
> So here a few interesting questions arise:
>
> 1. Is there any way to specify that threads run on physically
> different processors/cores? I know the OS is supposed to be smart
> but maybe not that smart because the thread-creating code isn't aware
> of the context of the program being computed.
>
> 2. Particularly if the answer to the above question is YES, is it
> guaranteed that a thread will spend its entire life within the
> physical processor it first started on? I am not terribly familiar
> with the low-level stuff but, when a thread has exhausted its time
> slice, could it be scheduled on a different physical processor the
> next time around?
>
> 3. Depending on what the answers of 1. and 2. are, it seems to be it
> would be useful to have a mechanism for "locking" a thread to a
> processor? Sort of to make the maximum use of the available
> hardware? Particularly in the case when a process wants to start M
> threads where M <= N available processors.
>
> I don't think my specific situations are very complicated but am
> trying to use the opportunity to teach myself a programming style
> which is certainly very new to me. My situations involve mostly high-
> complexity matrix and graph computations that can be partitioned and
> parallelized easily. Nothing extra fancy (like data-races, and the
> necessity for communication, locking, etc.). It's pretty safe to say
> that the N parallel threads can proceed full speed ahead -- depending
> on what hardware is available -- I basically need a lot of
> computational cycles available.
>
> Finally, I am particularly interested in knowing the answers for Mac
> OS X, but it would be lovely to know what the POSIX ways (if any) are
> of doing these things.
>
On Linux, sched_setaffinity (and pthread_attr_setaffinity_np for NTPL
threads), but it's not POSIX.
On some systems, you don't even have an 1:1 mapping (ie., several
threads run only under a single process and will only use a single
processor even if more are available).
I'm not sure about OS X.
BTW, I think you'd be interested in Cell and other vector processing
(Altivec, SSE*).
--
lfr
0/0
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/email@hidden
This email sent to email@hidden