Skip to content
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

Accelerate initialization through the use of undefined arrays #116

Closed
JanJereczek opened this issue Jul 15, 2024 · 1 comment · Fixed by #123
Closed

Accelerate initialization through the use of undefined arrays #116

JanJereczek opened this issue Jul 15, 2024 · 1 comment · Fixed by #123
Assignees
Labels
performance We could be faster

Comments

@JanJereczek
Copy link
Owner

JanJereczek commented Jul 15, 2024

The initialization is not the performance-critical step of our code but accelerating it can improve the user experience. To achieve this, we could initialize any array with undef, in alignment with the results of following benchmark:

julia> @btime zeros(10,10)
  47.559 ns (2 allocations: 944 bytes)
10×10 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 ⋮                        ⋮                   
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

julia> @btime Matrix{Float64}(undef,10,10)
  23.417 ns (2 allocations: 944 bytes)
10×10 Matrix{Float64}:
 6.9109e-310  6.9109e-310  6.9109e-310  …  6.9109e-310  6.9109e-310  6.9109e-310
 6.9109e-310  6.9109e-310  6.9109e-310     6.9109e-310  6.9109e-310  6.9109e-310
 6.9109e-310  6.9109e-310  6.9109e-310     6.9109e-310  6.9109e-310  6.9109e-310
 ⋮                                      ⋱                            
 6.9109e-310  6.9109e-310  6.9109e-310     6.9109e-310  6.9109e-310  6.9109e-310
 6.9109e-310  6.9109e-310  6.9109e-310     6.9109e-310  6.9109e-310  6.9109e-310
@JanJereczek JanJereczek self-assigned this Jul 15, 2024
@JanJereczek JanJereczek added the performance We could be faster label Jul 15, 2024
@JanJereczek
Copy link
Owner Author

Additionally, consider following benchmark:

@btime A = copy($Omega.null)
  5.639 μs (2 allocations: 128.05 KiB)

@btime A = Matrix{Float64}(undef, $Omega.Nx, $Omega.Ny)
  439.170 ns (2 allocations: 128.05 KiB)

Speed-up factor is about 10 for this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance We could be faster
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant