/** * 2-sieve */ template <class ZT, class F> bool GaussSieve<ZT, F>::run_2sieve() { ListPoint<ZT> *current_point; NumVect<Z_NR<ZT>> vec(nc); Z_NR<ZT> current_norm; #ifdef REDUCE_TIMING struct timeval time, time2; gettimeofday(&time, 0); long startt = 1000000 * time.tv_sec + time.tv_usec; double sec, sec2 = 0.0; long nred = 0; #endif /* Loop till you find a short enough vector, or enough collisions. */ while ((best_sqr_norm > goal_sqr_norm) && (collisions < mult * max_list_size + add)) { /* update stats */ iterations++; max_list_size = max(max_list_size, long(List.size())); /* sample new or fetch from queue */ if (Queue.empty()) { vec = Sampler->sample(); current_point = num_vec_to_list_point(vec, nc); samples++; } else { current_point = Queue.front(); Queue.pop(); } #ifdef REDUCE_TIMING gettimeofday(&time2, 0); long startt2 = 1000000 * time2.tv_sec + time2.tv_usec; nred++; #endif /* sieve current_point */ current_norm = update_p_2reduce(current_point); //print_list(List); #ifdef REDUCE_TIMING gettimeofday(&time2, 0); long endt2 = 1000000 * time2.tv_sec + time2.tv_usec; sec2 += (endt2 - startt2) / 1000000.0; #endif /* record collisions */ if (current_norm == 0) collisions++; if (current_norm > 0 && current_norm < best_sqr_norm) { best_sqr_norm = current_norm; } #if 1 print_curr_info(); /*if (samples+nr-List.size()-Queue.size() != collisions) exit(1); */ #endif /* tuples of (iters, max_list_size) */ iters_norm.push_back(best_sqr_norm); iters_ls.push_back(max_list_size); } #ifdef REDUCE_TIMING gettimeofday(&time, 0); long endt = 1000000 * time.tv_sec + time.tv_usec; sec = (endt - startt) / 1000000.0; cout << "# [info] total-reducuction time " << sec2; cout << ", average-reducuction time " << sec2 / nred << " (" << nred << ")" << endl; cout << "# [info] total time " << sec << endl; #endif /* finished main procedure, output some information */ print_final_info(); #ifdef DEBUG_CHECK_2RED if (check_2reduce_order_list<ZT>(List)) cout << "# [info] check 2-reduced OK" << endl; else cout << "# Error: check 2-reduced not OK" << endl; #endif if (best_sqr_norm > goal_sqr_norm) return false; return true; }
/** * 4-sieve */ template <class ZT, class F> bool GaussSieve<ZT, F>::run_4sieve() { ListPoint<ZT> *current_point; NumVect<Z_NR<ZT>> vec(nc); Z_NR<ZT> current_norm; /* main iteration */ while ((best_sqr_norm > target_sqr_norm) && (collisions < mult * max_list_size + 200)) { iterations++; max_list_size = max(max_list_size, long(List.size())); if (Queue.empty()) { vec = Sampler->sample(); current_point = num_vec_to_list_point(vec, nc); samples++; } else { current_point = Queue.front(); Queue.pop(); } current_norm = update_p_4reduce(current_point); #if 0 if (!check_4reduce_order_list<ZT>(List)) { cout << "!!! Failed " << endl; //print_list(List); exit(1); } else { cout << "[check 4-red] OK " << endl; //print_list(List); } #endif if (current_norm == 0) collisions++; if (current_norm > 0 && current_norm < best_sqr_norm) { best_sqr_norm = current_norm; } #if 1 print_curr_info(); #endif /* tuples of (iters, max_list_size) */ iters_norm.push_back(best_sqr_norm); iters_ls.push_back(max_list_size); } /* finished main procedure, output some information */ print_final_info(); #ifdef DEBUG_CHECK_4RED if (check_4reduce_order_list<ZT>(List)) cout << "# [info] check 4-reduced OK" << endl; else cout << "# Error: check 4-reduced not OK" << endl; #endif // print_list(List); if (best_sqr_norm > target_sqr_norm) return false; return true; }