Understanding meanings of memory allocation numbers

I`m a mechanical engineer who is not familiar with pro programming skills. I wrote a CFD code and cheque the performance i.e runtime and memory with @time and
julia --track-allocation=user --inline=yes.
The result is something like this.

20.860648 seconds (71.33 M allocations: 1.075 GiB, 2.11% gc time)

        - # Fluid variables (density and velocity)
        - function Den_vel!(rho::Array{Float64},ux::Array{Float64},uy::Array{Float64},f::Array{Float64})
        0     for c = 1:Nx1
        0         for r = 1:Ny1
1135680000             rho[r,c]=f[r,c,9]+f[r,c,1]+f[r,c,2]+f[r,c,3]+f[r,c,4]+f[r,c,5]+f[r,c,6]+f[r,c,7]+f[r,c,8];
        0             ux[r,c]=(f[r,c,1]+f[r,c,5]+f[r,c,8]-f[r,c,3]-f[r,c,6]-f[r,c,7])/rho[r,c];
        0             uy[r,c]=(f[r,c,5]+f[r,c,6]+f[r,c,2]-f[r,c,7]-f[r,c,8]-f[r,c,4])/rho[r,c];
        -         end # for r
        -     end # for c
   480000     return rho , ux , uy;
        - end # of function  [Den_vel!]

        - const Nx1 = 25;
        - const Ny1 = 25;
        - const Q = 9;

        - function main()
        -          # allocations
    48784     f       = Array{Float64}(Ny1,Nx1,Q); 
    48784     f_post  = Array{Float64}(Ny1,Nx1,Q);
     5568     rho     = Array{Float64}(Ny1,Nx1);   
     5568     ux      = Array{Float64}(Ny1,Nx1);
     5568     uy      = Array{Float64}(Ny1,Nx1);
        -      #  doing some stuff ....
        0     while condition 
        -      # doing some stuff
        0         rho, ux, uy = Den_vel!(rho,ux,uy,f);
        -      # doing some stuff
        -      end # of while loop
        - end # of function main

@time main()

The while loop iterated 15000 times.
Please look at this result, I wonder if it is normal or not?
Note that rho, ux and uy definitions are similar. all of them are allocated in the main function and given to Den_vel! function as the argument. but rho has a lot of allocations and ux and uy have zero allocations.
Amount of allocation and gc time is not clear for me.
What does allocation mean? Does it means that every time the code redefined a place in ram for this variable? or not?
why rho has allocations?

Try splitting the sum up in a smaller number of terms. At least there has been an issue with this.

rho[r,c]=(f[r,c,9]+f[r,c,1]+f[r,c,2]+f[r,c,3]+f[r,c,4]) + (f[r,c,5]+f[r,c,6]+f[r,c,7]+f[r,c,8])
1 Like

That was interesting for me. It worked. :hushed: Why is that happening?:thinking:
do you have any idea about the return allocation?

I believe it is related to limitations in how big tuples inference can handle but my search karma isn’t good enough to find the relevant issue number. I’m not sure whether it has been solved in Julia 0.7 but at least those kinds of limits are much higher now, so you are less likely to run into them in the future. Hopefully someone with more insight can comment on that.

Not sure about the return allocation but you have already updated those arrays in place, so there’s no need to return them at all.