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

[misc] Ensure succeeded variable is properly initialized in matrix-free solvers #8484

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions python/taichi/linalg/matrixfree_cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def MatrixFreeCG(A, b, x, tol=1e-6, maxiter=5000, quiet=True):
beta = ti.field(dtype=solver_dtype)
scalar_builder.place(alpha, beta)
scalar_snode_tree = scalar_builder.finalize()
succeeded = True

@ti.kernel
def init():
Expand Down Expand Up @@ -96,6 +95,7 @@ def update_p():
p[I] = r[I] + beta[None] * p[I]

def solve():
succeeded = True
A._matvec(x, Ax)
init()
initial_rTr = reduce(r, r)
Expand Down Expand Up @@ -129,8 +129,9 @@ def solve():
f">>> Conjugate Gradient method failed to converge in {maxiter} iterations: Residual = {sqrt(new_rTr):e}"
)
succeeded = False
return succeeded

solve()
succeeded = solve()
vector_fields_snode_tree.destroy()
scalar_snode_tree.destroy()
return succeeded
Expand Down Expand Up @@ -252,6 +253,7 @@ def update_r():
r[I] = s[I] - omega[None] * t[I]

def solve():
succeeded = True
A._matvec(x, Ax)
init()
initial_rTr = reduce(r, r)
Expand Down Expand Up @@ -296,8 +298,9 @@ def solve():
if not quiet:
print(f">>> BICGSTAB failed to converge in {maxiter} iterations: Residual = {sqrt(rTr):e}")
succeeded = False
return succeeded

solve()
succeeded = solve()
vector_fields_snode_tree.destroy()
scalar_snode_tree.destroy()
return succeeded
Loading