Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

WIP: tbb concurrent hash usage example #631

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
multimap
Ivan Butygin committed Feb 21, 2020
commit c59fd1f6b21de996eb3359ffa7d622c5295c2f47
25 changes: 6 additions & 19 deletions sdc/_concurrent_hash.cpp
Original file line number Diff line number Diff line change
@@ -26,12 +26,11 @@

#include <Python.h>
#include <cstdint>
#include <tbb/concurrent_hash_map.h>
#include <tbb/concurrent_vector.h>
#include <tbb/concurrent_unordered_map.h>


template<typename Key, typename Val>
using hashmap = tbb::concurrent_hash_map<Key,tbb::concurrent_vector<Val>>;
using hashmap = tbb::concurrent_unordered_multimap<Key,Val>;

template<typename Key, typename Val>
using iter_range = std::pair<typename hashmap<Key, Val>::iterator, typename hashmap<Key, Val>::iterator>;
@@ -54,12 +53,7 @@ void delete_int_hashmap(void* obj)
void addelem_int_hashmap(void* obj, int64_t key, size_t val)
{
auto& h = *static_cast<int_hashmap*>(obj);
int_hashmap::accessor ac;
h.insert(ac, key);
auto& vec = ac->second;
ac.release();
vec.push_back(val);
// h[key].push_back(val);
h.insert({key,val});
}

void* createiter_int_hashmap(void* obj)
@@ -86,16 +80,10 @@ int64_t iterkey_int_hashmap(void* it)
return r.first->first;
}

size_t itersize_int_hashmap(void* it)
size_t iterval_int_hashmap(void* it)
{
auto& r = *static_cast<int_hashmap_iters*>(it);
return r.first->second.size();
}

size_t iterelem_int_hashmap(void* it, size_t index)
{
auto& r = *static_cast<int_hashmap_iters*>(it);
return r.first->second[index];
return r.first->second;
}

void deleteiter_int_hashmap(void* obj)
@@ -128,8 +116,7 @@ PyMODINIT_FUNC PyInit_hconcurrent_hash()
REGISTER(enditer_int_hashmap)
REGISTER(nextiter_int_hashmap)
REGISTER(iterkey_int_hashmap)
REGISTER(itersize_int_hashmap)
REGISTER(iterelem_int_hashmap)
REGISTER(iterval_int_hashmap)
REGISTER(deleteiter_int_hashmap)
#undef REGISTER
return m;
26 changes: 7 additions & 19 deletions sdc/concurrent_hash.py
Original file line number Diff line number Diff line change
@@ -42,8 +42,7 @@
ll.add_symbol('enditer_int_hashmap', hconcurrent_hash.enditer_int_hashmap)
ll.add_symbol('nextiter_int_hashmap', hconcurrent_hash.nextiter_int_hashmap)
ll.add_symbol('iterkey_int_hashmap', hconcurrent_hash.iterkey_int_hashmap)
ll.add_symbol('itersize_int_hashmap', hconcurrent_hash.itersize_int_hashmap)
ll.add_symbol('iterelem_int_hashmap', hconcurrent_hash.iterelem_int_hashmap)
ll.add_symbol('iterval_int_hashmap', hconcurrent_hash.iterval_int_hashmap)
ll.add_symbol('deleteiter_int_hashmap', hconcurrent_hash.deleteiter_int_hashmap)

_create_int_hashmap = types.ExternalFunction("create_int_hashmap",
@@ -61,10 +60,8 @@
types.void(types.voidptr))
_iterkey_int_hashmap = types.ExternalFunction("iterkey_int_hashmap",
types.int64(types.voidptr))
_itersize_int_hashmap = types.ExternalFunction("itersize_int_hashmap",
types.intp(types.voidptr))
_iterelem_int_hashmap = types.ExternalFunction("iterelem_int_hashmap",
types.intp(types.voidptr, types.intp))
_iterval_int_hashmap = types.ExternalFunction("iterval_int_hashmap",
types.intp(types.voidptr))
_deleteiter_int_hashmap = types.ExternalFunction("deleteiter_int_hashmap",
types.void(types.voidptr))

@@ -97,11 +94,7 @@ def iterkey_int_hashmap():
pass


def itersize_int_hashmap():
pass


def iterelem_int_hashmap():
def iterval_int_hashmap():
pass


@@ -144,14 +137,9 @@ def iterkey_int_hashmap_overload(h):
return lambda h: _iterkey_int_hashmap(h)


@overload(itersize_int_hashmap)
def itersize_int_hashmap_overload(h):
return lambda h: _itersize_int_hashmap(h)


@overload(iterelem_int_hashmap)
def iterelem_int_hashmap_overload(h, i):
return lambda h, i: _iterelem_int_hashmap(h, i)
@overload(iterval_int_hashmap)
def iterval_int_hashmap_overload(h):
return lambda h: _iterval_int_hashmap(h)


@overload(deleteiter_int_hashmap)
6 changes: 2 additions & 4 deletions sdc/tests/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -1806,10 +1806,8 @@ def test_impl():
it = sdc.concurrent_hash.createiter_int_hashmap(h)
while 0 == sdc.concurrent_hash.enditer_int_hashmap(it):
key = sdc.concurrent_hash.iterkey_int_hashmap(it)
sz = sdc.concurrent_hash.itersize_int_hashmap(it)
for i in range(sz):
val = sdc.concurrent_hash.iterelem_int_hashmap(it, i)
print(key, val)
val = sdc.concurrent_hash.iterval_int_hashmap(it)
print(key, val)

sdc.concurrent_hash.nextiter_int_hashmap(it)