-
Notifications
You must be signed in to change notification settings - Fork 55
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
Shifted MINRES Allocations Issue #937
Comments
I will fix it but it's just 160 bits Farhad. :) |
@farhadrclass using BenchmarkTools
for FC in (Float32, Float64)
@testset "Data Type: $FC" begin
A = FC.(get_div_grad(18, 18, 18)) # Dimension m x n
m, n = size(A)
k = div(n, 2)
Au = A[1:k,:] # Dimension k x n
Ao = A[:,1:k] # Dimension m x k
b = Ao * ones(FC, k) # Dimension m
c = Au * ones(FC, n) # Dimension k
λ = FC(1.3)
T = real(FC)
shifts = T[1; 2; 3; 4; 5]
nshifts = 5
nbits_FC = sizeof(FC) # 8 bits for ComplexF32 and 16 bits for ComplexF64
nbits_T = sizeof(T)
@testset "MINRES" begin
# MINRES needs:
# 6 n-vectors: x, r1, r2, w1, w2, y
storage_minres_bytes(n) = nbits_FC * 6 * n
expected_minres_bytes = storage_minres_bytes(n)
minres(A, b) # warmup
actual_minres_bytes = @allocated minres(A, b)
@test expected_minres_bytes ≤ actual_minres_bytes ≤ 1.02 * expected_minres_bytes
solver = MinresSolver(A, b)
minres!(solver, A, b) # warmup
inplace_minres_bytes = @allocated minres!(solver, A, b)
@test inplace_minres_bytes == 0
end
@testset "MINRES_lambda" begin
# MINRES needs:
# 6 n-vectors: x, r1, r2, w1, w2, y
storage_minres_bytes(n) = nbits_FC * 6 * n
expected_minres_bytes = storage_minres_bytes(n)
minres(A, b) # warmup
actual_minres_bytes = @ballocated minres($A, $b)
@test expected_minres_bytes ≤ actual_minres_bytes ≤ 1.02 * expected_minres_bytes
solver = MinresSolver(A, b)
minres!(solver, A, b; λ) # warmup
inplace_minres_bytes = @ballocated minres!($solver, $A, $b, λ=$λ)
@test inplace_minres_bytes == 0
end
end
end Test Summary: | Pass Total Time
Data Type: Float32 | 4 4 21.6s
Test Summary: | Pass Total Time
Data Type: Float64 | 4 4 24.6s |
Thanks @amontoison The issue I have is that when I use MINRES in my solver: https://github.com/Farhad-phd/JSOSolvers.jl/blob/iR2/src/R2N.jl
I still need to clean the code a bit but the allocation is there |
The allocation could be in |
@amontoison exactly, I am trying to remove my allocation part of the code, however the 3 algorithm uses the same code except the call to subsolver, so I assumed 268 is from there. For CgSolver the main issue is that I need to shift the H with \sgima*I which creates the memory and I am fixing that right now. I was expecting the MinresSolver however to have around 268 or less allocation but that is not the case. Would it be possible to check on Minres end and see if allocate when using shift ? |
I checked it with my unit tests above (no allocation with |
@farhadrclass |
Description:
The MINRES solver unexpectedly allocates memory when using shifted computations, even though it should not. My tests indicate that the solver does not maintain zero allocations as expected, specifically when running the
MINRES_lambda
test case.Steps to Reproduce:
Below is the test code used to verify memory allocation for the shifted MINRES solver:
Observed Results:
Expected Results:
The solver should allocate no additional memory when using
minres!
with a shift parameter (λ
). Specifically, theinplace_minres_bytes
should equal0
.Impact:
This issue affects the expected performance and efficiency of the solver, particularly in memory-constrained environments.
Additional Information:
The observed allocation of 160 bytes occurs consistently during the
MINRES_lambda
test case for bothFloat32
andFloat64
data types.The text was updated successfully, but these errors were encountered: