-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Pre-allocate computation arrays for plasticity #32180
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
base: next
Are you sure you want to change the base?
Conversation
|
Job Precheck, step Clang format on 5fc246c wanted to post the following: Your code requires style changes. A patch was auto generated and copied here
Alternatively, with your repository up to date and in the top level of your repository:
|
5fc246c to
4b17c70
Compare
|
Job Documentation, step Docs: sync website on 81747b5 wanted to post the following: View the site here This comment will be updated on new commits. |
|
Hi @loganharbour . While at INL, we did some profiling and found that heap allocation/deallocation was taking about 20% of the compute time in plasticity models. This is my attempt at addressing a bit of this problem (by making class variables). Could you please look and comment? There are probably better ways of doing this. I'm worried about:
|
|
Job Coverage, step Generate coverage on 81747b5 wanted to post the following: Framework coverage
Modules coverageSolid mechanics
Full coverage reportsReports
This comment will be updated on new commits. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
loganharbour
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutable is mostly okay.
Do the functions that call it need to be const? If not, it's probably to just make the functions non-const so that it's clear that they change state. And add in the docstring that they changed that shared state.
For mastodon - you can actually re-add the old methods, and just have them call your new function (returning a copy of tensor). We can merge this, fix mastodon, and then remove the old methods.
modules/solid_mechanics/include/materials/MultiParameterPlasticityStressUpdate.h
Outdated
Show resolved
Hide resolved
3152c75 to
497d3aa
Compare
|
Hi @loganharbour , thank you for your input so far. Can you have another look and tell me whether this approach is good? If so, i'll make a bunch of other similar changes. I suspect not only mastodon/blackbear will need modification - there might be closed-source apps that need small modification too. Perhaps mutable+const is actually better, as "const" tells the reader "this isn't changing class members" which is reasonable conceptually for the dstressparam_dstress function, which doesn't change important things like stress. But then mutable is needed, and i don't see many mutable things in MOOSE. |
497d3aa to
84b2fd5
Compare
Yeah, because of this I think it's best that we keep the old functions around (in their non-optimized state) so that we can cleanly patch them and eventually remove the old functions in MOOSE once the apps are patched. |
|
OK, thanks @loganharbour . Today at some stage, i'm going to go ahead and change more similar things in a similar way, assuming you think this approach (putting the "out" result as a function argument instead of a function return) is optimal. |
|
Hi @loganharbour - could you please confirm that these mutables won't cause problems with multi-threading? |
3ed96fa to
33defc3
Compare
GiudGiud
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think these are stack variables. They are just pre-allocated, and still on the heap.
I would rename the PR to "Pre-allocate computation arrays for plasticity"
modules/solid_mechanics/include/materials/MultiParameterPlasticityStressUpdate.h
Outdated
Show resolved
Hide resolved
|
By the way, @loganharbour and @GiudGiud , with this PR, the walltime of residual calculations (which are the bulk of compute time in explicit time stepping) is about 0.7x what it was before this PR. This is in realistic models. I'm super pleased with that speedup. |
…ely MohrCoulombStressUpdate, TensileStressUpdate and TwoParameterPlasticityStressUpdate, and derived classes from those, such as CappedDruckerPragerStressUpdate and CappedDruckerPragerCosseratStressUpdate, now have no variables that are repeatedly heap-allocated/deallocated in functions that are relevant to explicit time stepping (ie, functions relevant to Jacobian-only calculations have largely been untouched). Testing on realistic models shows this speeds up residual computations by around 1.4x, which is especially important when using explicit time stepping where residual calculations often take the bulk of the simulation runtime. Refs idaholab#32178 . Most of the strategy boils down to making a few mutable scratch class variables that are allocated just once. Mutable variables have been used so that const could be retained, which i think makes most sense in this situation. Most of the changes occur within MultiParameterPlasticityStressUpdate, and do not impact derived classes. However, the signatures of two important functions - dstress_param_dstress and d2stress_param_dstress - have been changed. The derived classes within solid_mechanics have all had their signatures updated, but external Apps such as Blackbear should be updated to take advantage of all the speedups associated with no repeated heap alloc/dealloc. When that is completed, the old versions may be deleted from MultiParameterPlasticityStressUpdate, and I've included notes on how to do that.
33defc3 to
81747b5
Compare
|
Job Test, step Results summary on 81747b5 wanted to post the following: Framework test summaryCompared against 5eee4e5 in job civet.inl.gov/job/3497366. No change Modules test summaryCompared against 5eee4e5 in job civet.inl.gov/job/3497366. No change |
|
Code looks good There's quite a bit of not-covered code, so we can't really know if the changes break things Are these routines tested in combined or in another module than solid mechanics? Or in an app? |
this is really great. We should take another look at any code allocating tensors on the fly |
Hi @GiudGiud - thank you... i want to address the reduced coverage. (But not all of it, as i note that about half the "misses" are on the functions that are now depreciated, so none of solid mechanics should hit those functions.). Could you please:
|
Yes unless they are marked "heavy"
I never do it that way, I just push to civet and civet takes care of generating the coverage report |
Created some stack variables to replace heap variables in plasticity algorithms. A number of other heap variables should be put on stack to close the issue: this is a first-pass only. Refs #32178
Reason
Design
Impact