Top Banner
Skel: A Streaming Process-based Skeleton Library for Erlang Archibald Elliott 1 Christopher Brown 1 Marco Danelutto 2 Kevin Hammond 1 Email: [email protected] 1 School of Computer Science, University of St Andrews, Scotland, UK. 2 Dept. Computer Science, University of Pisa, Pisa, Italy. IFL 2012 - Oxford
23

Skel: A Streaming Process-based Skeleton Library for Erlang · Skel: A Streaming Process-based Skeleton Library for Erlang Archibald Elliott1 Christopher Brown1 Marco Danelutto2 Kevin

Jan 26, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • Skel: A Streaming Process-based SkeletonLibrary for Erlang

    Archibald Elliott1 Christopher Brown1 Marco Danelutto2

    Kevin Hammond1

    Email: [email protected]

    1

    School of Computer Science, University of St Andrews, Scotland, UK.

    2

    Dept. Computer Science, University of Pisa, Pisa, Italy.

    IFL 2012 - Oxford

  • This Talk

    I Why we need ParallelismI Skeletons are good AbstractionsI Skeletons in ErlangI skel’s good Speedups

  • The Vision

    1. The single-core processor is almost completely obsolete

    2. Hardware systems are rapidly moving towards many- andmega-core

    By 2019 there will be millions of cores in home

    desktop machines – Joe Armstrong

    3. Software systems are still not ready:I Programming languages have not caught upI Software practices have not caught upI Programmers have not caught up

    4. We need to make programming parallel systems easy

  • Race Conditions

    What happens when you use Pthreads

  • Current Approaches

    I Most Programmers are taught to program sequentially

    I Modifying sequential code will not scale

    I Typical concurrency techniques will not scaleI Fundamentally, current approaches are too low-level:

    I You can’t program e↵ectively while thinking about deadlocks,race conditions, synchronisation, non-determinism etc.

    I You can’t program e↵ectively directly with threads, messagepassing, mutexes or shared memory.

    I You can only program e↵ectively with a di↵erent mindset

  • Our Approach

    I We need to provide a set of abstractions for the programmer;

    I They need to become second-nature;

    I They need to make it easy to introduce parallelism;

    I They need to make it easy to tune parallelism to gainmaximum speedup;

  • Functional Programming

    Functional programming can provide the correct abstractions

    However, languages take fundamentally di↵erent approaches

    I Haskell (GpH) is too implicit:I par :: a -> b -> bI pseq :: a -> b -> b

    I Erlang is too explicit:I spawnI ! and receive

  • Our Approach

    Parallel PatternA reusable way of parallelising a computation.

    Algorithmic SkeletonAn implementation of a Parallel Pattern.

  • API

    skel:run(Skeleton , InputItems ).% -> OutputItems

    I Skeleton – a skeleton

    I InputItems – items to be processed

    I OutputItems – items that have been processed

  • Seq

    {seq, Fun}

    Fun

    Tn · · · T1 T�n · · · T �1

    skel:run({seq , fun (X) -> X+1 end},[1,2,3,4,5,6]).

    % -> [2,3,4,5,6,7]

  • Pipe

    Tn · · · T1 T�n · · · T �1

    {pipe, [Skel1, Skel2, · · · , Skeln]}

    Skel1 Skel2 Skeln· · ·

    Inc = {seq , fun (X) -> X+1 end},Double = {seq , fun (X) -> X*2 end},skel:run({pipe , [Inc , Double]},

    [1,2,3,4,5,6]).% -> [4,6,8,10,12,14]

  • Farm

    Tn · · · T1 T �n · · · T �1

    ...

    Skel2

    Skel1

    {farm, Skel, M}

    SkelM

    Inc = {seq , fun(X)-> X+1 end},skel:run({farm , Inc , 3},

    [1,2,3,4,5,6]).% -> [2,5,3,6,4,7]

  • Map

    Tn · · · T1 T �n · · · T �1

    {map, Skel, Decomp, Recomp}

    ...

    Skel2

    Skelm

    Skel1

    Decomp Recomp

    Inc = {seq , fun(X)-> X+1 end},skel:run({map , Inc ,

    fun erlang:tuple_to_list /1,fun erlang:list_to_tuple /1},

    [{1,2},{3,4}]).% -> [{2,3},{4,5}]

  • Reduce

    Tn · · · T1Decomp

    {reduce, R, Decomp}

    R

    R

    R

    R

    R

    R

    R

    T �n · · · T �1

    skel:run({reduce , fun(X,Y) -> X + Y end ,fun erlang:tuple_to_list /1},

    [{1,2,3,4,5,6},{7,8,9,10,11,12}]).% -> [21,57]

  • Feedback

    Tn · · · T1 T�n · · · T �1

    Feedback

    {feedback, Skel, Feedback}

    Skel

    Inc = {seq , fun(X) -> X+1 end},skel:run({feedback , Inc ,

    fun(X) -> X < 5 end},[1,2,3,4,5,6,7,8,9,10]).

    % -> [5,6,7,8,9,10,11,5,5,5]

  • Experiments

    I Regular task cost: 1ms

    I Task cost > communication cost

    I Constant input number: 100,000

    I 8 Cores: 2x Intel Xeon 4-Core X5355 2.66GHz

    I Erlang R15B01

  • Results: Pipe

    2 4 6 8

    2

    4

    6

    8

    Number of Cores

    Speedu

    p

    Linear1 Stage2 Stages4 Stages8 Stages16 Stages

  • Results: Farm

    2 4 6 8

    2

    4

    6

    8

    Number of Cores

    Speedu

    p

    Linear1 Worker2 Workers4 Workers8 Workers16 Workers

  • Results: Map

    2 4 6 8

    2

    4

    6

    8

    Number of Cores

    Speedu

    p

    Linear1 Worker2 Workers4 Workers8 Workers16 Workers

  • Results: Reduce

    2 4 6 8

    0

    2

    4

    6

    8

    Number of Cores

    Speedu

    p

    Linear1 Item2 Items4 Items8 Items16 Items

  • Conclusions

    I Adopting a Parallel MindsetI Functional ProgrammingI Algorithmic Skeletons

    I Erlang is a great fit.I Low-level enough for controlI High-level enough to allow abstraction

    I skel’s speedups prove our implementation is good

  • Future Work

    I More Benchmarks

    I Better SpeedupsI Higher-order Skeletons

    I Divide and ConquerI MapReduceI Genetic AlgorithmsI . . .I Domain-specific Algorithms

  • THANK YOU

    http://www.paraphrase-ict.eu

    @paraphrase fp7

    Results