Commit 4c4b7204 authored by Tat Dat Duong's avatar Tat Dat Duong
Browse files

chore: remove duplicate mesh implementation

parent 311d7268
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ template <
    class BTree,
    typename Device, typename BenchDevice>
void executeBenchRun() {
  std::vector<std::string> suites = {"5"};
  std::vector<std::string> suites = {"1", "2", "3", "4", "5"};

  for (auto const &suite : suites) {
    int attempts = 1;
@@ -219,6 +219,7 @@ int main(void) {
  // std::cout << "----" << std::endl;

  executeDeviceBench<BLinkTree>();
  executeDeviceBench<BPlusTree>();

  return 0;
}
 No newline at end of file

implementation/test/mesh.cu

deleted100644 → 0
+0 −161
Original line number Diff line number Diff line
#include <TNL/Containers/Array.h>
#include <TNL/Containers/StaticArray.h>
#include <TNL/Containers/Vector.h>
#include <bits/stdint-uintn.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <sstream>
#include <string>
#include <utility>

#include "BLinkTree/Default.hpp"
#include "BPlusTree/Default.hpp"
#include "BTreeContainer/Default.hpp"
#include "TNL/Algorithms/ParallelFor.h"
#include "TNL/Cuda/CudaCallable.h"
#include "TNL/Devices/Cuda.h"
#include <TNL/Containers/Array.h>

const auto limit = std::numeric_limits<double>::epsilon();

template <typename T> std::string toStr(const T &t) {
  std::ostringstream os;
  os << t;
  return os.str();
}

using Cell = TNL::Containers::StaticArray<4, int>;

struct Point {
  double x;
  double y;
  double z;

  __cuda_callable__ friend bool operator==(const Point &a, const Point &b) {
    return (a.x - b.x) <= limit || (a.y - b.y) <= limit || (a.z - b.z) <= limit;
  }

  friend std::ostream &operator<<(std::ostream &output, const Point &item) {
    output << item.x << ", " << item.y << ", " << item.z;
    return output;
  }
};

using CellCoords = TNL::Containers::StaticArray<4, Point>;

template <typename Device>
void loadCells(const std::string &name, TNL::Containers::Array<Cell, Device> &result) {
  TNL::Containers::Array<Cell, Devices::Host> hostCells;
  std::ifstream file(name);
  std::string tmp;

  size_t count = 0;
  file >> tmp >> count >> tmp;

  hostCells.setSize(count);

  for (int i = 0; i < count; ++i) {
    Cell cell;
    file >> cell[0] >> cell[1] >> cell[2] >> cell[3];
    hostCells.setElement(i, cell);
  }
  result = hostCells;
}

template <typename Device>
void loadPoints(const std::string &name, TNL::Containers::Array<int, Device> &keys,
                TNL::Containers::Array<Point, Device> &values) {
  TNL::Containers::Array<int, Devices::Host> hostKeys;
  TNL::Containers::Array<Point, Devices::Host> hostValues;
  std::ifstream file(name);
  std::string tmp;

  size_t count = 0;
  file >> tmp >> count >> tmp;

  hostKeys.setSize(count);
  hostValues.setSize(count);

  for (size_t i = 0; i < count; ++i) {
    Point point;
    file >> point.x >> point.y >> point.z;

    hostKeys.setElement(i, i);
    hostValues.setElement(i, point);
  }

  keys = hostKeys;
  values = hostValues;
};

int main(void) {
  std::ios::sync_with_stdio(false);
  std::string index = toStr(5);

  using Device = Devices::Host;

  TNL::Containers::Array<Cell, Device> cells;
  TNL::Containers::Array<int, Device> keys;
  TNL::Containers::Array<Point, Device> values;
  TNL::Containers::Array<CellCoords, Device> expect;
  TNL::Containers::Array<CellCoords, Device> actual;

  printf("Loading cells\n");
  loadCells("./test/mesh/cube1m_" + index + "_cells.txt", cells);

  printf("Loading points\n");
  loadPoints("./test/mesh/cube1m_" + index + "_points.txt", keys, values);

  printf("Initializing\n");

  const int cellCount = cells.getSize();
  BTreeContainer<int, Point, 15, Device, BPlusTree> points(getContainerSize(keys.getSize(), 15));
  expect.setSize(cellCount);
  actual.setSize(cellCount);

  auto cellsView = cells.getConstView();
  auto valuesView = values.getConstView();
  auto expectView = expect.getView();

  TNL::Algorithms::ParallelFor2D<Device>::exec(0, 0, cellCount, 4,
                                               [=] __cuda_callable__(int i, int j) mutable {
                                                 expectView[i][j] = valuesView[cellsView[i][j]];
                                               });

  printf("Init\n");
  points.init();
  printf("Inserting\n");
  points.insert(keys, values);

  TNL::Containers::Array<int, Device> query(cellCount * 4);
  auto queryView = query.getView();
  TNL::Algorithms::ParallelFor2D<Device>::exec(
      0, 0, cellCount, 4,
      [=] __cuda_callable__(int i, int j) mutable { queryView[i * 4 + j] = cellsView[i][j]; });

  TNL::Containers::Array<Point, Device> results(query.getSize());
  TNL::Containers::Array<bool, Device> mask(query.getSize());

  printf("Find\n");
  points.find(query, results, mask);

  printf("Compare\n");
  auto actualView = actual.getView();
  auto resultView = results.getConstView();
  TNL::Algorithms::ParallelFor2D<Device>::exec(
      0, 0, cellCount, 4,
      [=] __cuda_callable__(int i, int j) mutable { actualView[i][j] = resultView[i * 4 + j]; });

  TNL_ASSERT_TRUE(
      TNL::Algorithms::Reduction<Device>::reduce(
          0, cellCount,
          [=] __cuda_callable__(int i) -> bool { return actualView[i] == expectView[i]; },
          [] __cuda_callable__(const bool &a, const bool &b) { return a && b; }, true),
      "Actual matches expect");

  return 0;
}
 No newline at end of file
+0 −1313

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −396
Original line number Diff line number Diff line
POINTS 395 double
0 0 0.166666666666667
0 0 0
0 0 1
0 0 0.833333333333333
0 0.0833333333333333 0.916666666666667
0 0 0.333333333333333
0 0 0.666666666666667
0 0.114583333333333 0.760416666666667
0 1 0
0 0.166666666666667 0
0 0.0833333333333333 0.0833333333333333
0 0.270833333333333 0.104166666666667
0 0.333333333333333 0
0 0.104166666666667 0.270833333333333
0 0.5 0
0 0.666666666666667 0
0 0.166666666666667 1
0 1 1
0 0.229166666666667 0.854166666666667
0 0.291666666666667 0.708333333333333
0 0.125 0.583333333333333
0 0.125 0.416666666666667
0 0 0.5
0 0.25 0.5
0 0.371527666666667 0.586805666666667
0 0.361111 0.395833333333333
0 0.71875 0.0729166666666667
0 0.916666666666667 0.0833333333333333
0 0.833333333333333 0
0 1 0.333333333333333
0 1 0.166666666666667
0 0.2951389 0.2818287
0 0.347222333333333 0.180555566666667
0 0.208333333333333 0.208333333333333
0 0.458333333333333 0.125
0 0.604166666666667 0.145833333333333
0 1 0.833333333333333
0 1 0.5
0 1 0.666666666666667
0 0.895833333333333 0.729166666666667
0 0.916666666666667 0.916666666666667
0 0.791666666666667 0.791666666666667
0 0.729166666666667 0.895833333333333
0 0.833333333333333 1
0 0.333333333333333 1
0 0.5 1
0 0.666666666666667 1
0 0.395833333333333 0.854166666666667
0 0.430555666666667 0.75
0 0.494213 0.621527666666667
0 0.5 0.5
0 0.569444333333333 0.25
0 0.416666666666667 0.25
0 0.483121 0.403067
0 0.708333333333333 0.291666666666667
0 0.854166666666667 0.229166666666667
0 0.875 0.583333333333333
0 0.875 0.416666666666667
0 0.598379666666667 0.371527666666667
0 0.75 0.5
0 0.693287 0.706597333333333
0 0.583333333333333 0.75
0 0.598862 0.489872666666667
0 0.638889 0.604166666666667
0 0.625 0.875
0 0.508680666666667 0.887152666666667
0.166666666666667 0 0
0.166666666666667 0 1
0.135416666666667 0 0.84375
0.0677083333333333 0 0.755208333333333
0.5 0 0
0.0677083333333333 0 0.244791666666667
0.270833333333333 0 0.145833333333333
0.135416666666667 0 0.15625
0.333333333333333 0 0
0.270833333333333 0 0.854166666666667
0.333333333333333 0 1
0.104166666666667 0 0.395833333333333
0.104166666666667 0 0.604166666666667
0.208333333333333 0 0.291666666666667
0.5 0 1
0.666666666666667 0 1
0.208333333333333 0 0.708333333333333
0.25 0 0.5
0.361111 0 0.395833333333333
0.361111 0 0.604166666666667
1 0 1
0.559027666666667 0 0.0902777666666667
0.666666666666667 0 0
0.729166666666667 0 0.104166666666667
0.833333333333333 0 0
0.916666666666667 0 0.0833333333333333
1 0 0.166666666666667
1 0 0
1 0 0.333333333333333
0.416666666666667 0 0.25
0.458333333333333 0 0.125
0.618055666666667 0 0.180555566666667
0.416666666666667 0 0.75
0.375 0 0.875
0.491319333333333 0 0.887152666666667
1 0 0.5
1 0 0.833333333333333
1 0 0.666666666666667
0.569444333333333 0 0.361111
0.645833333333333 0 0.476852
0.916666666666667 0 0.916666666666667
0.833333333333333 0 1
0.770833333333333 0 0.854166666666667
0.604166666666667 0 0.854166666666667
0.569444333333333 0 0.75
0.5 0 0.5
0.483121 0 0.596933
0.701967666666667 0 0.2835648
0.791666666666667 0 0.208333333333333
0.895833333333333 0 0.270833333333333
0.875 0 0.375
0.75 0 0.416666666666667
0.598379666666667 0 0.628472333333333
0.927083333333333 0 0.71875
0.708333333333333 0 0.708333333333333
0.75 0 0.569444333333333
0.887152666666667 0 0.491319333333333
0.854166666666667 0 0.604166666666667
0.0833333333333333 0.0833333333333333 0
0.078125 0.253472233333333 0
0.270833333333333 0.104166666666667 0
0.0833333333333333 0.916666666666667 0
0.166666666666667 1 0
0.755208333333333 0.0677083333333333 0
0.604166666666667 0.104166666666667 0
0.15625 0.340277666666667 0
0.1171875 0.468171333333333 0
0.114583333333333 0.760416666666667 0
0.458333333333333 0.125 0
0.208333333333333 0.208333333333333 0
0.347222333333333 0.180555566666667 0
0.125 0.583333333333333 0
0.25 0.5 0
0.3125 0.347222333333333 0
0.416666666666667 0.25 0
0.530382 0.2097801 0
0.333333333333333 1 0
0.84375 0.135416666666667 0
1 0.166666666666667 0
0.229166666666667 0.854166666666667 0
1 0.333333333333333 0
0.395833333333333 0.854166666666667 0
0.708333333333333 0.208333333333333 0
0.854166666666667 0.270833333333333 0
0.875 0.375 0
0.291666666666667 0.708333333333333 0
0.364583333333333 0.474537 0
0.339409666666667 0.614294 0
0.477430666666667 0.368634333333333 0
0.572916666666667 0.336805666666667 0
0.447916666666667 0.690972333333333 0
0.5 1 0
1 0.5 0
0.75 0.416666666666667 0
0.868345 0.495659666666667 0
0.508680666666667 0.887152666666667 0
0.5 0.5 0
0.627941666666667 0.480179333333333 0
0.666666666666667 1 0
0.934172333333333 0.581163333333333 0
1 0.666666666666667 0
0.642650333333333 0.589409666666667 0
0.809027666666667 0.614583333333333 0
0.583333333333333 0.75 0
0.729166666666667 0.895833333333333 0
0.625 0.875 0
1 0.833333333333333 0
0.916666666666667 0.916666666666667 0
0.833333333333333 1 0
0.895833333333333 0.729166666666667 0
0.73247 0.677879 0
0.791666666666667 0.791666666666667 0
1 1 0
0.0833333333333333 0.0833333333333333 1
0.0694444333333333 0.25 1
0.253472233333333 0.078125 1
0.208333333333333 0.208333333333333 1
0.5 0.125 1
0.1388889 0.333333333333333 1
0.0833333333333333 0.916666666666667 1
0.166666666666667 1 1
0.340277666666667 0.15625 1
0.347222333333333 0.3125 1
0.755208333333333 0.0677083333333333 1
0.604166666666667 0.104166666666667 1
0.84375 0.135416666666667 1
1 0.166666666666667 1
0.5 0.25 1
0.0729166666666667 0.71875 1
0.125 0.458333333333333 1
0.145833333333333 0.604166666666667 1
0.25 0.416666666666667 1
0.474537 0.364583333333333 1
0.229166666666667 0.854166666666667 1
0.333333333333333 1 1
0.708333333333333 0.208333333333333 1
0.409818666666667 0.465277666666667 1
0.854166666666667 0.270833333333333 1
0.875 0.375 1
1 0.333333333333333 1
0.604166666666667 0.361111 1
0.291666666666667 0.708333333333333 1
0.309027766666667 0.552083333333333 1
0.5 0.5 1
0.395833333333333 0.854166666666667 1
0.5 1 1
0.75 0.416666666666667 1
0.676745666666667 0.534561333333333 1
0.887152666666667 0.491319333333333 1
1 0.5 1
0.5 0.673611 1
0.586805666666667 0.615740666666667 1
0.718460666666667 0.626350333333333 1
0.604166666666667 0.854166666666667 1
0.666666666666667 1 1
0.854166666666667 0.604166666666667 1
1 0.666666666666667 1
0.708333333333333 0.708333333333333 1
0.71875 0.927083333333333 1
0.854166666666667 0.770833333333333 1
1 0.833333333333333 1
0.916666666666667 0.916666666666667 1
0.833333333333333 1 1
1 1 1
0.0833333333333333 1 0.0833333333333333
0.0833333333333333 1 0.916666666666667
0.145833333333333 1 0.395833333333333
0.145833333333333 1 0.229166666666667
0.28125 1 0.0729166666666667
0.395833333333333 1 0.145833333333333
0.0729166666666667 1 0.71875
0.145833333333333 1 0.604166666666667
0.229166666666667 1 0.854166666666667
0.3263889 1 0.5
0.291666666666667 1 0.291666666666667
0.447916666666667 1 0.309027766666667
0.522569333333333 1 0.1545139
0.625 1 0.125
0.291666666666667 1 0.708333333333333
0.398727 1 0.604166666666667
0.395833333333333 1 0.854166666666667
0.430555666666667 1 0.75
0.5 1 0.5
0.515673333333333 1 0.586805666666667
0.534722333333333 1 0.410783333333333
0.583333333333333 1 0.25
0.729166666666667 1 0.145833333333333
0.864583333333333 1 0.15625
0.522569333333333 1 0.845486
0.625 1 0.875
0.583333333333333 1 0.75
0.638889 1 0.604166666666667
0.635416666666667 1 0.476852
0.6875 1 0.361111
0.791666666666667 1 0.291666666666667
1 1 0.166666666666667
0.932291666666667 1 0.244791666666667
0.729166666666667 1 0.895833333333333
0.791666666666667 1 0.791666666666667
0.741898 1 0.678819333333333
0.75 1 0.5
0.895833333333333 1 0.395833333333333
1 1 0.333333333333333
0.916666666666667 1 0.916666666666667
0.895833333333333 1 0.729166666666667
0.875 1 0.583333333333333
1 1 0.5
1 1 0.833333333333333
1 1 0.666666666666667
1 0.0833333333333333 0.916666666666667
1 0.104166666666667 0.270833333333333
1 0.0833333333333333 0.0833333333333333
1 0.253472233333333 0.078125
1 0.125 0.375
1 0.208333333333333 0.208333333333333
1 0.340277666666667 0.15625
1 0.1545139 0.477430666666667
1 0.25 0.416666666666667
1 0.145833333333333 0.604166666666667
1 0.145833333333333 0.770833333333333
1 0.28125 0.927083333333333
1 0.347222333333333 0.3125
1 0.356770666666667 0.443576333333333
1 0.5 0.125
1 0.5 0.25
1 0.604166666666667 0.104166666666667
1 0.309027766666667 0.552083333333333
1 0.291666666666667 0.708333333333333
1 0.395833333333333 0.854166666666667
1 0.5 0.5
1 0.521219 0.384838
1 0.755208333333333 0.0677083333333333
1 0.638889 0.3125
1 0.708333333333333 0.208333333333333
1 0.84375 0.135416666666667
1 0.627314666666667 0.434027666666667
1 0.604166666666667 0.854166666666667
1 0.5 0.673611
1 0.586805666666667 0.615740666666667
1 0.75 0.416666666666667
1 0.854166666666667 0.270833333333333
1 0.71875 0.927083333333333
1 0.725405 0.577739333333333
1 0.708333333333333 0.708333333333333
1 0.875 0.375
1 0.845486 0.477430666666667
1 0.916666666666667 0.916666666666667
1 0.854166666666667 0.770833333333333
1 0.854166666666667 0.604166666666667
0.132864766666667 0.112200366666667 0.878546666666667
0.123392733333333 0.163346166666667 0.709829
0.0868652 0.192312133333333 0.114902166666667
0.100911466666667 0.233411233333333 0.380201666666667
0.205595833333333 0.142992966666667 0.2431486
0.388151333333333 0.142189233333333 0.132247733333333
0.1779755 0.301700533333333 0.840829333333333
0.291647233333333 0.1447536 0.780925333333333
0.107773233333333 0.335158666666667 0.622668666666667
0.2018229 0.1716836 0.478574333333333
0.409432333333333 0.136330866666667 0.432055333333333
0.373363 0.118840233333333 0.606035666666667
0.2903716 0.303210966666667 0.652455333333333
0.643310333333333 0.113920266666667 0.118851933333333
0.849582333333333 0.0886763333333333 0.130624166666667
0.123732066666667 0.363109666666667 0.431841
0.1203092 0.779615666666667 0.147680933333333
0.180559766666667 0.385068333333333 0.1780962
0.309365366666667 0.290209066666667 0.316490533333333
0.195329933333333 0.606946666666667 0.158016733333333
0.527498 0.180663266666667 0.2546999
0.570604333333333 0.254398 0.1261457
0.375705 0.293853033333333 0.1134835
0.134893166666667 0.868629333333333 0.666142
0.484375 0.193678866666667 0.775408666666667
0.15625 0.771804 0.848325333333333
0.158717866666667 0.498777 0.766031666666667
0.356025333333333 0.374283333333333 0.830094333333333
0.174166966666667 0.514377666666667 0.542005
0.411872666666667 0.326619433333333 0.464318666666667
0.645008 0.1382743 0.452308666666667
0.843244 0.141799433333333 0.875397666666667
0.655639333333333 0.218935166666667 0.815813333333333
0.547950666666667 0.246778866666667 0.622002
0.398239666666667 0.428765333333333 0.676145
0.813367 0.1588801 0.287602233333333
0.837024333333333 0.240235133333333 0.149298966666667
0.846354 0.2101207 0.456136
0.812067333333333 0.168045433333333 0.638021333333333
0.187291266666667 0.557798333333333 0.36734
0.157973033333333 0.799432333333333 0.400078666666667
0.256881133333333 0.835627666666667 0.2191763
0.446220666666667 0.861604666666667 0.151009
0.783999666666667 0.391594 0.1299483
0.412921666666667 0.474322 0.221943566666667
0.663047666666667 0.350418 0.3002855
0.416932333333333 0.684056333333333 0.1562433
0.544085666666667 0.393211 0.1190117
0.197916666666667 0.689441 0.623734
0.3107894 0.891481666666667 0.5804
0.3111994 0.824736 0.797229333333333
0.547907 0.389798333333333 0.833311666666667
0.248205766666667 0.602548 0.884484333333333
0.435137 0.580310666666667 0.80398
0.511132333333333 0.533772 0.510939
0.695389 0.360219 0.530862333333333
0.805197666666667 0.377927 0.797785666666667
0.656520666666667 0.504088666666667 0.680343333333333
0.843305666666667 0.429385666666667 0.354581
0.879087666666667 0.43099 0.572886333333333
0.452722 0.814224333333333 0.37721
0.808117666666667 0.556827333333333 0.1862341
0.645067666666667 0.858356 0.166249266666667
0.637155666666667 0.592231333333333 0.220526633333333
0.864432333333333 0.866542 0.0941157333333333
0.492135666666667 0.829032 0.639440333333333
0.493253666666667 0.797820666666667 0.856291666666667
0.623358333333333 0.560652666666667 0.874013333333333
0.796717333333333 0.564745333333333 0.875899666666667
0.673172666666667 0.689957666666667 0.737854
0.661144666666667 0.875461666666667 0.504337
0.754635333333333 0.634669 0.517259
0.874577333333333 0.60858 0.701975666666667
0.921646666666667 0.617999 0.434912666666667
0.847472 0.799295333333333 0.252498266666667
0.680431333333333 0.888693 0.801821333333333
0.876199666666667 0.745632333333333 0.858019
0.848459666666667 0.833562 0.685681
0.880153 0.838135 0.512566
0.859583333333333 0.899597333333333 0.886078666666667
+0 −3698

File deleted.

Preview size limit exceeded, changes collapsed.

Loading