Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs267
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
cs267
Commits
e0ac51b3
There was an error fetching the commit references. Please try again later.
Commit
e0ac51b3
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
Apply lock-free list, but only got 10% improvement. Intel vtune didn't lie...
parent
fc59542e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hw3/dist_kv_store.hpp
+8
-18
8 additions, 18 deletions
hw3/dist_kv_store.hpp
with
8 additions
and
18 deletions
hw3/dist_kv_store.hpp
+
8
−
18
View file @
e0ac51b3
...
...
@@ -38,7 +38,7 @@ private:
public
:
kv_store
(
size_t
my_rank
,
size_t
n_rank
,
size_t
slot_per_node
=
R267_KVS_DEF_SLOT_PER_NODE
)
:
local_buf
(
slot_per_node
),
mut_local_buf
(
slot_per_node
),
my_rank
(
my_rank
),
n_rank
(
n_rank
)
{
:
local_buf
(
slot_per_node
),
my_rank
(
my_rank
),
n_rank
(
n_rank
)
{
}
void
push
(
const
key_type
&
k
,
const
value_type
&
v
)
{
...
...
@@ -97,11 +97,8 @@ private:
};
void
do_insert
(
const
key_type
&
k
,
const
value_type
&
v
)
{
auto
target_ls_and_lock
=
find_slot
(
k
);
auto
&
target_ls
=
target_ls_and_lock
.
first
;
auto
&
local_buf_mut
=
target_ls_and_lock
.
second
;
auto
&
target_ls
=
find_slot
(
k
);
{
std
::
lock_guard
<
std
::
mutex
>
_
(
local_buf_mut
);
for
(
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
{
ele
.
second
=
v
;
...
...
@@ -115,11 +112,8 @@ private:
}
const
value_type
&
do_find
(
const
key_type
&
k
)
const
{
auto
target_ls_and_lock
=
find_slot
(
k
);
const
auto
&
target_ls
=
target_ls_and_lock
.
first
;
auto
&
local_buf_mut
=
target_ls_and_lock
.
second
;
const
auto
&
target_ls
=
find_slot
(
k
);
{
std
::
lock_guard
<
std
::
mutex
>
_
(
local_buf_mut
);
for
(
const
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
return
ele
.
second
;
...
...
@@ -128,11 +122,8 @@ private:
throw
std
::
out_of_range
(
"Element not found."
);
}
value_type
&
do_find
(
const
key_type
&
k
)
{
auto
target_ls_and_lock
=
find_slot
(
k
);
auto
&
target_ls
=
target_ls_and_lock
.
first
;
auto
&
local_buf_mut
=
target_ls_and_lock
.
second
;
auto
&
target_ls
=
find_slot
(
k
);
{
std
::
lock_guard
<
std
::
mutex
>
_
(
local_buf_mut
);
for
(
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
return
ele
.
second
;
...
...
@@ -141,21 +132,21 @@ private:
throw
std
::
out_of_range
(
"Element not found."
);
}
auto
find_slot
(
const
key_type
&
k
)
const
{
const
auto
&
find_slot
(
const
key_type
&
k
)
const
{
auto
hash
=
find_hash_for_ele
(
k
);
if
(
my_rank
!=
find_rank_for_hash
(
hash
))
{
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
}
auto
pos
=
find_local_slot_num_for_hash
(
hash
);
return
std
::
pair
<
const
slot_type
&
,
std
::
mutex
&>
{
std
::
cref
(
local_buf
.
at
(
pos
)),
std
::
ref
(
mut_local_buf
.
at
(
pos
))}
;
return
local_buf
.
at
(
pos
)
;
}
auto
find_slot
(
const
key_type
&
k
)
{
auto
&
find_slot
(
const
key_type
&
k
)
{
auto
hash
=
find_hash_for_ele
(
k
);
if
(
my_rank
!=
find_rank_for_hash
(
hash
))
{
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
}
auto
pos
=
find_local_slot_num_for_hash
(
hash
);
return
std
::
pair
<
slot_type
&
,
std
::
mutex
&>
{
std
::
ref
(
local_buf
.
at
(
pos
)),
std
::
ref
(
mut_local_buf
.
at
(
pos
))}
;
return
local_buf
.
at
(
pos
)
;
}
private
:
...
...
@@ -173,7 +164,6 @@ private:
}
std
::
vector
<
slot_type
>
local_buf
;
mutable
std
::
vector
<
std
::
mutex
>
mut_local_buf
;
size_t
my_rank
,
n_rank
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment