parallel programming modelsaeminium.dei.uc.pt/images/e/e2/parallelprogrammingmodels.pdf · parallel...

47
Parallel Programming Models Sven Stork Motivation MPI OpenMP (P)LINQ Erlang TBB Cilk X10 Conclusion Parallel Programming Models Sven Stork 29th September 2008

Upload: others

Post on 17-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Parallel Programming Models

Sven Stork

29th September 2008

Page 2: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Outline

1 Motivation

2 MPI

3 OpenMP

4 (P)LINQ

5 Erlang

6 TBB

7 Cilk

8 X10

9 Conclusion

Page 3: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Motivation

Why are we looking into these model ?

concurrent programming is the future (no choice)

parallel programming was not mainstream in the lastdecades

there is no (good) support for parallel programming incurrent programming languagesonly in domain specific areas (e.g HPC) research forparallel programmingconcepts and approaches of domain specific areas are mostof the time no suitable for general purpose programming

glimpse at the future

”HPC systems are about 20 year ahead of mainstream systems”

Page 4: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Motivation

http://www.top500.org

Page 5: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Motivation

http://www.top500.org

Page 6: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Motivation

http://www.top500.org

Page 7: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Motivation

What are we looking for ?

What are the current/proposed solutions out there?

Are the solutions domain specific or general purpose ?What are the short comings and limitations ?Is there a consensus of features that seems to solve theissues ?

How to look at it ?

From current standards to proposed solutions

Page 8: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI -Overview

What is MPI ?

API for writing parallel applications

de-facto (industry) standard in HPC (High PerformanceComputing)

API defined for C, C++ and Fortran

widely deployed, support for basically all type of machines(dual-core → Cray → ”Roadrunner”)

http://www.mpi-forum.org

Page 9: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Features

MPI Feature List

Message PassingP2P communication

blockingnon-blocking

Collective communication (broadcast, scatter, reduce)

Parallel I/O

Remote Memory Access

build-in data conversion for heterogeneous setups

Page 10: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Example

#i n c l u d e <mpi . h>

i n t main ( i n t argc , c h a r ∗ a r g v [ ] ) {i n t rank = 0 , s i z e = 0 ;s h o r t i n t r e c v = 0 ;MPI Status s t a t u s ;

M P I I n i t (& argc , &a r g v ) ;MPI Comm size (MPI COMM WORLD, &s i z e ) ;MPI Comm rank (MPI COMM WORLD, &rank ) ;

s w i t c h ( rank ) {c a s e 0 :

MPI Send(&rank , 1 , MPI INT , 1 , 0 , MPI COMM WORLD ) ;MPI Recv(& recv , 1 , MPI INT , 1 , 0 , MPI COMM WORLD, &s t a t u s ) ;b r e a k ;

c a s e 1 :MPI Send(&rank , 1 , MPI INT , 0 , 0 , MPI COMM WORLD ) ;MPI Recv(& recv , 1 , MPI INT , 0 , 0 , MPI COMM WORLD, &s t a t u s ) ;b r e a k ;

d e f a u l t :b r e a k ;

}

M P I F i n a l i z e ( ) ;r e t u r n 0 ;

}

Page 11: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Example[BROKEN]

BROKEN 1

Process 0 Process 1MPI Send(. . . ) MPI Send(. . . )MPI Recv(. . . ) MPI Recv(. . . )

BROKEN 2

What happens if the program is started with just 1 process ?

BROKEN 3

The recv variable is of type short → buffer overflow.

Page 12: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Example[BROKEN]

Will this program run or not ?

It runs:If the implementation uses an eager protocol then thesend call will act non-blocking (common case for smallmessages)

It hangs:The implementation uses a rendezvous protocol to andeach process is waiting for the corresponding receive(common case for bigger messages)

It crash:A restrictive compiler/system could detect the stackoverflow and cause the application to segfault.

Page 13: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Example [FIXED]

#i n c l u d e <mpi . h>

i n t main ( i n t argc , c h a r ∗ a r g v [ ] ) {i n t rank = 0 , s i z e = 0 , r e c v ;MPI Status s t a t u s ;

M P I I n i t (& argc , &a r g v ) ;MPI Comm size (MPI COMM WORLD, &s i z e ) ;MPI Comm rank (MPI COMM WORLD, &rank ) ;

i f ( s i z e >= 2 ) {s w i t c h ( rank ) {c a s e 0 :

MPI Send(&rank , 1 , MPI INT , 1 , 0 , MPI COMM WORLD ) ;MPI Recv(& recv , 1 , MPI INT , 1 , 0 , MPI COMM WORLD, &s t a t u s ) ;b r e a k ;

c a s e 1 :MPI Recv(& recv , 1 , MPI INT , 0 , 0 , MPI COMM WORLD, &s t a t u s ) ;MPI Send(&rank , 1 , MPI INT , 0 , 0 , MPI COMM WORLD ) ;b r e a k ;

d e f a u l t :b r e a k ;

}}

M P I F i n a l i z e ( ) ;r e t u r n 0 ;

}

Page 14: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

Overview

Features

Example

Issues

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

MPI - Issues

Pro

standard API

support for basically almost every system out there

Contra

very low level primitives

no real resource management

user responsible for synchronisation and data distribution

too complicated (> 200 methods are defined → 6 functionMPI common case)

wrong programs may work to some degree (e.g. differentsystem, different problem size)

basically all bigger MPI programs have bugs

Page 15: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

OpenMP Overview

What is OpenMP ?

industry standard for shared memory parallelism

defined for C, C++ and Fortran

’annotations’ for the compiler (e.g. gcc >= 4.2)

http://www.openmp.org

Page 16: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

OpenMP - Features

Features

transparently implemented via #pragmas or comments

specification of parallel tasks

sectionsfortasks (new in version 3.0)

synchronisation

masterbarriertaskwaitflush (consistent memory view)atomics

Page 17: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Restrictive Standard

Page 18: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

OpenMP - Example

Example

Parallel Sections#pragma omp p a r a l l e l s e c t i o n s . . .{

#pragma omp s e c t i o n . . .{ . . . }

#pragma omp s e c t i o n . . .{ . . . }

. . .}

Parallel For Loop

#pragma omp p a r a l l e l f o r . . .f o r ( i = 0 ; i < N ; i++ ) {

. . .}

Task#pragma omp p a r a l l e l t a s k . . .

Page 19: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

OpenMP - Example

s t a t i c c o n s t i n t N = 1 0 0 ;

i n t main ( i n t argc , c h a r ∗ a r g v [ ] ) {i n t x , y ;d o u b l e ∗ r e s t r i c t a = NULL ;d o u b l e ∗ r e s t r i c t B = NULL ;d o u b l e ∗ r e s t r i c t c = NULL ;

a = ( d o u b l e ∗) m a l l o c (N ∗ s i z e o f ( d o u b l e ) ) ;

B = ( d o u b l e ∗) m a l l o c ( N∗N ∗ s i z e o f ( d o u b l e ) ) ;c = ( d o u b l e ∗) m a l l o c (

N ∗ s i z e o f ( d o u b l e ) ) ;

// . . . i n i t data

/∗ compute ∗/#pragma omp p a r a l l e l f o r d e f a u l t ( none ) s h a r e d ( a , B, c ) p r i v a t e ( x , y )

f o r ( y = 0 ; y < N ; y++ ) {f o r ( x = 0 ; x < N ; x++ ) {

c [ y ] += a [ y ] ∗ B [ x+y∗N ] ;}

}

f o r ( y = 0 ; y < N ; y++ ) {p r i n t f ( ”%f \n” , c [ y ] ) ;

}

f r e e ( a ) ; f r e e (B ) ; f r e e ( c ) ;r e t u r n 0 ;

}

Page 20: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

Overview

Features

Example

Issues

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

OpenMP - Issues

Pro

incremental parallelization approach

single code base (debugging of sequential version)

easy to use for structured problems (e.g. loops)

allows fine tuning off concurrent execution

Contra

mainly focused on loop parallelism

user has still main responsibility for synchronisation

some features are implementation specific (e.g nestedparallelism)

Page 21: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Overview

Features

Example

Issues

Erlang

TBB

Cilk

X10

Conclusion

LINQ - Overview

Overview

LINQ = Language Integrated Query

developed by Microsoft for the .NET platform (C#, VB,. . . )

’SQL’ish style for manipulating data sets (e.g. collections,XML, databases)

PLINQ is a parallel implementation of LINQ based on TPL

http://msdn.microsoft.com/en-us/netframework/aa904594.aspx

Page 22: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Overview

Features

Example

Issues

Erlang

TBB

Cilk

X10

Conclusion

LINQ - Features

Features

everything that implements IEnumerable < T > can beused inside a query

automatic type inference

Supported Commands

from . . . in . . . selecting object from ”collection”

where . . . specifies selection condition

select . . . specifies which what to return from the query

orderby . . . specifies by which property the result should besorted

join . . . on . . . merge several sequences

group . . . by . . . apply operation only to group of objects

Page 23: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Overview

Features

Example

Issues

Erlang

TBB

Cilk

X10

Conclusion

LINQ - Example

LINQ before transformation

v a r Found = from o i n Or de rswhere o . CustomerID == 84s e l e c t o . Cost ;

LINQ after transformation

va r Found =Orders . Where ( o=> o . CustomerID==84). S e l e c t ( o=>o . Cost ) ;

Page 24: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Overview

Features

Example

Issues

Erlang

TBB

Cilk

X10

Conclusion

LINQ - Example

u s i n g System . C o l l e c t i o n s . G e n e r i c ;u s i n g System . L inq ;

c l a s s Data {p u b l i c i n t i d ;p u b l i c s t r i n g name ;p u b l i c i n t age ;

} ;

p u b l i c c l a s s Simple {p u b l i c s t a t i c i n t Main ( s t r i n g [ ] a r g s ) {

v a r o b j s = new L i s t <Data> {new Data { i d =1, name=”Hans” , age =12} ,. . .

} ;

v a r r e s u l t = from o i n o b j swhere o . name == a r g s [ 0 ] && o . age >= 21o r d e r b y o . age a s c e n d i n gs e l e c t new {o . name , o . age } ;

f o r e a c h ( v a r o i n r e s u l t ) {System . C o n s o l e . W r i t e L i n e ( o ) ;

}

r e t u r n 0 ;}

} ;

Page 25: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Overview

Features

Example

Issues

Erlang

TBB

Cilk

X10

Conclusion

LINQ - Issues

Pro

declarative versus imperative

backend independent

allows automatically parallelization

async. and ’on-the-fly’ implementations

Contra

are automatic/anonymous types good or bad ?

Page 26: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Overview

Overview

functional programming language

message passing based concurrency model

originally developed by Ericson for developing telecomsoftware (basically 24/7 requirement)

has been released as open source

some usage: Wings 3D, the chat system of Facebooka

http://www.erlang.org

ahttp://www.facebook.com/notes.php?id=9445547199

Page 27: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Features

Features

functional programming language

’hot code’ swapping (replace code in running program)

designed for concurrency

message passing is 1st class citizensupport for SMP and distributed computing

FT support (if one ’erlang’ process dies simply restart thisone)

Page 28: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Features

Process creation

New process are created via the spawn function:

<PID> = spawn (<MODULE>, <FUNC>, <PARAMETERS>)

Message sending

For sending message the object that is ’piped’ into the PID viathe ’ !’ operator:

Pong PID ! { ping , N}

Page 29: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Features

Message reception

Message as handled by a receive block (”switch” statement+ pattern matching)

r e c e i v ep a t t e r n 1 −>

a c t i o n s 1 ;p a t t e r n 2 −>

a c t i o n s 2 ;. . . .pat te rnN

a c t i o n s Nend .

Page 30: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Example

−module ( tu t15 ) .−e x p o r t ( [ s t a r t /0 , p ing /2 , pong/0 ] ) .

p ing (0 , Pong PID ) −>Pong PID ! f i n i s h e d ,i o : fo rmat ( ”Ping F i n i s h e d ˜n” , [ ] ) ;

p ing (N, Pong PID ) −>Pong PID ! {ping , s e l f ( )} ,r e c e i v e

pong −>i o : fo rmat ( ”Ping r e c e i v e d pong ˜n” , [ ] )

end ,p i ng (N − 1 , Pong PID ) .

pong ( ) −>r e c e i v e

f i n i s h e d −>i o : fo rmat ( ”Pong F i n i s h e d ˜n” , [ ] ) ;

{ping , Ping PID} −>i o : fo rmat ( ”Pong r e c e i v e d p ing ˜n” , [ ] ) ,Ping PID ! pong ,pong ( )

end .

s t a r t ( ) −>Pong PID = spawn ( tut15 , pong , [ ] ) ,spawn ( tut15 , p ing , [ 10 , Pong PID ] ) .

Page 31: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

Overview

Features

Example

Issues

TBB

Cilk

X10

Conclusion

Erlang - Issues

Pro

functional + message passing avoids ’shared state’a

lightweight process model

supports running distributed across multiple machines

transparent transmission of any Erlang expression

alocal state is still possible

Contra

sometimes shared state is good to have

functional programming can be awkward

Page 32: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Overview

Features

Example

Issues

Cilk

X10

Conclusion

TBB - Overview

Overview

TBB - Threading Building Blocks

C++ library for multi-core programming

Originally developed by Intel and later open sourced (mostinteresting part is missing)

http://www.threadingbuildingblocks.org

Page 33: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Overview

Features

Example

Issues

Cilk

X10

Conclusion

TBB - Features

Features

parallel for

parallel reduce

auto partitioner (not in OSE)

pipeline support

containers (e.g. concurrent hashmap)

low level wrapper (e.g. atomic operations, locks)

memory manager

Page 34: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Overview

Features

Example

Issues

Cilk

X10

Conclusion

TBB - Example

// . . . s k i pped i n c l u d e s

u s i n g namespace tbb ;

c l a s s H e l l o W o r l d {p u b l i c :

p r o t e c t e d c h a r ∗name ;// sha r ed between a l l c l o n e s

H e l l o W o r l d ( c h a r ∗ name ) { t h i s−>name = name ; }

v o i d o p e r a t o r ( ) ( c o n s t b l o c k e d r a n g e <s i z e t >& r ) c o n s t {

s t d : : cout << name << ” [ ”<< r . b e g i n ( ) << ” , ”<< r . end ( ) << ” ] ” << s t d : : e n d l ;

// c r e a t e some a r t i f i c i a l l o adi n t i = 500000;w h i l e ( i−− != 0) { c o n t i n u e ; }

}} ;

i n t main ( i n t argc , c h a r ∗ a r g v [ ] ) {t a s k s c h e d u l e r i n i t i n i t ;

p a r a l l e l f o r ( b l o c k e d r a n g e <s i z e t >(0 , 10000 , 100) , H e l l o W o r l d ( ” f o o ” ) ) ;

r e t u r n 0 ;}

Page 35: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Overview

Features

Example

Issues

Cilk

X10

Conclusion

TBB - Issues

Pro

fits into object oriented approach

library approach is portable and don’t require changes ofthe programming language

no inheritance from a specific base class required

Contra

it’s up to the user to come up with an non-overlappingimplementation → CHEATING

can cause lot of object copies

the user is still responsible for the sync. (or the avoidanceof it)

problems without a ”range” cannot easily be represented

Page 36: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

Overview

Features

Example

Issues

X10

Conclusion

Cilk - Overview

Overview

research programming language

task parallel language based on C

a port for Java has been made

http://supertech.csail.mit.edu/cilk/

new startup company who created Cilk++

http://www.cilk.com/

Page 37: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

Overview

Features

Example

Issues

X10

Conclusion

Cilk - Features

Features

3 additional keywords to C programming language

cilkmarks a function to be a cilk function

syncused to wait for previously spawned functions

spawnspawn a new function/task off

Page 38: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

Overview

Features

Example

Issues

X10

Conclusion

Cilk - Example

#i n c l d u e <s t d i o . h>

c i l k f i b ( i n t n ){

i n t l e f t = 0 ;i n t r i g h t = 0 ;

i f ( n <= 1 ) r e t u r n 1 ;

l e f t = spawn f i b ( n−1);r i g h t = f i b ( n−2);

s y n c ;

r e t u r n l e f t + r i g h t ;}

v o i d main ( v o i d ) {i n t r e s u l t = 0 ;r e s u l t = spawn f i b ( 1 0 ) ;s y n c ;p r i n t f ( ” f i b (10)=\% i \n” , r e s u l t ) ;

}

Page 39: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

Overview

Features

Example

Issues

X10

Conclusion

Cilk - Issues

Pro

allows incremental parallelization of source code

single code base for sequential and parallel version

it’s composable to some degree

work stealing → work balancing

Contra

wait is not selective → wait always for all previouslyspawned ’tasks’

function call granularity might be limiting

Page 40: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Overview

Features

Example

Issues

Conclusion

X10 - Overview

Overview

part of HPCS (High Productivity Computing Systems)

developed by IBM

designed for non-uniform memory machines

http://x10.sourceforge.net/x10examples.shtml

Page 41: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Overview

Features

Example

Issues

Conclusion

X10 - Features

X10 almost like Java

Missing Features

concurrency (threads)arraysbuilt-in types

Additional Features

places (partitioned global address space)distributed multi-dimensional arraysclocks (barriers)activities (tasks)atomic blocks (TM)sequential for but parallel foreach

Page 42: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Overview

Features

Example

Issues

Conclusion

X10 - Example AtomicBlock

Atomic Blocks aka TM

act like a transaction

either the whole result of the block is visibleor nothing

automatic conflict detecting and resolution

atomic {. . .

}

Page 43: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Overview

Features

Example

Issues

Conclusion

X10 - Example Places

Create of a ’remote’ object

f i n a l p l a c e Other = h e r e . n e x t ( ) ;f i n a l T t = new T ( ) ;

f i n i s h a s y n c ( Other ){f i n a l T t1 = new T ( ) ;a s y n c ( t ) {

t . v a l = t1 ;}

}

async = async. taskfinish async = bocking

Page 44: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Overview

Features

Example

Issues

Conclusion

X10 - Issues

Pro

distributed global address space allows support optimizingprogramms for NUMA and distributed memoryarchoitectures

higher level abstractions for

Contra

cumbersome data fetching via multiple activities

cannot have delayed wait for async. activities

Page 45: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Conclusion

Bad ”Features”

explicit representation

granularity is fixedimplementation fixed

manual resource management/mapping

user responsible for synchr.

user responsible for data transfers

lack of verification

too many features (complicated and error prone)

domain specific designs

lack of tools

Page 46: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

Promising Features

implicit representation (like LINQ)

notion of distributed system (X10, Erlang)

sequential execution opportunity (OpenMP)

composability (Cilk, OpenMP, LINQ, Erlang)

automatic resource management (LINQ, OpenMP, Cilk)

balance defaults ⇐⇒ configuration (OpenMP)

incremental parallelization (LINQ, OpenMP, Cilk)

Page 47: Parallel Programming Modelsaeminium.dei.uc.pt/images/e/e2/ParallelProgrammingModels.pdf · parallel programming was not mainstream in the last decades there is no (good) support for

ParallelProgramming

Models

Sven Stork

Motivation

MPI

OpenMP

(P)LINQ

Erlang

TBB

Cilk

X10

Conclusion

The End

Thanks for the attention !Questions ???