summaryrefslogtreecommitdiff
path: root/expt_0510.cu
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-05-15 01:32:53 +0800
committerKunoiSayami <[email protected]>2023-05-15 01:32:53 +0800
commitce670dbc723df4988f9be7b2704f97066dfeec4c (patch)
treef1dd4d86f0df1990b8ee39981d0e05af8b1bf869 /expt_0510.cu
parent614638fc122f31fcb6c5336002dda9aca4e0acc6 (diff)
feat(exp): Support get random data from queue
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'expt_0510.cu')
-rw-r--r--expt_0510.cu42
1 files changed, 35 insertions, 7 deletions
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 <algorithm>
#include <cassert>
#include <cstdio>
+#include <random>
#include <vector>
std::vector<unsigned long long> 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<std::mt19937::result_type> 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<key_type>(
population_vector.begin(), population_vector.begin() + sample_length - 2);