From 5e34779d9506abf0ac3ac1cae44c586b7e8906b3 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Thu, 4 Jun 2020 13:57:57 -0400 Subject: [PATCH] remove return statement from omp-for loop and use "break" --- numerical_methods/durand_kerner_roots.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp index 90789fd4d..a970829ca 100644 --- a/numerical_methods/durand_kerner_roots.cpp +++ b/numerical_methods/durand_kerner_roots.cpp @@ -122,10 +122,13 @@ std::pair durand_kerner_algo( log_file << complex_str((*roots)[n]) << ","; } - while (!check_termination(tol_condition) && iter < INT16_MAX) { + bool break_loop = false; + while (!check_termination(tol_condition) && iter < INT16_MAX && + !break_loop) { std::complex delta = 0; tol_condition = 0; iter++; + break_loop = false; if (log_file.is_open()) log_file << "\n" << iter << ","; @@ -146,9 +149,13 @@ std::pair durand_kerner_algo( if (std::isnan(std::abs(delta)) || std::isinf(std::abs(delta))) { std::cerr << "\n\nOverflow/underrun error - got value = " << std::abs(delta); - return std::pair(iter, tol_condition); + // return std::pair(iter, tol_condition); + break_loop = true; } + if (break_loop) + break; + (*roots)[n] -= delta; tol_condition = std::max(tol_condition, std::abs(std::abs(delta))); @@ -158,6 +165,9 @@ std::pair durand_kerner_algo( } // tol_condition /= (degree - 1); + if (break_loop) + break; + #if defined(DEBUG) || !defined(NDEBUG) if (iter % 500 == 0) { std::cout << "Iter: " << iter << "\t";