From ce670dbc723df4988f9be7b2704f97066dfeec4c Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Mon, 15 May 2023 01:32:53 +0800 Subject: feat(exp): Support get random data from queue Signed-off-by: KunoiSayami --- expt_0510.cu | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'expt_0510.cu') diff --git a/expt_0510.cu b/expt_0510.cu index 17e104d..1b95385 100644 --- a/expt_0510.cu +++ b/expt_0510.cu @@ -4,6 +4,7 @@ #include #include #include +#include #include std::vector population_vector, sample_vector, @@ -159,16 +160,39 @@ __global__ void freeStorageStage2() { // cudaFree(cdf_result); } -void read_file(char const *filename, long sample_length, - unsigned long max_number = TEST_LENGTH) { - max_number += sample_length + 256; - auto read_number = 0; +unsigned long randomRow(unsigned long max_value_) { + std::random_device randomDevice; + std::mt19937 mt19937(randomDevice()); + std::uniform_int_distribution dst(0, max_value_); + return dst(mt19937); +} + +void readFile(char const *filename, long sample_length, + unsigned long &total_row, + unsigned long max_number = TEST_LENGTH) { + auto read_number = 0UL; FILE *file = fopen(filename, "r"); assert(file); for (long long i; read_number < max_number && fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) read_number++; + + if (total_row > 0) { + read_number = randomRow(total_row - sample_length - max_number - 256); + total_row = read_number; + // fprintf(stderr, "Skip %lu\n", read_number); + for (long long i; read_number > 0 && fscanf(file, "%lld ", &i) != EOF; + store_into_vector(i)) + read_number--; + } + + read_number = 0; + + auto remain = sample_length + 256; + for (long long i; read_number < remain && fscanf(file, "%lld ", &i) != EOF; + store_into_vector(i)) + read_number++; fclose(file); } @@ -188,6 +212,7 @@ int main(int argc, char const *argv[]) { auto test_size = TEST_LENGTH; auto sample_length = DEFAULT_SAMPLE_LENGTH; + auto total_row = 0UL; if (argc >= 2) { test_size = strtol(argv[1], nullptr, 10); @@ -195,11 +220,14 @@ int main(int argc, char const *argv[]) { if (argc >= 3) { sample_length = pow_for_sample(strtol(argv[2], nullptr, 10)); } + if (argc >= 4) { + total_row = strtol(argv[3], nullptr, 10); + } - read_file("normal_distribution.txt", test_size); + readFile("normal_distribution.txt", test_size, total_row); - printf("population: %zu, test size: %zu, sample length: %zu | ", - population_vector.size(), test_size, sample_length); + printf("population: %zu, skip: %lu, test size: %zu, sample length: %zu | ", + population_vector.size(), total_row, test_size, sample_length); sample_vector = std::vector( population_vector.begin(), population_vector.begin() + sample_length - 2); -- cgit v1.3.1