Stop if residual is 0
authorAndreas Eversberg <jolly@eversberg.eu>
Wed, 21 Oct 2015 04:27:20 +0000 (06:27 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 14 May 2016 10:55:54 +0000 (12:55 +0200)
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);
 //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;
                if (target_residual_change && (prev_residual-curr_residual)/prev_residual < target_residual_change)
                        break;
                prev_residual = curr_residual;