Skip to content

Commit

Permalink
fixed filltable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonglin Chen committed Apr 22, 2019
1 parent f517c36 commit 1c84dc7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions groupby_hash_templates.cu
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ void fillTable(Tkey* key_columns,
bool isInserted = false;
while (!isInserted) {
// first read the value out
ssize_t old = hash_key_idx[curPos];
int old = hash_key_idx[curPos];
// if it is -1, try update, else don't
if (old == -1)
old = atomicCAS(&(hash_key_idx[curPos]), -1, i);
// now old contains either i or a new address, if it is a new address meaning other thread claimed it
// note: old should not contain -1 now, safe to cast to size_t
if ((size_t)old != i) {
// now old contains either -1 or a new address, if it is a new address meaning other thread claimed it

if (old != -1) {
// note: old should not contain -1 now, safe to cast to size_t
if (!keyEqualCM<Tkey>(key_columns, (size_t)old, i, num_key_rows, num_key_cols)) {
// collision
curPos = (curPos + 1) % len_hash_table; // linear probing
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ $(EXE): $(OBJ)
$(EXE_HASH): $(OBJ_HASH)
$(NVCC) $(OBJ_HASH) -o $(EXE_HASH) $(LD_FLAGS) $(NVCC_FLAGS) $(CXX_FLAG)
clean:
rm -rf *.o $(EXE)
rm -rf *.o $(EXE) $(EXE_HASH)

0 comments on commit 1c84dc7

Please sign in to comment.