python-pillow/Pillow — pull request #1013 by wiredfool (2014-11-16 06:09:11+00:00)
Title: Experimental: OpenMP

While looking through the SSE version of @homm's benchmarking of the new stretch implementation, I ran across an Intel paper on speeding up imaging operations. In addition to vectorization, they used openmp to parallelize the loops with very little developer effort. GCC 4.4+ ships with OpenMP 3.0, which is good enough for what we would need to do here. I've put the pragma on the horizontal stretch inner loop and put together the necessary bits to get Pillow built using OpenMP.

`python setup.py build_ext --enable-openmp install ` or simply `make install-openmp`

Using the same benchmark as #977,

Current master:

Interpolation | Size | Time
------------- | ---- | ----
Antialias | 2048x1152 | 0.4238
Antialias | 320x240 | 0.2331
Bicubic | 2048x1152 | 0.3306
Bicubic | 320x240 | 0.1509
Bilinear | 2048x1152 | 0.2369
Bilinear | 320x240 | 0.08423

With OpenMP on a 4 cores of an i7 from 2008 in a Ubuntu 12.04 vm, running kvm. (So, not cutting edge, but not wimpy)

Interpolation | Size | Time
------|-----|----
Antialias | 2048x1152 | 0.1845
Antialias | 320x240 | 0.08882
Bicubic | 2048x1152 | 0.212
Bicubic | 320x240 | 0.1025
Bilinear | 2048x1152 | 0.1741
Bilinear | 320x240 | 0.06423

Note that the speeds of the OpenMP version seem to be roughly constrained by memory bandwidth rather than in processor ops. I think this is a win, but needs further investigation.

There are at least a few places where I think work may be required:
* Currently, gcc only. I think windows could be supported easily, there's currently no support for openmp in clang/xcode. There is openmp for clang, but it's not in mainline yet.
* Unsure of the packaging issues for binaries.
* Not sure what the performance will be like on systems that advertise 32 threads but only provide 1.5 worth of cores. (e.g. travis).
* Unsure of interaction with SSE. Would be awesome if it boosted that as well.
* Testing and benching is going to be important.