From 77796af33c0b45189b03839f725899c62db8ae71 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Tue, 30 May 2023 02:09:17 +0800 Subject: fix: Fix read helper bug Signed-off-by: KunoiSayami --- expt_0425.cu | 7 +++---- expt_0529.cu | 2 ++ read_helper.h | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/expt_0425.cu b/expt_0425.cu index c4ea6d5..a1de92f 100644 --- a/expt_0425.cu +++ b/expt_0425.cu @@ -1,11 +1,11 @@ // Experimental content: Branch custom search between binary search -#include "sortlib.cuh" - #include #include #include #include +#define ENABLE_SORT_TEST +#include "sortlib.cuh" std::vector population_vector, sample_vector, le_sample_vector; @@ -57,8 +57,7 @@ __global__ void kernel(unsigned long step, const double slice_size, // printf("%d\n", tid); auto index = (int)(custom_sort.sample_cdf_custom_version( - cudaSampleItem, cudaSampleItem + SAMPLE_LENGTH, - cudaPopulationItem[tid]) / + cudaSampleItem, cudaPopulationItem[tid]) / slice_size) - 1; // printf("%llu %d\n", cudaPopulationItem[tid], index); diff --git a/expt_0529.cu b/expt_0529.cu index 11524a7..985648f 100644 --- a/expt_0529.cu +++ b/expt_0529.cu @@ -1,3 +1,5 @@ +// Experimental content: Print level by cdf + #include "sortlib.cuh" #define READ_NO_OUTPUT #include "read_helper.h" diff --git a/read_helper.h b/read_helper.h index 2e87b0b..d19834a 100644 --- a/read_helper.h +++ b/read_helper.h @@ -46,10 +46,6 @@ public: key_type minValue() const { return min_value; } std::vector population_vector; - void finish_read() { - this->population_vector.push_back(this->max_value); - this->population_vector.push_back(this->min_value); - } static unsigned long randomRow(unsigned long max_value_) { std::random_device randomDevice; @@ -92,15 +88,16 @@ public: read_number++; fclose(file); P_ERR("\r"); - finish_read(); } void split_into(std::vector &sample, std::vector &p) { - sample.resize(sample_length); + sample.resize(sample_length - 2); p.resize(needed_read_length - sample_length); // printf("%zu\n", needed_read_length - sample_length); memcpy(sample.data(), population_vector.data(), - sizeof(key_type) * sample_length); + sizeof(key_type) * (sample_length - 2)); + sample.push_back(this->max_value); + sample.push_back(this->min_value); memcpy(p.data(), population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } @@ -108,7 +105,10 @@ public: void split_into(key_type *&sample, key_type *&p) { sample = new key_type[sample_length]; p = new key_type[needed_read_length - sample_length]; - memcpy(sample, population_vector.data(), sizeof(key_type) * sample_length); + memcpy(sample, population_vector.data(), + sizeof(key_type) * (sample_length - 2)); + sample[sample_length - 2] = this->max_value; + sample[sample_length - 1] = this->min_value; memcpy(p, population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } -- cgit v1.3.1