diff options
Diffstat (limited to 'expt_0529.cu')
| -rw-r--r-- | expt_0529.cu | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/expt_0529.cu b/expt_0529.cu new file mode 100644 index 0000000..11524a7 --- /dev/null +++ b/expt_0529.cu @@ -0,0 +1,71 @@ +#include "sortlib.cuh" +#define READ_NO_OUTPUT +#include "read_helper.h" + +long pow_for_sample(long n) { + auto x = 2; + for (int i = 1; i < n; i++) { + x *= 2; + } + return x - 1; +} + +static unsigned trailing_zeroes(size_t index) { + constexpr auto block_size = 2; + unsigned bits = 0; + auto x = index / block_size; + + if (x) { + while (x % block_size == 0) { + ++bits; + x /= block_size; + } + } + return bits; +} + +inline double calcSliceSize(size_t insertion_size) { + return 1.0 / (double)insertion_size; +} + +constexpr auto RESULT_LENGTH = 35; + +int main(int argc, char const *argv[]) { + + if (argc != 3) { + printf("Usage %s [sample(pow)] [population]\n", argv[0]); + return 1; + } + + auto sample_length = pow_for_sample(strtol(argv[1], nullptr, 10)); + auto population_length = strtol(argv[2], nullptr, 10); + + printf("sample length: %ld, population length: %ld\n", sample_length, + population_length); + + ReadHelper readHelper("normal_distribution.txt", sample_length, 0); + readHelper.readFile(nullptr); + + std::vector<key_type> sample, population; + std::vector<unsigned int> result(RESULT_LENGTH); + readHelper.split_into(sample, population); + rebuildSort(sample); + + auto scale_size = calcSliceSize(population_length); + + auto sort = CustomSort(sample_length, sizeof(key_type) * 8); + + for (auto element : readHelper.population_vector) { + auto ret = sort.sample_cdf_custom_version(sample.data(), element); + auto cdf_index = ret / scale_size; + auto index = trailing_zeroes((size_t)cdf_index); + result[index]++; + } + + for (int i = 0; i < 32; i++) { + if (!result[i]) { + continue; + } + printf("%d: %d\n", i, result[i]); + } +} |
