numarray and SMP

Aahz aahz at pythoncraft.com
Tue Jul 6 09:59:39 EDT 2004


In article <Pine.LNX.4.44.0407011237490.10235-100000 at ccc1.wpi.edu>,
Christopher T King  <squirrel at WPI.EDU> wrote:
>
>1) Surround the C vector operations with Py_BEGIN_ALLOW_THREADS and 
>   Py_END_ALLOW_THREADS, thus allowing the vector operations (which don't 
>   access Python structures) to run in parallel with the interpreter.
>   Python glue code would take care of threading and locking.
>
>2) Move the parallelization into the C vector functions themselves. This 
>   would likely get poorer performance (a chain of vector operations
>   couldn't be combined into one threaded operation).
>
>I'd much rather do #1, but will playing around with the interpreter state 
>like that cause any problems?

Not at all -- that's precisely what they're there for.  All you have to
do is make sure you're not calling back into Python before doing
Py_END_ALLOW_THREADS.  Traditionally, Python has only done this for I/O
operations; I'm very happy to see someone trying to take a whack at the
computational side.  (Although I ended up mostly dropping the ball, that
was the original impetus for the Decimal project, to encourage more
computational threading.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Typing is cheap.  Thinking is expensive."  --Roy Smith, c.l.py



More information about the Python-list mailing list