mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Use allocatable arrays in predictive_mixing

Open evbauer opened this issue 1 year ago • 2 comments

On the distillation branch, Rob pointed out to me that there's a risk of stack overflow when using explicit shape automatic arrays, for example to declare an extra array for saving the composition in case it needs to be reset. (See discussion at https://github.com/MESAHub/mesa/commit/a31cb38ff3b647f4cdeb501d22c5322b318e870c#r117329563.)

This was a construction I had copied over from predictive mixing, which makes even more extensive use of such automatic arrays: https://github.com/MESAHub/mesa/blob/c3e28ef8279e6f56a62239a8ce6e8f822fab10ec/star/private/predictive_mix.f90#L719-L735

@rhdtownsend do you think it would be worthwhile to refactor this code to use something more like the saved_data construction with allocatable arrays like in conv_premix?

evbauer avatar Aug 22 '23 20:08 evbauer

Does it help, though? Are we not just delaying the inevitable until there's an assignment of allocate statement? Or does an array being allocatable mean that only parts of it will go on the stack when needed (in which case I agree with using allocatable arrays)? I do find the explicit shapes help readability, though that can also be achieved in a comment.

warrickball avatar Sep 14 '23 12:09 warrickball

I think this is compiler dependent, but I recall it being the case with gfortran that automatic arrays go on the stack, while allocatables go on the heap. Without user intervention (e.g., via ulimit), the stack is quite limited in size, so I can see a legitimate difference here.

cheers,

Rich

On Sep 14, 2023, at 8:10 AM, Warrick Ball @.***> wrote:

Does it help, though? If the calculation is going to take that much memory, then that's that. I.e., are we not just delaying the inevitable until there's an assignment of allocate statement? Or does an array being allocatable mean that only parts of it will go on the stack when needed (in which case I agree with using allocatable arrays)? I do find the explicit shapes help readability, though that can also be achieved in a comment. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

-- Rich Townsend • Professor of Astronomy Astronomy Department • University of Wisconsin-Madison Phone: 608-262-1752 • E-mail: @.***

rhdtownsend avatar Sep 14 '23 13:09 rhdtownsend