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

Anders Wallin anders.e.e.wallin at gmail.com
Mon Feb 1 18:58:41 CET 2010


>> 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.

MPI is clearly one option, but requires a re-write of the whole code,
and results in code that does not resemble the single-thread code
much. I would like to use OpenMP, since it's a "for dummies" way of
parallellizing things.

Any other suggestions for writing parallel C++ code which is called
from Python ??

AW


More information about the Cplusplus-sig mailing list