From d3cc600b6cb6476181720ad78ae93c9d31d066a4 Mon Sep 17 00:00:00 2001 From: Tobias Reiter Date: Fri, 8 Nov 2024 12:35:48 +0100 Subject: [PATCH] Remove KD tree benchmark example --- examples/KDTreeBenchmark/CMakeLists.txt | 7 -- examples/KDTreeBenchmark/KDTreeBenchmark.cpp | 107 ------------------- 2 files changed, 114 deletions(-) delete mode 100644 examples/KDTreeBenchmark/CMakeLists.txt delete mode 100644 examples/KDTreeBenchmark/KDTreeBenchmark.cpp diff --git a/examples/KDTreeBenchmark/CMakeLists.txt b/examples/KDTreeBenchmark/CMakeLists.txt deleted file mode 100644 index 6dafef19..00000000 --- a/examples/KDTreeBenchmark/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -project(KDTreeBenchmark LANGUAGES CXX) - -add_executable(${PROJECT_NAME} "${PROJECT_NAME}.cpp") -target_link_libraries(${PROJECT_NAME} PRIVATE ViennaPS) - -add_dependencies(ViennaPS_Examples ${PROJECT_NAME}) -viennacore_setup_bat(${PROJECT_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) diff --git a/examples/KDTreeBenchmark/KDTreeBenchmark.cpp b/examples/KDTreeBenchmark/KDTreeBenchmark.cpp deleted file mode 100644 index 1cb75c3a..00000000 --- a/examples/KDTreeBenchmark/KDTreeBenchmark.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include - -#ifdef _OPENMP -#include -#endif - -#include -#include - -inline double getTime() { -#ifdef _OPENMP - return omp_get_wtime(); -#else - return std::chrono::duration( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count(); -#endif -} - -template -std::vector> generatePoints(unsigned N, unsigned D) { - std::random_device rd; - std::vector> data(N); - for (auto &d : data) - d.resize(D); - -#pragma omp parallel default(none) shared(N, D, data, rd) - { - auto engine = std::default_random_engine(rd()); - std::uniform_real_distribution<> d{-10., 10.}; -#pragma omp for - for (int i = 0; i < N; ++i) { - std::vector point; - point.reserve(D); - std::generate_n(std::back_inserter(point), D, - [&d, &engine]() { return d(engine); }); - data[i].swap(point); - } - } - return data; -} - -using namespace viennacore; - -int main(int argc, char *argv[]) { - using NumericType = double; - static constexpr int D = 3; - - // The number of points in the tree - unsigned N = 1'000'000; - if (argc > 1) { - int tmp = std::atoi(argv[1]); - if (tmp > 0) - N = static_cast(tmp); - } - - // The number of points to query the tree with - unsigned M = 100'000; - if (argc > 2) { - int tmp = std::atoi(argv[2]); - if (tmp > 0) - M = static_cast(tmp); - } - - // The number repetitions - unsigned repetitions = 1; - if (argc > 3) { - int tmp = std::atoi(argv[3]); - if (tmp > 0) - repetitions = static_cast(tmp); - } - - // Training Point generation - std::cout << "Generating Training Points...\n"; - auto points = generatePoints(N, D); - - // Testing points generation - std::cout << "Generating Testing Points...\n"; - auto testPoints = generatePoints(M, D); - - { - std::cout << "Growing Tree...\n"; - SmartPointer> tree = nullptr; - auto startTime = getTime(); - for (unsigned i = 0; i < repetitions; ++i) { - tree = SmartPointer>::New(points); - tree->build(); - } - auto endTime = getTime(); - std::cout << "Tree grew in " << (endTime - startTime) / repetitions - << "s\n"; - - // Nearest Neighbors - std::cout << "Finding Nearest Neighbors...\n"; - startTime = getTime(); - for (unsigned i = 0; i < repetitions; ++i) { - for (const auto &pt : testPoints) [[maybe_unused]] - auto result = tree->findNearest(pt); - } - endTime = getTime(); - - std::cout << M << " nearest neighbor queries completed in " - << (endTime - startTime) / repetitions << "s\n"; - } -}