Performance optimizations for shared secondary bank#4011
Open
paulromano wants to merge 4 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR is a follow-on to #3995 with further optimizations I've made for when the shared secondary bank is turned on. The optimizations are focused on how thread-local banks are collected into the shared secondary bank. Currently, this involves a critical section to drain the thread-local banks into a single
SharedArrayfollowed by a sort on the array to preserve reproducibility. I've made the following changes:Performance Profiling
As I mentioned in #3995, these optimizations arose when I was observing poor performance on a D1S simulation using weight windows. To share some profiles as I was going through these optimizations. Here is the starting point (before #3995):

You can see a huge block from the memory allocation of the particle cross section caches (addressed in #3995) but also some other inefficiences due to the allocation/sorting of the shared secondary bank itself (addressed here). After the optimizations from #3995 and this PR, this is what the profile looks like now:

At this point, the major "overhead" from the shared secondary mode is computing random number seeds (
future_seed_coefficients) and I don't think there's much we can do about that.Overall for this problem, the performance with the shared secondary bank improved by about 2.3× with both sets of optimizations, and whereas before it was about 37% of the performance with a local secondary bank, now it reaches 77% of the performance with a local secondary bank (turns out for this problem the load balancing between threads is not bad enough for shared secondary to give better performance than local).
Checklist
I have followed the style guidelines for Python source files (if applicable)I have made corresponding changes to the documentation (if applicable)I have added tests that prove my fix is effective or that my feature works (if applicable)