Stop if residual is 0
[colorize.git] / lib / multigrid.c
index f3097ee..a2409c8 100644 (file)
@@ -1434,6 +1434,10 @@ int solve_mg(int nlevel, int iters, int ncycle, darray_t **values, darray_t **ma
 //printf("residual %.8f (change=%%%.4f)\n", curr_residual, (prev_residual-curr_residual)/prev_residual*100);
                if (target_residual_change)
                        printf(" %.1f%%", (prev_residual-curr_residual)/prev_residual*100); fflush(stdout);
+               if (curr_residual == 0.0) {
+                       printf(" 0"); fflush(stdout);
+                       break;
+               }
                if (target_residual_change && (prev_residual-curr_residual)/prev_residual < target_residual_change)
                        break;
                prev_residual = curr_residual;