Threaded grids, and avoiding duplication #89
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 decoratornjit_parallel
in the filethreading_utilities.py
:prange
is the realprange
andnjit_parallel
includes the parallel flag.prange
is simplerange
andnjit_parallel
is simplynjit
.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 choosesuse_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 argumentuse_threading
of theSimulation
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 calculationshift_grid_spectral
need to be replaced by threaded numba calls. I can do this in a future PR.