astrofrog / fast-histogram

:zap: Fast 1D and 2D histogram functions in Python :zap:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add OpenMP

henryiii opened this issue · comments

I think it should be possible to rewrite the loops to include OpenMP pragmas. The final update could be protected with #pragma omp atomic and you can use default(shared) private(tx ty ix iy) firstprivate(dataptr) or something similar. You'll need to redo the loops, however, you'll need for loops instead of the inner while (or maybe the outer do while), and the stride part might need to be precalculated in some way.

I agree it would be nice to have this, although based on previous experience with OpenMP in other Python packages, I think I'd want this to be opt-in (rather than trying to automatically determining whether OpenMP can be used). Compilers on MacOS X are a bit of a mess in that respect.

I personally don't have enough experience with OpenMP to be comfortable making those changes, but if you or anyone else reading this issue is happy to look in to it, I'd gladly review a PR.

I can do the OpenMP part, but I don't have enough experience in raw Numpy to know how to write the loops with for's instead of whiles.

I automatically try to use OpenMP on macOS in GooFit, and you are right, it is a mess on macOS. Right now I'm just curious to see it added to the code for comparison, even if it's not as easy to turn on.