/** * put matrix vectors to list */ template <class ZT, class F> void GaussSieve<ZT, F>::add_mat_list(ZZ_mat<ZT> &B) { Z_NR<ZT> t, current_norm; dot_product(best_sqr_norm, B[0], B[0]); ListPoint<ZT> *p; for (int i = 0; i < nr; ++i) { p = new_listpoint<ZT>(nc); matrix_row_to_list_point(B[i], p); // cout << "# [info] init: additing point "; // cout << p->v << endl; if (alg == 3) current_norm = update_p_3reduce(p); else if (alg == 2) current_norm = update_p_2reduce(p); else if (alg == 4) current_norm = update_p_4reduce(p); else { cout << " Error, only support 2-, 3- and 4-sieve" << endl; exit(1); } if ((current_norm < best_sqr_norm) && (current_norm > 0)) // if ((current_norm < best_sqr_norm) ) best_sqr_norm = current_norm; } }
/** * 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; }