Moved mat_mul operations outside inner loops and - #607
Closed
dseyler wants to merge 8 commits into
Closed
Conversation
…own at compile time
…code, but saves 10-15% runtime
Contributor
Author
|
Sorry, opened with wrong branch. Reopening with the correct one! |
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.
Current situation
After profiling a 500k element structural mechanics simulation, I noticed several mat_mul function calls that were unnecessarily repeated within loops, as discussed in issue 602.
These occurred at:
and have now been moved outside their loops.
Additionally, while investigating, it was noticed that many of these mat_mul operations were of fixed-size arrays with sizes known at compilation. These can be optimized with fixed-size Eigen maps, which run 3-4x faster than the generic mat_mul operation.
New fixed-size functions were defined in mat_mul.cpp:
These functions are then dispatched within mat_mul() so developers do not need to distinguish between these differences.
And in mat_mul:
In total, these changes decreased runtime by ~21%.
I suspect this number could increase much more if we correctly implement eigen arrays throughout sv_struct.cpp and mat_models.cpp as many arrays are of size nsd or enon, which have a discrete number of values and can be optimized similarly. I tested this on the viscosity models alone and found another 10% improvement (can open an issue about this, but the code is too messy for this PR)
Release Notes
Code of Conduct & Contributing Guidelines