[C++-sig] OpenMP and boost-python?

Stefan Seefeld seefeld at sympatico.ca
Mon Feb 1 19:15:45 CET 2010


On 02/01/2010 12:58 PM, Anders Wallin wrote:
>>> How difficult is it to make boost-python play nice with OpenMP? Anyone
>>> done it? Is this ever going to be a feature of boost-python, or always
>>> going to require special patching and hacking?
>>>        
>> I'm not sure in how much boost.python would actually need to care about
>> this. Presumably, some OpenMP support needs to be provided by the runtime
>> library (such as the thread management), so I would expect the Python binary
>> (or whatever your main application is) to be responsible for initializing
>> the right runtime library / support.
>> What compiler are you using ? Does it provide some documentation on what
>> needs to be done to activate OpenMP at runtime ?
>>      
> I am using GCC 4.4.1
> The pure C++ code with OpenMP compiles and runs fine using many
> threads. There is almost a linear speedup of trivially parallel
> for-loops.
>
> When this same code is wrapped with boost-python and called from
> Python that speedup disappears, i.e. the Python GIL(?, or something
> similar), forces the C++ code to run in a single thread, or only one
> thread to execute at a time.
>    

I'm not convinced of this. It is true that there may only ever be one 
thread accessing the Python runtime (thus the GIL to enforce it). But 
you may certainly have as many threads doing other work as you want. And 
if your OpenMP-enabled code is pure C++, with no hooks into the Python 
runtime, then I don't see why that may not work.

Again: If your OpenMP-using code and the Python-exposed API are well 
isolated, I don't think either needs to know about the other.

     Stefan


-- 

       ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list