Multi-threading on Multi-CPU machines

Steven sadams123 at optushome.com.au
Mon Jul 8 12:27:17 EDT 2002


"Garry Taylor" <gtaylor at lowebroadway.com> wrote in message
news:f0fd5987.0207080702.407100ec at posting.google.com...
> Hello,
> I am attempting to make a multi-threading function in one of my
> programs in an effort to gain a speed increase, but I'm getting quite
> the opposite, even on a dual-CPU Intel/Linux box. Can anyone enlighten
> me as to why, my code is below:
.....
>
> This does the same thing, threaded and then not, but on all of my
> machinbes, the multi-threaded is slower, what can I do about this?

does the Python interpreter run on both CPU's? that is, do you have the
Python threads executing concurrently on both CPU's, I'd imagine that they
would be, but just wondering...

I tested on my machine, which is a single AthlonXP 1900, and get times of
about 3.6 and 3.4 for the Threader and NoThreader versiosn respectively, and
I'd attribute a fair bit to the creation time for a thread, though I don't
have any real timing to back that up. I did change it slightly so that the
function passed did no work, so it was basically just the overhead of
setting up and finishing a thread, and the threaded version took much longer
than the non-threaded (as you'd expect on a single CPU machine).

As it is, although you can have a CPU running each tasks, you still do very
frequent checking of variables that are global to the whole thing, so that
constant checking of the THreadCounter is going to introduce an overhead
that isn't present on the non-threaded, as is the increment operation in
each thread, the non-threaded version doesn't have the overhead of changing
the variable on whatever CPU its sitting.

If there were a method running half the threads on one CPU, and half on the
other, and not communicating with that 'parent' until the very very end,
when all of each thread-spawners threads had completed, then you might see a
performance increase.

I'm sure someone with a better knowledge of threading on Python can give you
a better answer...

Steven





More information about the Python-list mailing list