Remove unnecessary allocations in Nematic OP#1428
Merged
Merged
Conversation
Contributor
Author
|
@ispivack , hopefully this is useful! |
janbridley
marked this pull request as ready for review
May 8, 2026 00:45
joaander
reviewed
May 8, 2026
joaander
left a comment
Member
There was a problem hiding this comment.
Great! Please update the change log.
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
The nematic OP used Managedarray{3, 3} which is a vector backed data structure. This resulted in an unnecessary allocation in the innermost loop. Worse yet, the fancy multi-index of managed arrays allocates an extra vector for every call to
operator(), so each particle was performing a huge number of unnecessary allocations. This PR swaps to using a basicfloat[9]as the intermediate buffer, which is then distributed to the particle and global tensors as needed.A future PR revising the ManagedArray indexing is probably in order too -- see #1429. This PR is a separate change though, as nematic is so fast that the single managed array allocation quarters the performance.
Motivation and Context
Benchmarks run on battery power on an M1 Pro MacBook.
How Has This Been Tested?
Checklist: