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
8b462847
There was an error fetching the commit references. Please try again later.
Commit
8b462847
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
change push/find to set/get
parent
0a7afb0b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hw3/dist_kv_store.hpp
+43
-43
43 additions, 43 deletions
hw3/dist_kv_store.hpp
hw3/hash_map.hpp
+2
-2
2 additions, 2 deletions
hw3/hash_map.hpp
hw3/kv_test.cc
+6
-6
6 additions, 6 deletions
hw3/kv_test.cc
with
51 additions
and
51 deletions
hw3/dist_kv_store.hpp
+
43
−
43
View file @
8b462847
...
@@ -41,79 +41,79 @@ public:
...
@@ -41,79 +41,79 @@ public:
:
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
)
{
void
set
(
const
key_type
&
k
,
const
value_type
&
v
)
{
auto
target_rank
=
find
_rank_for_hash
(
find
_hash_for_ele
(
k
));
auto
target_rank
=
get
_rank_for_hash
(
get
_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
{
if
(
my_rank
==
target_rank
)
{
return
do_
in
se
r
t
(
k
,
v
);
return
do_set
(
k
,
v
);
}
}
else
{
else
{
bool
succ
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_
in
se
r
t
,
this
,
k
,
v
)).
wait
();
bool
succ
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_set
,
this
,
k
,
v
)).
wait
();
if
(
not
succ
)
if
(
not
succ
)
throw
std
::
runtime_error
(
"RPC
in
se
r
t failed."
);
throw
std
::
runtime_error
(
"RPC set failed."
);
}
}
}
}
std
::
pair
<
bool
,
value_type
>
operator
[]
(
const
key_type
&
k
)
const
{
std
::
pair
<
bool
,
value_type
>
get
(
const
key_type
&
k
)
const
{
auto
target_rank
=
find
_rank_for_hash
(
find
_hash_for_ele
(
k
));
auto
target_rank
=
get
_rank_for_hash
(
get
_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
{
if
(
my_rank
==
target_rank
)
{
return
std
::
make_pair
(
true
,
*
do_
find
(
k
));
return
std
::
make_pair
(
true
,
*
do_
get
(
k
));
}
}
else
{
else
{
auto
res
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_
find
,
this
,
k
)).
wait
();
auto
res
=
upcxx
::
rpc
(
target_rank
,
std
::
bind
(
&
this_type
::
do_rpc_
get
,
this
,
k
)).
wait
();
if
(
not
res
.
success
)
if
(
not
res
.
success
)
throw
std
::
runtime_error
(
"RPC
find
failed."
);
throw
std
::
runtime_error
(
"RPC
get
failed."
);
return
std
::
make_pair
(
res
.
found
,
res
.
val
);
return
std
::
make_pair
(
res
.
found
,
res
.
val
);
}
}
}
}
bool
push
_if_is_mine
(
const
key_type
&
k
,
const
value_type
&
v
)
{
bool
set
_if_is_mine
(
const
key_type
&
k
,
const
value_type
&
v
)
{
auto
target_rank
=
find
_rank_for_hash
(
find
_hash_for_ele
(
k
));
auto
target_rank
=
get
_rank_for_hash
(
get
_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
{
if
(
my_rank
==
target_rank
)
{
do_
in
se
r
t
(
k
,
v
);
do_set
(
k
,
v
);
}
}
return
my_rank
==
target_rank
;
return
my_rank
==
target_rank
;
}
}
std
::
pair
<
bool
,
value_type
>
find
_if_is_mine
(
const
key_type
&
k
)
{
std
::
pair
<
bool
,
value_type
>
get
_if_is_mine
(
const
key_type
&
k
)
{
auto
target_rank
=
find
_rank_for_hash
(
find
_hash_for_ele
(
k
));
auto
target_rank
=
get
_rank_for_hash
(
get
_hash_for_ele
(
k
));
if
(
my_rank
==
target_rank
)
if
(
my_rank
==
target_rank
)
return
std
::
make_pair
(
true
,
*
do_
find
(
k
));
return
std
::
make_pair
(
true
,
*
do_
get
(
k
));
else
else
return
std
::
make_pair
(
false
,
value_type
{});
return
std
::
make_pair
(
false
,
value_type
{});
}
}
private
:
private
:
bool
do_rpc_
in
se
r
t
(
key_type
k
,
value_type
v
)
{
bool
do_rpc_set
(
key_type
k
,
value_type
v
)
{
try
{
try
{
do_
in
se
r
t
(
k
,
v
);
do_set
(
k
,
v
);
return
true
;
return
true
;
}
}
catch
(
std
::
exception
&
e
)
{
catch
(
std
::
exception
&
e
)
{
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc
in
se
r
t: "
,
e
.
what
());
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc set: "
,
e
.
what
());
return
false
;
return
false
;
}
}
}
}
auto
do_rpc_
find
(
key_type
k
)
const
{
auto
do_rpc_
get
(
key_type
k
)
const
{
try
{
try
{
const
auto
*
res
=
do_
find
(
k
,
true
);
const
auto
*
res
=
do_
get
(
k
,
true
);
if
(
res
)
if
(
res
)
return
rpc_
find
_result
{
true
,
true
,
*
res
};
return
rpc_
get
_result
{
true
,
true
,
*
res
};
else
else
return
rpc_
find
_result
{
false
,
true
,
value_type
{}};
return
rpc_
get
_result
{
false
,
true
,
value_type
{}};
}
}
catch
(
std
::
exception
&
e
)
{
catch
(
std
::
exception
&
e
)
{
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc
find
: "
,
e
.
what
());
rlib
::
println
(
std
::
cerr
,
"Error: exception while executing rpc
get
: "
,
e
.
what
());
return
rpc_
find
_result
{
false
,
false
,
value_type
{}};
return
rpc_
get
_result
{
false
,
false
,
value_type
{}};
}
}
}
}
private
:
private
:
struct
rpc_
find
_result
{
struct
rpc_
get
_result
{
bool
found
,
success
;
bool
found
,
success
;
value_type
val
;
value_type
val
;
};
};
void
do_
in
se
r
t
(
const
key_type
&
k
,
const
value_type
&
v
)
{
void
do_set
(
const
key_type
&
k
,
const
value_type
&
v
)
{
auto
&
target_ls
=
find
_slot
(
k
);
auto
&
target_ls
=
get
_slot
(
k
);
{
{
for
(
auto
&
ele
:
target_ls
)
{
for
(
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
{
...
@@ -127,8 +127,8 @@ private:
...
@@ -127,8 +127,8 @@ private:
}
}
}
}
const
value_type
*
do_
find
(
const
key_type
&
k
,
bool
no_throw
=
false
)
const
{
const
value_type
*
do_
get
(
const
key_type
&
k
,
bool
no_throw
=
false
)
const
{
const
auto
&
target_ls
=
find
_slot
(
k
);
const
auto
&
target_ls
=
get
_slot
(
k
);
{
{
for
(
const
auto
&
ele
:
target_ls
)
{
for
(
const
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
...
@@ -139,8 +139,8 @@ private:
...
@@ -139,8 +139,8 @@ private:
throw
std
::
out_of_range
(
"Element not found."
);
throw
std
::
out_of_range
(
"Element not found."
);
return
nullptr
;
return
nullptr
;
}
}
value_type
*
do_
find
(
const
key_type
&
k
,
bool
no_throw
=
false
)
{
value_type
*
do_
get
(
const
key_type
&
k
,
bool
no_throw
=
false
)
{
auto
&
target_ls
=
find
_slot
(
k
);
auto
&
target_ls
=
get
_slot
(
k
);
{
{
for
(
auto
&
ele
:
target_ls
)
{
for
(
auto
&
ele
:
target_ls
)
{
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
if
(
equal_engine_type
{}(
ele
.
first
,
k
))
...
@@ -152,33 +152,33 @@ private:
...
@@ -152,33 +152,33 @@ private:
return
nullptr
;
return
nullptr
;
}
}
const
auto
&
find
_slot
(
const
key_type
&
k
)
const
{
const
auto
&
get
_slot
(
const
key_type
&
k
)
const
{
auto
hash
=
find
_hash_for_ele
(
k
);
auto
hash
=
get
_hash_for_ele
(
k
);
if
(
my_rank
!=
find
_rank_for_hash
(
hash
))
{
if
(
my_rank
!=
get
_rank_for_hash
(
hash
))
{
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
}
}
auto
pos
=
find
_local_slot_num_for_hash
(
hash
);
auto
pos
=
get
_local_slot_num_for_hash
(
hash
);
return
local_buf
.
at
(
pos
);
return
local_buf
.
at
(
pos
);
}
}
auto
&
find
_slot
(
const
key_type
&
k
)
{
auto
&
get
_slot
(
const
key_type
&
k
)
{
auto
hash
=
find
_hash_for_ele
(
k
);
auto
hash
=
get
_hash_for_ele
(
k
);
if
(
my_rank
!=
find
_rank_for_hash
(
hash
))
{
if
(
my_rank
!=
get
_rank_for_hash
(
hash
))
{
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
throw
std
::
invalid_argument
(
"This key doesn't belong to me."
);
}
}
auto
pos
=
find
_local_slot_num_for_hash
(
hash
);
auto
pos
=
get
_local_slot_num_for_hash
(
hash
);
return
local_buf
.
at
(
pos
);
return
local_buf
.
at
(
pos
);
}
}
private
:
private
:
inline
auto
find
_rank_for_hash
(
hash_type
h
)
const
{
inline
auto
get
_rank_for_hash
(
hash_type
h
)
const
{
return
h
%
n_rank
;
return
h
%
n_rank
;
}
}
inline
auto
find
_local_slot_num_for_hash
(
hash_type
h
)
const
{
inline
auto
get
_local_slot_num_for_hash
(
hash_type
h
)
const
{
// The result is the same in all nodes.
// The result is the same in all nodes.
const
auto
slot_per_node
=
local_buf
.
size
();
const
auto
slot_per_node
=
local_buf
.
size
();
return
h
/
n_rank
%
slot_per_node
;
return
h
/
n_rank
%
slot_per_node
;
}
}
inline
auto
find
_hash_for_ele
(
const
key_type
&
k
)
const
{
inline
auto
get
_hash_for_ele
(
const
key_type
&
k
)
const
{
hash_type
h
=
hash_engine_type
{}(
k
);
hash_type
h
=
hash_engine_type
{}(
k
);
return
h
;
return
h
;
}
}
...
...
This diff is collapsed.
Click to expand it.
hw3/hash_map.hpp
+
2
−
2
View file @
8b462847
...
@@ -23,10 +23,10 @@ struct HashMap {
...
@@ -23,10 +23,10 @@ struct HashMap {
}
}
bool
insert
(
const
kmer_pair
&
kmer
)
{
bool
insert
(
const
kmer_pair
&
kmer
)
{
return
real_db
.
push
_if_is_mine
(
kmer
.
kmer
,
kmer
);
return
real_db
.
set
_if_is_mine
(
kmer
.
kmer
,
kmer
);
}
}
bool
find
(
const
pkmer_t
&
key_kmer
,
kmer_pair
&
val_kmer
)
{
bool
find
(
const
pkmer_t
&
key_kmer
,
kmer_pair
&
val_kmer
)
{
auto
res
=
real_db
[
key_kmer
]
;
auto
res
=
real_db
.
get_if_is_mine
(
key_kmer
)
;
if
(
res
.
first
)
if
(
res
.
first
)
val_kmer
=
res
.
second
;
val_kmer
=
res
.
second
;
return
res
.
first
;
return
res
.
first
;
...
...
This diff is collapsed.
Click to expand it.
hw3/kv_test.cc
+
6
−
6
View file @
8b462847
...
@@ -6,7 +6,7 @@ int main() {
...
@@ -6,7 +6,7 @@ int main() {
upcxx
::
init
();
upcxx
::
init
();
kv_store
<
double
,
int
>
kvs
(
upcxx
::
rank_me
(),
upcxx
::
rank_n
());
kv_store
<
double
,
int
>
kvs
(
upcxx
::
rank_me
(),
upcxx
::
rank_n
());
try
{
try
{
auto
[
succ
,
val
]
=
kvs
[
1.23
]
;
auto
[
succ
,
val
]
=
kvs
.
get
(
1.23
)
;
if
(
succ
)
if
(
succ
)
rlib
::
println
(
"FUCK! succ! val is"
,
val
);
rlib
::
println
(
"FUCK! succ! val is"
,
val
);
}
}
...
@@ -16,16 +16,16 @@ int main() {
...
@@ -16,16 +16,16 @@ int main() {
upcxx
::
barrier
();
// without this barrier, the access above may success at rank1.
upcxx
::
barrier
();
// without this barrier, the access above may success at rank1.
if
(
upcxx
::
rank_me
()
==
0
)
{
if
(
upcxx
::
rank_me
()
==
0
)
{
kvs
.
push
(
1.23
,
666
);
kvs
.
set
(
1.23
,
666
);
kvs
.
push
(
6.666
,
123
);
kvs
.
set
(
6.666
,
123
);
kvs
.
push
(
0.01
,
99
);
kvs
.
set
(
0.01
,
99
);
kvs
.
push
(
1.
,
111
);
kvs
.
set
(
1.
,
111
);
rlib
::
println
(
"pushed!"
);
rlib
::
println
(
"pushed!"
);
}
}
upcxx
::
barrier
();
upcxx
::
barrier
();
auto
[
succ
,
val
]
=
kvs
[
6.666
]
;
auto
[
succ
,
val
]
=
kvs
.
get
(
6.666
)
;
if
(
not
succ
)
if
(
not
succ
)
rlib
::
println
(
"not succ!"
);
rlib
::
println
(
"not succ!"
);
rlib
::
println
(
upcxx
::
rank_me
(),
val
);
rlib
::
println
(
upcxx
::
rank_me
(),
val
);
...
...
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