Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threaded grids, and avoiding duplication #89

Merged
merged 13 commits into from
Jul 20, 2017

Conversation

RemiLehe
Copy link
Member

@RemiLehe RemiLehe commented Jul 19, 2017

This PR is only a suggestion -- feel free to reject it.

The aim of this PR is to implement the threaded and non-threaded version of simple functions (in this case, particle push and a few grid function) without duplication. This is done by redefining prange and a JIT decorator njit_parallel in the file threading_utilities.py:

  • if threading is available, prange is the real prange and njit_parallel includes the parallel flag.
  • otherwise, prange is simple range and njit_parallel is simply njit.

Using this trick, some of the grid function were implemented with threading (but others remain to be implemented, such as shifting of the grid in spectral space). I also removed the duplicated particle pusher functions. Eventually, we could probably avoid duplication in the gathering function and deposition functions as well.

Drawback: If the user has numba 0.34 installed, but chooses use_threading=False, threading will still be used for the grid functions, and for the particle pusher. (On the other hand, this is already the case for the FFT...) I am not sure what the best solution to this is, so far. Any suggestion is welcome. Or if you are fine with this drawback (at least for now), this can be merged.
*The user now chooses whether or not to use threading by setting the environment variable FBPIC_DISABLE_THREADING to 1. Therefore I removed the argument use_threading of the Simulation class.

Remains to be done:

  • Although the tests should pass with numba 0.33 (because of the checks that were added), they do not pass currently. This should be maybe investigated. This is now fixed.
  • Profiling: checking that this speeds up execution, and find which remaining routines should be threaded. Done: the plot below shows the scaling (without the compilation and initialization in "others"). The curve "others" does not significantly go down, which means that other grid methods need to be threaded. In particular, the numpy calculation shift_grid_spectral need to be replaced by threaded numba calls. I can do this in a future PR.

screen shot 2017-07-19 at 1 57 02 pm

@RemiLehe RemiLehe changed the title [WIP] Threaded grids [WIP] Threaded grids, and avoiding duplication Jul 19, 2017
@RemiLehe RemiLehe changed the title [WIP] Threaded grids, and avoiding duplication Threaded grids, and avoiding duplication Jul 19, 2017
@MKirchen MKirchen merged commit ffe436c into fbpic:cpuprange Jul 20, 2017
@RemiLehe RemiLehe deleted the threaded_grids branch July 21, 2017 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants