示例#1
0
/**
 * 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;
}
示例#2
0
/**
 * 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;
}
示例#3
0
int main(int argc, char* argv[]) {
  int my_rank, procs;
  long i, jindex, current_index, runtimes_index;
  double* tstart_sec;
  double* tend_sec;
  double* maxRuntimes_sec = NULL;
  //pred_job_list_t jlist;
  job_list_t jlist;
  collective_params_t coll_params;
  long nrep, stride;
  int stop_meas;
  pred_conditions_t pred_coefs;
  basic_collective_params_t coll_basic_info;
  time_t start_time, end_time;
  double* batch_runtimes;
  long updated_batch_nreps;
  reprompib_sync_functions_t sync_f;
  reprompib_dictionary_t params_dict;
  reprompib_sync_options_t sync_opts;
  reprompib_common_options_t common_opt;
  nrep_pred_params_t pred_opts;

  /* start up MPI
   * */
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &procs);

  // initialize time measurement functions
  init_timer();
  start_time = time(NULL);

  // initialize global dictionary
  reprompib_init_dictionary(&params_dict, HASHTABLE_SIZE);

  // initialize synchronization functions according to the configured synchronization method
  initialize_sync_implementation(&sync_f);

  // parse arguments and set-up benchmarking jobs
  print_command_line_args(argc, argv);

  // parse the benchmark-specific arguments (prediction methods)
  reprompib_parse_options(argc, argv, &pred_opts);

  // parse common arguments (e.g., msizes list, MPI calls to benchmark, input file)
  reprompib_parse_common_options(&common_opt, argc, argv);

  // parse extra parameters into the global dictionary
  reprompib_parse_extra_key_value_options(&params_dict, argc, argv);

  sync_f.parse_sync_params(argc, argv, &sync_opts);

  init_collective_basic_info(common_opt, procs, &coll_basic_info);
  //generate_pred_job_list(&pred_opts, &common_opt, &jlist);
  generate_job_list(&common_opt, 0, &jlist);

  // execute the benchmark jobs
  for (jindex = 0; jindex < jlist.n_jobs; jindex++) {
    job_t job;
    job = jlist.jobs[jlist.job_indices[jindex]];

    // start synchronization module
    sync_f.init_sync_module(sync_opts, pred_opts.n_rep_max);

    if (jindex == 0) {
      print_initial_settings_prediction(&common_opt, &pred_opts, &params_dict, sync_f.print_sync_info);
    }

    tstart_sec = (double*) malloc(pred_opts.n_rep_max * sizeof(double));
    tend_sec = (double*) malloc(pred_opts.n_rep_max * sizeof(double));

    maxRuntimes_sec = (double*) malloc(pred_opts.n_rep_max * sizeof(double));

    nrep = pred_opts.n_rep_min;
    stride = pred_opts.n_rep_stride;

    // compute clock drift models relative to the root node
    sync_f.sync_clocks();

    current_index = 0;
    runtimes_index = 0;

    collective_calls[job.call_index].initialize_data(coll_basic_info, job.count, &coll_params);

    // initialize synchronization window
    sync_f.init_sync();

    while (1) {

      // main measurement loop
      for (i = 0; i < nrep; i++) {
        sync_f.start_sync();

        tstart_sec[current_index] = sync_f.get_time();
        collective_calls[job.call_index].collective_call(&coll_params);
        tend_sec[current_index] = sync_f.get_time();
        current_index++;
        runtimes_index++;

        sync_f.stop_sync();
      }

      batch_runtimes = maxRuntimes_sec + (runtimes_index - nrep);
      compute_runtimes(tstart_sec, tend_sec, (current_index - nrep), nrep, sync_f.get_errorcodes,
          sync_f.get_normalized_time, batch_runtimes, &updated_batch_nreps);

      // set the number of correct measurements to take into account out-of-window measurement errors
      runtimes_index = (runtimes_index - nrep) + updated_batch_nreps;

      stop_meas = 0;
      set_prediction_conditions(runtimes_index, maxRuntimes_sec, pred_opts, &pred_coefs);
      stop_meas = check_prediction_conditions(pred_opts, pred_coefs);

      /*if (my_rank==0) {
       fprintf(stdout, "runt_index=%ld updated_nrep=%ld \n",
       runtimes_index, updated_batch_nreps );

       fprintf(stdout, "nrep=%ld (min=%ld, max=%ld, stride=%ld) \n",
       nrep, jlist.prediction_params.n_rep_min, jlist.prediction_params.n_rep_max, jlist.prediction_params.n_rep_stride );
       }
       */

      MPI_Bcast(&stop_meas, 1, MPI_INT, OUTPUT_ROOT_PROC, MPI_COMM_WORLD);

      if (stop_meas == 1) {
        break;
      } else {
        nrep = nrep + stride;
        stride = stride * 2;
      }

      if (current_index + nrep > pred_opts.n_rep_max) {
        nrep = pred_opts.n_rep_max - current_index;
      }
      if (current_index >= pred_opts.n_rep_max) {
        break;
      }
    }

    job.n_rep = runtimes_index;
    // print_results
    print_measurement_results_prediction(&job, &common_opt, maxRuntimes_sec,
        &pred_opts, &pred_coefs);

    free(tstart_sec);
    free(tend_sec);
    free(maxRuntimes_sec);

    collective_calls[job.call_index].cleanup_data(&coll_params);
    sync_f.clean_sync_module();
  }

  end_time = time(NULL);
  print_final_info(&common_opt, start_time, end_time);

  cleanup_job_list(jlist);
  reprompib_free_common_parameters(&common_opt);
  reprompib_cleanup_dictionary(&params_dict);

  /* shut down MPI */
  MPI_Finalize();

  return 0;
}
示例#4
0
int main(int argc, char *argv[])
{
  ssize_t i, j, niter;
  params_t *params;
  gk_csr_t *mat;
  FILE *fpout;
 
  /* get command-line options */
  params = parse_cmdline(argc, argv);

  /* read the data */
  mat = gk_csr_Read(params->infile, GK_CSR_FMT_METIS, 1, 1);

  /* display some basic stats */
  print_init_info(params, mat);



  if (params->ntvs != -1) {
    /* compute the pr for different randomly generated restart-distribution vectors */
    float **prs;

    prs = gk_fAllocMatrix(params->ntvs, mat->nrows, 0.0, "main: prs");

    /* generate the random restart vectors */
    for (j=0; j<params->ntvs; j++) {
      for (i=0; i<mat->nrows; i++)
        prs[j][i] = RandomInRange(931);
      gk_fscale(mat->nrows, 1.0/gk_fsum(mat->nrows, prs[j], 1), prs[j], 1);

      niter = gk_rw_PageRank(mat, params->lamda, params->eps, params->niter, prs[j]);
      printf("tvs#: %zd; niters: %zd\n", j, niter);
    }

    /* output the computed pr scores */
    fpout = gk_fopen(params->outfile, "w", "main: outfile");
    for (i=0; i<mat->nrows; i++) {
      for (j=0; j<params->ntvs; j++) 
        fprintf(fpout, "%.4e ", prs[j][i]);
      fprintf(fpout, "\n");
    }
    gk_fclose(fpout);

    gk_fFreeMatrix(&prs, params->ntvs, mat->nrows);
  }
  else if (params->ppr != -1) {
    /* compute the personalized pr from the specified vertex */
    float *pr;

    pr = gk_fsmalloc(mat->nrows, 0.0, "main: pr");

    pr[params->ppr-1] = 1.0;

    niter = gk_rw_PageRank(mat, params->lamda, params->eps, params->niter, pr);
    printf("ppr: %d; niters: %zd\n", params->ppr, niter);

    /* output the computed pr scores */
    fpout = gk_fopen(params->outfile, "w", "main: outfile");
    for (i=0; i<mat->nrows; i++) 
      fprintf(fpout, "%.4e\n", pr[i]);
    gk_fclose(fpout);

    gk_free((void **)&pr, LTERM);
  }
  else {
    /* compute the standard pr */
    int jmax;
    float diff, maxdiff;
    float *pr;

    pr = gk_fsmalloc(mat->nrows, 1.0/mat->nrows, "main: pr");

    niter = gk_rw_PageRank(mat, params->lamda, params->eps, params->niter, pr);
    printf("pr; niters: %zd\n", niter);

    /* output the computed pr scores */
    fpout = gk_fopen(params->outfile, "w", "main: outfile");
    for (i=0; i<mat->nrows; i++) {
      for (jmax=i, maxdiff=0.0, j=mat->rowptr[i]; j<mat->rowptr[i+1]; j++) {
        if ((diff = fabs(pr[i]-pr[mat->rowind[j]])) > maxdiff) {
          maxdiff = diff;
          jmax = mat->rowind[j];
        }
      }
      fprintf(fpout, "%.4e %10zd %.4e %10d\n", pr[i], 
          mat->rowptr[i+1]-mat->rowptr[i], maxdiff, jmax+1);
    }
    gk_fclose(fpout);

    gk_free((void **)&pr, LTERM);
  }

  gk_csr_Free(&mat);

  /* display some final stats */
  print_final_info(params);
}