Esempio n. 1
0
File: main.cpp Progetto: CCJY/coliru
int main() {
    Container_t container;
    auto & sequenced = container.get<0>();

    fillFront(sequenced);

    stabled_ordered(container, [](Entry const& entry) {
            cout << entry.nonUniqueInt << ": " << entry.somethingExtra << endl;
        });

    cout << endl;
    container.clear();

    fillBack(sequenced);
    stabled_ordered(container, [](Entry const& entry) {
            cout << entry.nonUniqueInt << ": " << entry.somethingExtra << endl;
        });
}
Esempio n. 2
0
int main()
{
  // number of boxes
  int numberofboxes = N * N * N;

  int code = (2 << 1) + (2 << 0) + (2 << 1);
  std::cerr << code << "\n";

  // setup AOS form of boxes
  std::vector<Vector3D<Precision>> uppercorners(numberofboxes);
  std::vector<Vector3D<Precision>> lowercorners(numberofboxes);

  // setup same in mixed array of corners ... upper-lower-upper-lower ...
  std::vector<Vector3D<Precision>> corners(2 * numberofboxes);

  // setup SOA form of boxes -- the memory layout should probably rather be SOA6D
  Vector3D<kVc::precision_v> *VcCorners = new Vector3D<kVc::precision_v>[ 2 * numberofboxes / kVc::precision_v::Size ];

  int counter1 = 0;
  int counter2 = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        lowercorners[counter1] = Vector3D<Precision>(i, j, k);
        uppercorners[counter1] = Vector3D<Precision>(i + delta, j + delta, k + delta);

        corners[counter2] = lowercorners[counter1];
        counter2++;
        corners[counter2] = uppercorners[counter1];
        counter2++;

        counter1++;
      }
    }
  }

  // print boxes
  for (int i = 0; i < numberofboxes; ++i) {
    // std::cerr << "# " << i << " lower " << lowercorners[i] << " " << uppercorners[i] << "\n";
  }

  // set up VcCorners
  counter2 = 0;
  for (int i = 0; i < numberofboxes; i += kVc::precision_v::Size) {
    Vector3D<kVc::precision_v> lower;
    Vector3D<kVc::precision_v> upper;
    // assign by components
    for (int k = 0; k < kVc::precision_v::Size; ++k) {
      lower.x()[k] = lowercorners[i + k].x();
      lower.y()[k] = lowercorners[i + k].y();
      lower.z()[k] = lowercorners[i + k].z();
      upper.x()[k] = uppercorners[i + k].x();
      upper.y()[k] = uppercorners[i + k].y();
      upper.z()[k] = uppercorners[i + k].z();
    }
    // std::cerr << lower << "\n";
    // std::cerr << upper << "\n";
    VcCorners[counter2++] = lower;
    VcCorners[counter2++] = upper;
  }
  std::cerr << "assigned " << counter2 << "Vc vectors\n";

  // constructing samples
  std::vector<Vector3D<Precision>> points(SZ);
  std::vector<Vector3D<Precision>> directions(SZ);
  for (int i = 0; i < SZ; ++i) {
    points[i]     = Vector3D<Precision>(N * delta + 0.1, N * delta + 0.1, N * delta + 0.1);
    directions[i] = volumeUtilities::SampleDirection();
  }

  Container_t hitlist;
  hitlist.resize(2 * N);

  Stopwatch timer;
  int hits                    = 0;
  double meanfurthestdistance = 0;

  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                 ,
                                 hitlist
#endif
                                 );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Cached times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
    hitlist.clear();
    hits += benchNoCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                   ,
                                   hitlist
#endif
                                   );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
#endif
  }
  timer.Stop();
  std::cerr << "Ordinary times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingAndVector(points[i], directions[i], VcCorners, numberofboxes / kVc::precision_v::Size
#ifdef SORTHITBOXES
                                  ,
                                  hitlist
#endif
                                  );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << "VECTORHITLIST" << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Vector times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  return 0;
}