[Numpy-discussion] Threading, multi-processors, and Numeric Python

Joe Van Andel vanandel at atd.ucar.edu
Fri Feb 23 16:18:35 CST 2001


OK, I guess I've just discovered the answer to my own question.  [Don't
you just hate that! :-) ]


My C++ extensions that perform the real calculations needed to be
modified to support multiple threads.  By adding the
Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS macros, the Python
interpreter knew it was safe to allow other threads to execute during
computations, just like it allows other threads to execute during I/O.

 To accomodate the Python global thread lock, I needed to change my code
as follows:

my_func()
{

	/* python calls */

        Py_BEGIN_ALLOW_THREADS

        /* computations that don't use python API */


	Py_END_ALLOW_THREADS

	/* python API calls */
}

Now, I can see both processors being used.

-- 
Joe VanAndel  	          
National Center for Atmospheric Research
http://www.atd.ucar.edu/~vanandel/
Internet: vanandel at ucar.edu




More information about the Numpy-discussion mailing list