Multi-processor

Hi. I’m starting to look into multi-processor technologies (both hardware and software).

I already have the software running in a one-processor PC using SDL.

Is multi-threading the way to go?

Thanks,

Carlos

Is multi-threading the way to go?

If you want to use multiple CPUs, it’s the only way to go.

You have to decide if this is worth the added complexity to your code;
in many cases, it is not. Doubly so when you consider that in this day,
lots of people still don’t have multiple CPUs. Hyperthreading and all
this talk about Dual Cores will change that in the near future, though.

–ryan.

Thanks, Ryan.

Yes, I’ll have to use multiple CPUs. It’s a research project, with lots of image processing power required. I’ll probably be using a four processor array.

One more question. I don’t see in the SDL API any function to connect a thread to a specific processor.

Is that done automatically…?

Carlos----- Original Message -----
From: Ryan C. Gordon
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Tuesday, August 31, 2004 11:15 AM
Subject: Re: [SDL] Multi-processor

Is multi-threading the way to go?

If you want to use multiple CPUs, it’s the only way to go.

You have to decide if this is worth the added complexity to your code;
in many cases, it is not. Doubly so when you consider that in this day,
lots of people still don’t have multiple CPUs. Hyperthreading and all
this talk about Dual Cores will change that in the near future, though.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

One more question. I don’t see in the SDL API any function to connect
a thread to a specific processor.

Is that done automatically…?

All OSes that support multiple CPUs will put threads onto the least
loaded processor so that the work load is distributed. They will switch
them to new CPUs if needed (i.e. - two threads suddenly demand a lot of
CPU time on the same processor while another physical CPU is sitting
idle), but generally try not to, so that the CPU caches aren’t wasted.
It’s complicated to squeeze all the performance out of this that is
possible, but most OSes are smart about this behind the scenes.

This is true for Linux, Windows, FreeBSD, and MacOSX…I’m sure others,
like Solaris, do something similar.

Note that some OSes (Linux, BeOS, maybe others) can let you dictate what
thread goes to what physical CPU, and lets you command it to never
migrate between CPUs no matter what (they call this “processor
affinity”), but you can’t do that via SDL, and generally, you shouldn’t
do that anyhow…let the OS do the right thing for you. If you must
have this, you can skip SDL’s threads and use the system calls directly,
but I’d recommend against this. If you use syscalls, you can’t
(portably) use SDL_CreateThread and the mutex functions, etc (but the
rest of SDL is still available to you).

–ryan.

Carlos Vrancken wrote:

Thanks, Ryan.

Yes, I’ll have to use multiple CPUs. It’s a research project, with
lots of image processing power required. I’ll probably be using a four
processor array.

One more question. I don’t see in the SDL API any function to connect
a thread to a specific processor.

Is that done automatically…?

Isn’t it done by the underlying OS ?

Julien

One more question: the linux kernel 2.6 introduced an improved threading
model. Should I used the Native POSIX Thread Library (NPTL) in order to take
advantage of that?

Thanks!

C.> ----- Original Message -----

From: jpauty@irisa.fr (Julien Pauty)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Tuesday, August 31, 2004 11:55 AM
Subject: Re: [SDL] Multi-processor

Carlos Vrancken wrote:

Thanks, Ryan.

Yes, I’ll have to use multiple CPUs. It’s a research project, with
lots of image processing power required. I’ll probably be using a four
processor array.

One more question. I don’t see in the SDL API any function to connect
a thread to a specific processor.

Is that done automatically…?

Isn’t it done by the underlying OS ?

Julien


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

One more question: the linux kernel 2.6 introduced an improved threading
model. Should I used the Native POSIX Thread Library (NPTL) in order to take
advantage of that?

Thanks!

C.

That may have better support and power, but you’ll lose
cross-platform code. Probably better to stay within SDL, but heck, what
do I know ;)On Wed, 01 Sep 2004 15:47:25 -0500, Carlos Vrancken wrote:

Carlos Vrancken wrote:

One more question: the linux kernel 2.6 introduced an improved threading
model. Should I used the Native POSIX Thread Library (NPTL) in order to take
advantage of that?

If you just want to create multiple computation threads to balance the
computation among multiple CPUs, standard linux pthreads are fine. NPTL
only provides more functionality and a better scaling (we’re talking
about lots of threads here, not just one per cpu).

So in short, using SDL threads (which map onto the linux pthreads under
linux) is sufficient for what you want to do. If you’re new to threaded
programming, there are a lot of other things to learn instead of wasting
your time learning a new threading API (concurrent programming has a lot
more challenges than sequential programming, and these are way harder to
debug).

One case where using threading isn’t sufficient is when the code runs
across nodes in a cluster. That requires message-oriented programming
(with APIs like MPI, PVM or even raw sockets) and is quite diffenrent
from threaded programming. Thus think before you start coding, since MPI
programs can take advantage of one multi-cpu machine, while threaded
programs can’t run as-is on a cluster.

Stephane