[Mesa-users] Variable array sizes in s%
Farag, Ebraheem
ebraheem.farag at yale.edu
Tue Sep 15 01:33:33 UTC 2026
Hello Mathijs,
Unfortunately, I don't think that's what happens. I believe when you point, you are pointing at the piece of memory, so you'll need to repoint by calling "my_m => s% m(k_min, k_max)" every time the buffer changes (or at the beginning of your routine in start_step/check_model to be safe) . The good news is that this is a very cheap operation.
-EbF
________________________________
From: Mathijs Vanrespaille <mathijs.vanrespaille at kuleuven.be>
Sent: Monday, September 14, 2026 6:06 PM
To: Farag, Ebraheem <ebraheem.farag at yale.edu>; mesa-users <mesa-users at lists.mesastar.org>
Subject: Re: Variable array sizes in s%
Hi Eb,
I see! That also explains why I didn't see such alternating behaviour in another MESA model I ran; there was no remeshing in the first time step and thus the two buffers remained in sync. Thanks a lot!
That leaves me with a new question about pointers to the arrays in s% on account of my inexperience with pointers. I have some pointers to specific parts of the arrays like
my_m => s% m(k_min, k_max)
If I set up a pointer like this in one time step and MESA switches to the other buffer in the next time step, then my_m should now point to the new buffer and hence the up-to-date values, should it not?
Cheers,
Mathijs
________________________________
From: Farag, Ebraheem <ebraheem.farag at yale.edu>
Sent: 14 September 2026 07:55
To: mesa-users <mesa-users at lists.mesastar.org>; Mathijs Vanrespaille <mathijs.vanrespaille at kuleuven.be>
Subject: Re: Variable array sizes in s%
Hello Mathijs,
MESA carries two alternating sets (buffers) of star pointer arrays, one buffer for the old mesh, and one buffer for the new mesh. In one timestep, extras_start_step is called before the model is remeshed, hence it uses a different buffer than the one called in extras_check_model. The buffers alternate every step, since the solution to the current step becomes the buffer for the pre-remeshed model at the start of the next timestep. Because the buffers in your example happen to differ in length by 2, you are likely observing the total size of the array for e.g. s% m to alternate because the model is switching between each buffer each timestep (where remesh is called). you are accessing a different array of memory with slightly different total size.
Here is an example of what happens when the buffers are fixed in size and differ in length by two:
-------------------------------------------------------------
size(s% m_Buffer1) = N
Size(s% m_Buffer2) = N+2
s% m => (Buffer1)
extras_start_step : size(s%m) = N
remesh: s%m => (Buffer2)
extras_check_model: size(s%m) = N+2
...
extras_start_step : size(s%m) = N+2
remesh: s%m => (Buffer1)
extras_check_model: size(s%m) = N
-------------------------------------------------------------
This is a difference in the spare capacity of the array, not a difference in s% nz. The size between the buffers can vary, but this does not matter because s% nz remains a subset of the total array size. When remeshing asks the model to extend an array it extends to:
max(s%prev_mesh_nz, s%nz) + 200
The arrays in each buffer grow asynchronously since they are grown on different timesteps, when a remesh is asked for, and when the requested number of zones exceeds the size of the current buffer's star pointer arrays. Once each buffer's star pointer arrays grow, they do not get smaller. The buffer is grown in a way which attempts to minimize the number of times the star pointer arrays need to be resized/reallocated in memory.
-EbF
________________________________
From: Mesa-users <mesa-users-bounces at lists.mesastar.org> on behalf of Mathijs Vanrespaille via Mesa-users <mesa-users at lists.mesastar.org>
Sent: Monday, September 7, 2026 3:51 PM
To: mesa-users <mesa-users at lists.mesastar.org>
Subject: [Mesa-users] Variable array sizes in s%
Dear MESA users and devs,
I have a question about the array sizes in MESA version 26.4.1. I noticed that the size of the arrays in s%, e.g. s% m changes between extras_start_step and extras_check_model even though the number of zones in s% nz remains unchanged in a rotating model based on the conserve_angular_momentum test case. Specifically, the sizes of the s% arrays alternate between increase by +2 in one step and decreasing by -2 again in the next step. Attached is a basic work directory that prints s% nz and size(s% m) at different stages of each time step to demonstrate this behaviour.
I thought the size of these arrays was meant to be mostly constant to avoid paying the computational cost of de-allocating and re-allocating them, hence why they are also initialised to be larger than s% nz. Is this variable size of the arrays in s% expected and/or desirable? If so, what is its purpose? If not, does anyone have any guesses what may cause it? I took a look in $MESA_DIR/star/private/alloc.f90 and $MESA_DIR/star/private/adjust_mesh.f90, but I didn't spot any obvious clues.
Kind regards,
Mathijs Vanrespaille
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20260915/e000266b/attachment.htm>
More information about the Mesa-users
mailing list