diff options
| -rw-r--r-- | expt_0525.cu | 13 | ||||
| -rw-r--r-- | read_helper.h | 35 |
2 files changed, 27 insertions, 21 deletions
diff --git a/expt_0525.cu b/expt_0525.cu index af024bc..c780c37 100644 --- a/expt_0525.cu +++ b/expt_0525.cu @@ -660,18 +660,19 @@ int main(int argc, char **argv) { exit(1); } - auto sample_length = strtol(argv[2], nullptr, 10); + auto sample_length = strtol(argv[1], nullptr, 10); auto insertion_length = strtol(argv[2], nullptr, 10); - auto search_length = strtol(argv[2], nullptr, 10); - auto total_row = 0UL; + auto search_length = strtol(argv[3], nullptr, 10); + printf("Sample: %ld, Insertion: %ld, Search: %ld\n", sample_length, + insertion_length, search_length); ReadHelper readHelper("normal_distribution.txt", sample_length, insertion_length + search_length); - readHelper.readFile(total_row); + readHelper.readFile(nullptr); std::vector<key_type> _sample, _population; readHelper.split_into(_sample, _population); - printf("Create search vector: %ld\n", - _population.end() - _population.begin() + insertion_length); + /*printf("%lu, Create search vector: %ld\n", _population.size(), + _population.end() - (_population.begin() + insertion_length));*/ std::vector<key_type> _search(_population.begin() + insertion_length, _population.end()); _population.resize(insertion_length); diff --git a/read_helper.h b/read_helper.h index 292eaac..54ca77a 100644 --- a/read_helper.h +++ b/read_helper.h @@ -22,16 +22,18 @@ class ReadHelper { static constexpr size_t REVERSED_BLOCK = 256; public: - size_t sample_length, needed_read_length; + const size_t sample_length, needed_read_length; ReadHelper(char const *filename, size_t sample_length, size_t insertion_length) : filename(filename), sample_length(sample_length), - needed_read_length(insertion_length + sample_length) {} + needed_read_length(insertion_length + sample_length) { + // printf("%zu %zu\n", sample_length, needed_read_length); + } unsigned long long maxValue() const { return max_value; } unsigned long long minValue() const { return min_value; } - std::vector<unsigned long long> population_vector; - inline void store_into_vector(unsigned long long value) { + std::vector<key_type> population_vector; + inline void store_into_vector(key_type value) { if (max_value < value) { max_value = value; } @@ -53,32 +55,32 @@ public: return dst(mt19937); } - void readFile(unsigned long &total_row) { + void readFile(unsigned long *total_row) { this->population_vector.clear(); auto read_number = 0UL; FILE *file = fopen(filename, "r"); assert(file); P_ERR("Reading sample"); - for (long long i; - read_number < needed_read_length && fscanf(file, "%lld ", &i) != EOF; + for (key_type i; + read_number < sample_length && fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) read_number++; - if (total_row > 0) { + if (total_row != nullptr) { P_ERR("\rReading skip"); - read_number = randomRow(total_row - sample_length - needed_read_length - + read_number = randomRow(*total_row - sample_length - needed_read_length - REVERSED_BLOCK); - total_row = read_number; + *total_row = read_number; // fprintf(stderr, "Skip %lu\n", read_number); - for (long long i; read_number > 0 && fscanf(file, "%lld ", &i) != EOF;) + for (key_type i; read_number > 0 && fscanf(file, "%lld ", &i) != EOF;) read_number--; } P_ERR("\rReading population"); read_number = 0; - auto remain = sample_length + REVERSED_BLOCK; - for (long long i; read_number < remain && fscanf(file, "%lld ", &i) != EOF; + auto remain = needed_read_length - sample_length + REVERSED_BLOCK; + for (key_type i; read_number < remain && fscanf(file, "%lld ", &i) != EOF; store_into_vector(i)) read_number++; fclose(file); @@ -87,8 +89,9 @@ public: } void split_into(std::vector<key_type> &sample, std::vector<key_type> &p) { - sample.reserve(sample_length); - p.reserve(needed_read_length - sample_length); + sample.resize(sample_length); + 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); memcpy(p.data(), population_vector.data() + sample_length, @@ -102,6 +105,8 @@ public: memcpy(p, population_vector.data() + sample_length, sizeof(key_type) * (needed_read_length - sample_length)); } + + size_t size() const { return this->population_vector.size(); } }; #endif
\ No newline at end of file |
