PDA

View Full Version : Multi-Threaded App Question.


Flybye
09-24-2007, 09:49 AM
If an app is Multi-threaded, does that mean it will take advantage of multicores regardless of how many cores are present?

Or would an app designed to work with a dual core not be able to take advantage of more than 2 cores?

Player0
09-24-2007, 01:52 PM
If an app is Multi-threaded, does that mean it will take advantage of multicores regardless of how many cores are present?

Not necessarily but probably. Windows uses preemptive multitasking so it's really up to the scheduler which threads are going where with what priorities. In practice the process and threads will usually go to separate CPUs. It is possible for everything to wind up on the same CPU in non-optimal situations.

(also, one could make a joke about the open endedness of of 'how many cores are present' since 0 or 1 could yield odd answers)

Or would an app designed to work with a dual core not be able to take advantage of more than 2 cores?

It's sometimes questionable whether or not multithreading can be advantageous since it requires more overhead and some programmers just don't do it properly. But more specifically to the point at hand, it greatly depends on the software and how many threads it's spawning. If it only spawns two threads then no. If it spawns 8 threads then yes.

An application may decide that only one thread is necessary even if it could use multiple threads since, again, the overhead may not justify the small performance gain. It also may increase development time or add another point of failure for apps so most people don't get to crazy with it.

You're still running on top of an OS however which eats up at least one of your virtual CPUs. An app with one process and one thread might only need up to two cores. But Windows still counts for a third. So quad processors may serve a purpose even if your typical app only spawns one thread at a time.

Unfortunately, I dont know what a typical app spawns. I just suspect that it's low.

Flybye
09-24-2007, 08:32 PM
Allrighty. Thanks. I had been wondering mostly about games, but I really wasn't sure about windoze app. Then all all simply comes down to how efficiently the app/game was produced.

Player0
09-24-2007, 08:46 PM
In Windows Task Manager, you can go to View->Select Columns and show the number of threads being used by any particular application.

Flybye
09-24-2007, 08:51 PM
Hmm...forgot about that. I could open up the window all the way, play a game, then minimize it, and my history will be there :)

illmatik
09-25-2007, 12:19 AM
Multi-threaded applications can offer tremendous boosts in performance in several situations. Depending on the language (and underlying OS in many cases) used, the level of effort/experience involved to take advantage of muli-core chips in this way can vary (or hurt) rather than relying on raw clock speed to get the job done. Some languages like Erlang [Ericcson-Language which many phone switching and air traffic control systems are written in] are starting to shine due to the increased amount of cores available in a single system and the way applications are developed in multiple concurrent modules rather than one master executable. The language I'm always yapping about Q (which is K & KDB+ from www.kxsystems.com), is an interpreted language/database that was designed to scale and spawn across cores/clusters/networks by simple parameters passed within the argument being executed. Here's a recent comment from its creator when a newb got thrown the task of administering his companys kdb (and for any of you who know databases, it's quite impressive considering each record is a stock tick that comprises several different parameters):

>The answers you seek are there.
> cp is best backup. etc.

jason isn't being flippant. (of course)

he's got a huge and complex database.
several hundred billion rows and
i think up to 2 billion complex transactions per day.
(i.e. the feed handlers alone need to be extremely
efficient.)
all of this on one 4-way machine!

Still though, the CPUs available to us today are quite easily some of the most powerful machines available to us. This month's Linux Journal reviews 7 servers @ 7k, and even though Sun's new CoolThreads architecture (8 cores 64 threads) still can't beat out an HP dual Xeon box in raw performance for common scalable optimizations (it's quite possible that platform specific development thinking in 64 bits and 64 threads might make it cruise, but time and money you'd need to pay a developer to do it could probably buy you a whole rack full of Xeon boxen to just brute force it with easily understandable code ;)