-
Notifications
You must be signed in to change notification settings - Fork 114
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
Incorrect memory allocation measurements due to global variables #2166
Comments
Please take a look at it and address this first if you have time thanks |
Is the difference coming from potentially compiling the function at the first call and including the corresponding allocations or not? For example, the docstring of help?> @time
@time expr
@time "description" expr
[...]
In some cases the system will look inside the @time expression and compile some of the called code
before execution of the top-level expression begins. When that happens, some compilation time will
not be counted. To include this time you can run @time @eval ....
[...] What would be the preferred way to check whether executing a function leads to an undesirable large amount of allocations, @vchuravy ? |
@ranocha yes this is correct. In type-stable code the compiler allocations are sometimes hidden. E.g., in the second example the version without a global variable for me shows zero allocations even on the first call, whereas with an access to a global variable the first call allocates a lot and every subsequent call allocates some. One could use a manual Generally? Execute twice, measure the second time. |
Why is it sometimes hidden, and what are you referring to when you say sometimes (i.e., in which cases)? @vchuravy
I think that is what you/we are currently doing here, right? One thing I want to confirm is whether a memory allocation print of zero in the case of elixir_advection_gauss_sbp.jl (which I mentioned) is a normal result for you. @ranocha |
Yes, having zero allocations in |
Since we execute |
I have no idea - the real problem is that #2150 has to run |
@ranocha Yes this issue can be closed 😊 |
This issue was identified due to the unusual memory allocation behavior observed in #2150. It was found that the memory allocation bytes differ greatly between the first and second runs of the
rhs!
function.I further went into this issue and found there may be a problem with how we measure the memory allocation using
allocated
macro - in short, it is suggested to avoid using global variables to achieve same memory allocation bytes across infinite runs (i.e., all runs produce the same result).But here the developer is doing something wrong, for example
Trixi.jl/test/test_dgmulti_1d.jl
Lines 17 to 30 in 9c2f326
The first run of
rhs!
is included in the file elixir_advection_gauss_sbp.jl and the second run ofrhs!
is insidelet
block, If we further examine the second run ofrhs!
, it actually reports zero allocation bytes when we print it. This unusual behavior is caused by the use of global variables in the file we ran initially - at leastsemi
is global during this module. So we never captured the real memory allocation throughout all the tests in this repository.You can also double check here about how the introduction of global var will influence the memory allocation.
The first example -
and
The second example -
xref https://discourse.julialang.org/t/using-allocated-to-track-memory-allocations/4617
cc @ranocha @jlchan @DanielDoehring
The text was updated successfully, but these errors were encountered: