Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Actris
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Iris
Actris
Commits
b3ef376b
Commit
b3ef376b
authored
5 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Tweak.
parent
5343f4be
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theories/examples/map_reduce.v
+60
-57
60 additions, 57 deletions
theories/examples/map_reduce.v
with
60 additions
and
57 deletions
theories/examples/map_reduce.v
+
60
−
57
View file @
b3ef376b
...
@@ -29,6 +29,66 @@ Instance: Params (@group_insert) 5.
...
@@ -29,6 +29,66 @@ Instance: Params (@group_insert) 5.
Instance
:
Params
(
@
group
)
3
.
Instance
:
Params
(
@
group
)
3
.
Instance
:
Params
(
@
group
)
7
.
Instance
:
Params
(
@
group
)
7
.
(** Distributed version *)
Definition
par_map_reduce_map_server
:
val
:=
rec
:
"go"
"n"
"cmap"
"csort"
"xs"
:=
if
:
"n"
=
#
0
then
#
()
else
if
:
recv
"cmap"
then
(* send item to mapper *)
if
:
lisnil
"xs"
then
send
"cmap"
#
false
;;
"go"
(
"n"
-
#
1
)
"cmap"
"csort"
"xs"
else
send
"cmap"
#
true
;;
send
"cmap"
(
lhead
"xs"
);;
"go"
"n"
"cmap"
"csort"
(
ltail
"xs"
)
else
(* receive item from mapper *)
let
:
"zs"
:=
recv
"cmap"
in
send_all
"csort"
"zs"
;;
"go"
"n"
"cmap"
"csort"
"xs"
.
Definition
par_map_reduce_collect
:
val
:=
rec
:
"go"
"csort"
"i"
"ys"
:=
if
:
~recv
"csort"
then
((
"i"
,
"ys"
),
NONE
)
else
let
:
"jy"
:=
recv
"csort"
in
let
:
"j"
:=
Fst
"jy"
in
let
:
"y"
:=
Snd
"jy"
in
if
:
"i"
=
"j"
then
"go"
"csort"
"j"
(
lcons
"y"
"ys"
)
else
((
"i"
,
"ys"
),
SOME
(
"j"
,
"y"
))
.
Definition
par_map_reduce_reduce_server
:
val
:=
rec
:
"go"
"n"
"csort"
"cred"
"acc"
"zs"
:=
if
:
"n"
=
#
0
then
"zs"
else
if
:
recv
"cred"
then
(* Send item to mapper *)
match
:
"acc"
with
NONE
=>
(* nothing left *)
send
"cred"
#
false
;;
"go"
(
"n"
-
#
1
)
"csort"
"cred"
NONE
"zs"
|
SOME
"acc"
=>
(* Read subsequent items with the same key *)
let
:
"grp"
:=
par_map_reduce_collect
"csort"
(
Fst
"acc"
)
(
lcons
(
Snd
"acc"
)
(
lnil
#
()))
in
send
"cred"
#
true
;;
send
"cred"
(
Fst
"grp"
);;
"go"
"n"
"csort"
"cred"
(
Snd
"grp"
)
"zs"
end
else
(* receive item from mapper *)
let
:
"zs'"
:=
recv
"cred"
in
"go"
"n"
"csort"
"cred"
"acc"
(
lapp
"zs'"
"zs"
)
.
Definition
cmpZfst
:
val
:=
λ
:
"x"
"y"
,
Fst
"x"
≤
Fst
"y"
.
Definition
par_map_reduce
:
val
:=
λ
:
"n"
"map"
"red"
"xs"
,
let
:
"cmap"
:=
start_map_service
"n"
"map"
in
let
:
"csort"
:=
start_chan
(
λ
:
"c"
,
sort_elem_service
cmpZfst
"c"
)
in
par_map_reduce_map_server
"n"
"cmap"
"csort"
"xs"
;;
send
"csort"
#
stop
;;
let
:
"cred"
:=
start_map_service
"n"
"red"
in
(* We need the first sorted element in the loop to compare subsequent elements *)
if
:
~recv
"csort"
then
lnil
#
()
else
(* Handle the empty case *)
let
:
"jy"
:=
recv
"csort"
in
par_map_reduce_reduce_server
"n"
"csort"
"cred"
(
SOME
"jy"
)
(
lnil
#
())
.
(** Properties about the functional version *)
(** Properties about the functional version *)
Local
Infix
"≡ₚₚ"
:=
Local
Infix
"≡ₚₚ"
:=
(
PermutationA
(
prod_relation
(
=
)
(
≡
ₚ
)))
(
at
level
70
,
no
associativity
)
:
stdpp_scope
.
(
PermutationA
(
prod_relation
(
=
)
(
≡
ₚ
)))
(
at
level
70
,
no
associativity
)
:
stdpp_scope
.
...
@@ -141,63 +201,6 @@ Section map_reduce.
...
@@ -141,63 +201,6 @@ Section map_reduce.
Proof
.
intros
xs1
xs2
Hxs
.
by
rewrite
/
map_reduce
/=
Hxs
.
Qed
.
Proof
.
intros
xs1
xs2
Hxs
.
by
rewrite
/
map_reduce
/=
Hxs
.
Qed
.
End
map_reduce
.
End
map_reduce
.
(** Distributed version *)
Definition
par_map_reduce_map_server
:
val
:=
rec
:
"go"
"n"
"cmap"
"csort"
"xs"
:=
if
:
"n"
=
#
0
then
#
()
else
if
:
recv
"cmap"
then
(* send item to mapper *)
if
:
lisnil
"xs"
then
send
"cmap"
#
false
;;
"go"
(
"n"
-
#
1
)
"cmap"
"csort"
"xs"
else
send
"cmap"
#
true
;;
send
"cmap"
(
lhead
"xs"
);;
"go"
"n"
"cmap"
"csort"
(
ltail
"xs"
)
else
(* receive item from mapper *)
let
:
"zs"
:=
recv
"cmap"
in
send_all
"csort"
"zs"
;;
"go"
"n"
"cmap"
"csort"
"xs"
.
Definition
par_map_reduce_collect
:
val
:=
rec
:
"go"
"csort"
"i"
"ys"
:=
if
:
~recv
"csort"
then
((
"i"
,
"ys"
),
NONE
)
else
let
:
"jy"
:=
recv
"csort"
in
let
:
"j"
:=
Fst
"jy"
in
let
:
"y"
:=
Snd
"jy"
in
if
:
"i"
=
"j"
then
"go"
"csort"
"j"
(
lcons
"y"
"ys"
)
else
((
"i"
,
"ys"
),
SOME
(
"j"
,
"y"
))
.
Definition
par_map_reduce_reduce_server
:
val
:=
rec
:
"go"
"n"
"csort"
"cred"
"acc"
"zs"
:=
if
:
"n"
=
#
0
then
"zs"
else
if
:
recv
"cred"
then
(* Send item to mapper *)
match
:
"acc"
with
NONE
=>
(* nothing left *)
send
"cred"
#
false
;;
"go"
(
"n"
-
#
1
)
"csort"
"cred"
NONE
"zs"
|
SOME
"acc"
=>
(* Read subsequent items with the same key *)
let
:
"grp"
:=
par_map_reduce_collect
"csort"
(
Fst
"acc"
)
(
lcons
(
Snd
"acc"
)
(
lnil
#
()))
in
send
"cred"
#
true
;;
send
"cred"
(
Fst
"grp"
);;
"go"
"n"
"csort"
"cred"
(
Snd
"grp"
)
"zs"
end
else
(* receive item from mapper *)
let
:
"zs'"
:=
recv
"cred"
in
"go"
"n"
"csort"
"cred"
"acc"
(
lapp
"zs'"
"zs"
)
.
Definition
cmpZfst
:
val
:=
λ
:
"x"
"y"
,
Fst
"x"
≤
Fst
"y"
.
Definition
par_map_reduce
:
val
:=
λ
:
"n"
"map"
"red"
"xs"
,
let
:
"cmap"
:=
start_map_service
"n"
"map"
in
let
:
"csort"
:=
start_chan
(
λ
:
"c"
,
sort_elem_service
cmpZfst
"c"
)
in
par_map_reduce_map_server
"n"
"cmap"
"csort"
"xs"
;;
send
"csort"
#
stop
;;
let
:
"cred"
:=
start_map_service
"n"
"red"
in
(* We need the first sorted element in the loop to compare subsequent elements *)
if
:
~recv
"csort"
then
lnil
#
()
else
(* Handle the empty case *)
let
:
"jy"
:=
recv
"csort"
in
par_map_reduce_reduce_server
"n"
"csort"
"cred"
(
SOME
"jy"
)
(
lnil
#
())
.
(** Correctness proofs of the distributed version *)
(** Correctness proofs of the distributed version *)
Class
map_reduceG
Σ
A
B
`{
Countable
A
,
Countable
B
}
:=
{
Class
map_reduceG
Σ
A
B
`{
Countable
A
,
Countable
B
}
:=
{
...
...
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