@@ -779,6 +779,8 @@ struct Factorizer {
779779 }
780780 }
781781
782+ void resetIsIncomplete () { isIncomplete = true ; }
783+
782784 BigInteger getNextAltBatch () {
783785 std::lock_guard<std::mutex> lock (batchMutex);
784786
@@ -941,7 +943,7 @@ struct Factorizer {
941943 auto ikit = smoothNumberKeys.begin ();
942944 auto ivit = smoothNumberValues.begin ();
943945 BigInteger result = 1U ;
944- for (size_t i = 0U ; i < smoothNumberKeys.size (); ++i) {
946+ for (size_t i = 0U ; isIncomplete && ( i < smoothNumberKeys.size () ); ++i) {
945947 dispatch.dispatch ([this , i, ikit, ivit, &result]() -> bool {
946948 auto jkit = ikit;
947949 auto jvit = ivit;
@@ -958,6 +960,7 @@ struct Factorizer {
958960 // Check congruence of squares
959961 BigInteger factor = gcd (this ->toFactor , x + y);
960962 if ((factor != 1U ) && (factor != this ->toFactor )) {
963+ isIncomplete = false ;
961964 std::lock_guard<std::mutex> lock (this ->batchMutex );
962965 result = factor;
963966
@@ -968,6 +971,7 @@ struct Factorizer {
968971 // Try x - y as well
969972 factor = gcd (this ->toFactor , x - y);
970973 if ((factor != 1U ) && (factor != this ->toFactor )) {
974+ isIncomplete = false ;
971975 std::lock_guard<std::mutex> lock (this ->batchMutex );
972976 result = factor;
973977
@@ -1224,6 +1228,7 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou
12241228 for (unsigned cpu = 0U ; cpu < futures.size (); ++cpu) {
12251229 futures[cpu].get ();
12261230 }
1231+ worker.resetIsIncomplete ();
12271232
12281233 return boost::lexical_cast<std::string>(worker.solveForFactor ());
12291234 }
0 commit comments