[SciPy-user] Python on Intel Xeon Dual Core Machine

David Cournapeau david@ar.media.kyoto-u.ac...
Fri Feb 8 02:13:43 CST 2008

Nathan Bell wrote:
> On Feb 8, 2008 12:39 AM, David Cournapeau <david@ar.media.kyoto-u.ac.jp> wrote:
>> FWIW, I could dynamically load a trivial openmp shared library through
>> the dlopen machinery, which is what ctypes uses (to be exact, all python
>> extensions which are not static use it at some point). I tried with
>> centos 5.0 gcc, and then with one directly built from sources (4.2.1),
>> both with success.
>> Which compiler (version of gcc) are you using ? Do you have the code
>> which fails ?
> That's interesting.  I'd like to parallelize scipy.sparse.sparsetools,
> so that was my experiment.
> Here's what I did:
> (1) Added a single OpenMP pragma to one of the sparsetools functions
> void csr_diagonal(const I n_row,
> <SNIP>
>     const I N = std::min(n_row, n_col);
>     #pragma omp parallel for
>     for(I i = 0; i < N; i++){
>         I row_start = Ap[i];
> (2) Compile with g++-4.2
> $ g++-4.2 --version
> g++-4.2 (GCC) 4.2.1 (Ubuntu 4.2.1-5ubuntu4)
> g++-4.2 -Wall -ansi -c -O2 -fPIC -fopenmp sparsetools_wrap.cxx -I
> /usr/include/python2.5/ -I
> /usr/lib/python2.5/site-packages/numpy/core/include/
> g++-4.2 -shared sparsetools_wrap.o -o _sparsetools.so -lgomp
> (3) Import into Python

> $ python
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
Here lies your problem I think: the default compiler on ubuntu, the one 
all softwares are compiled with, is 4.1, which does not have openmp (I 
don't think it is backported by ubuntu, contrary to say fedora). So it 
cannot find open mp library implementation.

I don't know an easy solution: one thing would be to see if just saying 
where to find libgomp.so is enough (e.g. with LD_LIBRARY_PATH and co). 
But I would not trust the thing too much: the much safer alternative 
would be to recompile python with gcc 4.2.

But I checked again: dlopening a library with open mp does work: here is 
an archive with a trivial program using a lib dlopened, works on ubuntu 
with gcc 4.2:




More information about the SciPy-user mailing list