summaryrefslogtreecommitdiff
path: root/main.cu
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-06-14 00:07:34 +0800
committerKunoiSayami <[email protected]>2022-06-14 00:07:34 +0800
commitc5d52db9e4c3bda63a99958f387c29ffdad47971 (patch)
treea586c3b74c1f369daa348aea1a4d8fd9ed559678 /main.cu
parent34e95e65b783ba6b43a810432e03993ec7f9412c (diff)
fix: Fix wrong level calc
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'main.cu')
-rw-r--r--main.cu28
1 files changed, 13 insertions, 15 deletions
diff --git a/main.cu b/main.cu
index a463280..b1239d7 100644
--- a/main.cu
+++ b/main.cu
@@ -99,13 +99,15 @@ constexpr size_t FACTOR = 1;
// should change this to dynamic next time
constexpr size_t KEY_INDEX_SIZE = 32;
-constexpr int block_size = STEP_SIZE;
+volatile int block_size = STEP_SIZE;
// Supported operations
constexpr int ADD = 0;
constexpr int DELETE = 1;
constexpr int SEARCH = 2;
+typedef LL key_type;
+
#ifdef RANDOM_TARGET
constexpr const char *TARGET_STRING = "RANDOM";
#else
@@ -540,21 +542,21 @@ __global__ void kernel(LL *items, LL *op, LL *result) {
}*/
// Generate the level of a newly created node
-LL Randomlevel(std::mt19937 &randomEngine) {
- std::geometric_distribution<> distribution(0.5);
- return std::min(MAX_LEVEL, (size_t)distribution(randomEngine) + 1);
+LL Randomlevel(std::mt19937 &randomEngine, double p) {
+ std::geometric_distribution<> distribution(p);
+ return std::min(MAX_LEVEL, (size_t)distribution(randomEngine));
}
std::vector<LL> storage;
-unsigned trailing_zeroes(LL n) {
+unsigned trailing_zeroes(size_t index) {
unsigned bits = 0;
- LL x = n;
+ LL x = index / block_size;
if (x) {
- while ((x & 1) == 0) {
+ while (x % block_size == 0) {
++bits;
- x >>= 1;
+ x /= block_size;
}
}
return bits;
@@ -572,7 +574,7 @@ LL CustomLevel(LL value) {
auto index = left - storage.begin();
if (index % block_size == 0) {
- auto level = trailing_zeroes(index / block_size + 1) + 1;
+ auto level = trailing_zeroes(index) + 1;
// printf("%ld,%u\n", index, level);
return level;
}
@@ -641,7 +643,7 @@ int main(int argc, char **argv) {
// srand(0);
for (i = 0; i < NUM_ITEMS; i++) {
#ifdef RANDOM_HEIGHT
- // levels[i] = Randomlevel(randomEngine) - 1; // 36/14
+ levels[i] = Randomlevel(1 / randomEngine) - 1; // 36/14
#else
levels[i] = CustomLevel(items[i]) - 1; // 31/18
#endif
@@ -737,11 +739,7 @@ int main(int argc, char **argv) {
// Print kernel execution time in milliseconds
- printf("%s ", TARGET_STRING);
-
-#ifndef RANDOM_TARGET
- printf("%d ", block_size);
-#endif
+ printf("%s %d ", TARGET_STRING, block_size);
printf("%lu: %lf", NUM_ITEMS, time);