Beispiel #1
0
  SpaceSearcher(TIter t_begin, TIter t_end, T2Point t2p)
      : mc_(), c2t_(), t2p_(t2p) {

    // For performance checks
    CS207::Clock clock;
    clock.start();

    // Determine pmin and pmax, i.e., the minimum and maximum corners
    // for the bounding box.
    Point pmin = t2p_(*t_begin);
    Point pmax = pmin;
    for (auto it = t_begin; it != t_end; ++it) {
      Point p = t2p_(*it);
      for (int i = 0; i < 3; ++i) {
        if      (p[i] < pmin[i]) pmin[i] = p[i];
        else if (p[i] > pmax[i]) pmax[i] = p[i];
      }
    }

    // Create MortonCoder instance.
    bounding_box_ = BoundingBox(pmin, pmax);
    mc_ = MortonCoderType(bounding_box_);

    // Map Morton codes to data items.
    c2t_.clear();
    c2t_.resize(mc_.end_code);
    for (auto it = t_begin; it != t_end; ++it) {
      Point p = t2p_(*it);
      c2t_[mc_.code(p)].push_back(*it);
    }

    // Uncomment to print some info
#if 0
    size_type item_count = 0;
    size_type max_items = 0;
    for (auto it = c2t_.begin(); it != c2t_.end(); ++it) {
      auto& items = *it;
      item_count += items.size();
      if (items.size() > max_items)
        max_items = items.size();
    }
    std::cout << "Construction time: " << clock.seconds() << " seconds.\n";
    std::cout << "Total number of elements = " << item_count << std::endl;
    std::cout << "Total number of cells = " << mc_.end_code << std::endl;
    std::cout << "Max. number of elements per cell = " << max_items << std::endl;
    std::cout << std::endl;
#endif
  }
Beispiel #2
0
int main() {
    CS207::Clock timer;
    unsigned N = 512;
    Matrix A(N, N, 1.23);
    Matrix B(N, N, 2);
    Matrix C(N, N, 5.76);
    double alpha = 3.14;

    // Print out the type information of M
    std::cout << "Type of Expr:\n  "
              << 2.73*(A*B) + alpha*(alpha*A + B + A(0,0)*C) << std::endl;

    timer.start();
    Matrix D = 2.73*(A*B) + alpha*(alpha*A + B + A(0,0)*C);
    double eval_time = timer.seconds();
    std::cout << "Compute Time: " << eval_time << " seconds" << std::endl;
}
Beispiel #3
0
int main()
{
  while (!cin.eof()) {
    // How many primes to test? And should we print them?
    cerr << "Input Number: ";
    int n = 0;
    CS207::getline_parsed(cin, n);
    if (n <= 0)
      break;

    cerr << "Print Primes (y/n): ";
    char confirm = 'n';
    CS207::getline_parsed(cin, confirm);
    bool print_primes = (confirm == 'y' || confirm == 'Y');

    CS207::Clock timer;

    // Loop and count primes from 2 up to n
    int num_primes = 0;
    for (int i = 2; i <= n; ++i) {
      if (is_prime(i)) {
        ++num_primes;
        if (print_primes)
          cout << i << endl;
      }
    }

    double elapsed_time = timer.seconds();

    cout << "There are " << num_primes
         << " primes less than or equal to " << n << ".\n"
         << "Found in " << (1000 * elapsed_time) << " milliseconds.\n\n";
  }

  return 0;
}