Hi,
I am using Python Thread library for my parallel processing course
project. I am doing matrix convolution on a multi-processor machine
running Solaris. I just found out that no speed-up is obtained with
threading. It is probably because of something called GIL in Python.
How can I get around
that GIL and get speed-up?
Threading in Python is optimized for I/O bound processing, wherein
the threads spend most of their lives sleeping (blocked waiting for some
I/O to complete, or some lock/event/condition to change state). It is
not optimized for parallel number crunching.
Options:
Don't use the common "CPython" (eg, the Python built from C-language
source using the C-runtime library). Jython (a version that runs on the
JVM, using Java libraries) may not be afflicted with the GIL.
I don't recall if "Stackless" has the GIL...
Convert the deep math operations (ie, the math work done with each
cell and neighbors) to a compiled C-extension module and make sure it
releases the GIL on entry, and reclaims the GIL on exit. This would
allow the Python interpreter to get control back, while one thread is
number crunching, and start another thread. Otherwise you not only have
the GIL-serialized number crunching time, but you've also added the
overhead of thread context switches (that is, the threaded version runs
SLOWER than straight nested for loops).
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/