From e7de21daf6c674633ef1159c2fd042523c1ec32e Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Mon, 12 Jun 2023 00:51:30 +0800 Subject: refector: Rename last year experimental Signed-off-by: KunoiSayami --- expt_220821.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 expt_220821.cpp (limited to 'expt_220821.cpp') diff --git a/expt_220821.cpp b/expt_220821.cpp new file mode 100644 index 0000000..6bbcef0 --- /dev/null +++ b/expt_220821.cpp @@ -0,0 +1,81 @@ +// Experimental content: reliability test +#include "sortlib.h" +#include +#include +#include +#include +#include + +typedef unsigned long long key_type; +std::vector population_vector, sample_vector; +constexpr size_t SAMPLE_LENGTH = 1023, TEST_LENGTH = 1024; +constexpr int MOVE_OFFSET = sizeof(key_type) * 8 - 1; + +auto custom_sort = CustomSort(SAMPLE_LENGTH, MOVE_OFFSET); + +unsigned long long max_value = 0, min_value = 0xfffffffff; +inline void store_into_vector(unsigned long long value) { + if (max_value < value) { + max_value = value; + } + if (min_value > value) { + min_value = value; + } + population_vector.push_back(value); +} + +void valid_sort(std::vector &tmp) { + auto iter_end = population_vector.begin() + SAMPLE_LENGTH + 1024; + for (auto it = population_vector.begin() + SAMPLE_LENGTH; it != iter_end; + it++) { + // long std_search = + // std::lower_bound(tmp.begin(), tmp.end(), *it) - tmp.begin(); + long std_search = custom_sort.original_binary_search( + tmp.data(), tmp.data() + tmp.size(), *it) - + tmp.data(); + + auto cuda_binary_search1 = + custom_sort.binary_search(sample_vector.data(), *it) - + sample_vector.data(); + auto cuda_binary_search = + custom_sort.calculate_location(cuda_binary_search1) - 1; + /*printf("%ld:%ld %llu:%llu\n", std_search, cuda_binary_search, + *(tmp.begin() + std_search), + *(cuda_binary_search + sample_vector.begin()));*/ + printf("%ld:%ld %llu %llu %llu\n", std_search, cuda_binary_search, *it, + *(tmp.data() + std_search), + *(cuda_binary_search1 + sample_vector.data())); + // assert(*it > *(cuda_binary_search1 + sample_vector.data())); + // assert(std_search == cuda_binary_search); + } +} + +int main() { + FILE *file = fopen("normal_distribution.txt", "r"); + assert(file); + for (long long i; fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) + ; + fclose(file); + + std::vector tmp(population_vector.begin(), + population_vector.begin() + SAMPLE_LENGTH - 2); + tmp.push_back(max_value); + tmp.push_back(min_value); + + std::sort(tmp.begin(), tmp.end()); + + sample_vector.resize(SAMPLE_LENGTH); + for (size_t i = 0; i < SAMPLE_LENGTH; i++) { + sample_vector[custom_sort.calculate_location_inverse(i) - 1] = tmp[i]; + auto location = custom_sort.calculate_location(i); + auto location2 = custom_sort.calculate_location_inverse(location - 1); + // printf("%zu %zu\n", location, location2); + assert(location2 - 1 == i); + } + // valid_sort(tmp); + /*for (auto element : sample_vector) { + printf("%d ", element); + }*/ + valid_sort(tmp); + puts(""); +} \ No newline at end of file -- cgit v1.3.1