Multi-Threading


centus

Member
Joined
Oct 6, 2008
Messages
211
Location
Suzhou, China
Hello,

In my quest to optimize the performance of my fractal generator, I've come to think about multi-threading.
Someone here mentioned the fact that the Cortex A8 is good at multi-threading, is that true?
Should I expect a serious increase in performance?

If so, writing code in C how would I go about creating threads in Pandora? just include thread.h and use it?
I'm compiling on an Intel processor for now (going to port it to the Pandora when I actually get it), would making it multi-threaded on an Intel be a trivial port to Pandora or are there differences?

Thanks!
 
centus said:
Hello,

In my quest to optimize the performance of my fractal generator, I've come to think about multi-threading.
Someone here mentioned the fact that the Cortex A8 is good at multi-threading, is that true?
Should I expect a serious increase in performance?

If so, writing code in C how would I go about creating threads in Pandora? just include thread.h and use it?
I'm compiling on an Intel processor for now (going to port it to the Pandora when I actually get it), would making it multi-threaded on an Intel be a trivial port to Pandora or are there differences?

Thanks!

Pandora is using the Cortex-A8 processor which a single core so mult-threading most likely wont have much of a impact as you expect. Now this would change for the A9 which will be dual core, which is maybe what you heard about.
the pthreads lib should do what you want.
it really comes down to your code and how its structured, can one thread do something while another is doing nothing
 
Last edited by a moderator:
You might get a small performance increase from 2 threads, even on a single physical core, because of pipelining or I/O wait or something. With a long-running process like fractal rendering, it should be easy to test.

What to use for threading:
Whatever your library / toolkit provides.
GTK+ and Qt have them built-in.
SDL has them built-in, which is how I multithreaded my fractal renderer.
If all else fails, Linux has POSIX threads (pthread, as Pickle said) built-in, so import that header and link to whatever library it uses.

Google research will be required in any case.
 
You don't get improvements by threading unless there are multiple cores, the core(s) implement(s) symmetric multithreading (ie hyperthreading) or there is work you can be done while blocking against external I/O. The first two things don't apply to Cortex-A8 and the last one probably doesn't apply to your fractal generator. Without these things, splitting up a task across multiple threads will probably make it slower instead of faster.
 
On single core it's usually for -perceived- speed, not real speed :) (ui scheduling etc) .. Probably easy for you to test but with heavy crunch you'll just slow down

jeffphone
 
Thanks for all the input, so if I understand correctly, the most benefit I can get from threading would probably be in separating the event loop from the drawing loop, that way I can still respond to user events during drawing (i.e. zoom in while drawing and such).

Thanks again.
 
Sure; bearing in mind that ..

From the UI thread perspective, assuming the crunch thread is on full speed, you'll be sluggish to respond to events (and if you want to handle zoom etc, you need to define a way to tell the crunch thread to start its business over) .. unless you're telling the crunch thread to relax a bit, in which case, major slowdown :)

But it might work out nicely, too, a nice user experience.

Doing it the old way -- show a 'hourglass' or progress bar while crunch, and a cancel button so the user can grab control and then do zooms etc works fine, but might be too clunky. *shrug*

On the other hand, it can really work well .. I've done lots of experimentation with loading artwork in a background thread while the main app goes about its business; consider a picture viewer with sliding window, so can pre-load and pre-scale thumbnails before the user moves over to see them, etc. Or in the case of a sgtreaming audio player, go fetching audio thumbnails and samples and connection info in background, while the player has another background audio thread, while the player has a foreground UI thread.

But dont' push too much going on.. it is single core after all, so you're just going to make everythign chuggy, pretty easily :)

jeff
 
Back
Top