Last active
January 12, 2017 21:28
-
-
Save pchiusano/3e67334a85f6d8aad06605ea4deb78a8 to your computer and use it in GitHub Desktop.
map reduce on as many nodes as you want in 10 lines of Unison code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- note, syntax here is Unison, just using .hs extension to get some syntax highlighting | |
-- The mapping function may spawn subcomputations on different nodes, | |
-- and the reduction function is done in parallel, building a balanced tree | |
-- of operations. Computation fails if any step takes longer than timeout | |
mapreduce : forall a b | |
. Duration -> (a -> Remote b) -> b -> (b -> b -> b) -> Vector a | |
-> Remote b | |
mapreduce timeout f z op vs = do Remote | |
futures := Remote.traverse (f `and-then` Remote.start timeout) vs | |
Vector.fold-balanced (Remote.parallel-map2 timeout op) | |
(Remote.pure z) | |
futures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment