Example of Cython + openMP working on OS X?

920 views
Skip to first unread message

Richard Stanton

unread,
Jun 20, 2013, 5:35:32 PM6/20/13
to cython...@googlegroups.com
I've been trying to use multiple threads on my machine using prange, but no speed-up is occurring, suggesting that openMP is not actually being used. In the cython documentation, I noticed that it says that clang doesn't support openMP, so I've been trying to use gcc instead, but don't seem to have had much success.

Does anyone have a simple example of some code (+ a setup.py file) using, say, prange, that works under OS X? I'd be very grateful to see a working example that I could modify.

Thanks very much.

Richard Stanton

Dougal Sutherland

unread,
Jun 25, 2013, 1:29:14 AM6/25/13
to cython...@googlegroups.com
The attached code works for me when I use CC=gcc python setup.py install. If I then do python -m example.run, it uses all my cores. (Kill it with ^\, since it's doing a sillily long computation in a C extension and won't see ^C until it's done.)

This is on OS X 10.8.4 with Xcode 4.6.3 (though I think my command-line tools might be out of date), where gcc is actually llvm-gcc-4.2:

$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

It also works with my Homebrew-installed gcc 4.8.1.

I don't know of a good way to tell setup.py itself to use gcc rather than clang. Supposedly OpenMP support in clang is on its way, though, so this will hopefully become a nonissue before too long.

- Dougal
example.tar.bz2

Sturla Molden

unread,
Jun 25, 2013, 6:04:46 AM6/25/13
to cython...@googlegroups.com
On 25.06.2013 07:29, Dougal Sutherland wrote:
> The attached code works for me when I use CC=gcc python setup.py
> install. If I then do python -m example.run, it uses all my cores. (Kill
> it with ^\, since it's doing a sillily long computation in a C extension
> and won't see ^C until it's done.)
>
> This is on OS X 10.8.4 with Xcode 4.6.3 (though I think my command-line
> tools might be out of date), where gcc is actually llvm-gcc-4.2:
>
> $ gcc --version
> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc.
> build 5658) (LLVM build 2336.11.00)

Yes, on OSX CC is clang, so a

$ export CC=gcc

in the terminal will fix it.

llvm-gcc-4.2 is the system C compiler. Don't mess with it by installing
different GCCs on top.

Personally I prefer to use Intel C compiler (2013) on OSX, which is
link-compatible with llvm-gcc-4.2. To use this compiler with distutils
(setup.py) I use this in the terminal:

$ export CC=icc


Sturla

Richard Stanton

unread,
Jun 25, 2013, 12:25:00 PM6/25/13
to cython...@googlegroups.com
Thanks, Dougal.
Reply all
Reply to author
Forward
0 new messages