Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Concurrent and Multicore Haskell
Concurrent Haskell For responsive programs that multitask Plain old threads, with a few twists Popular programming model
A simple example backgroundWrite path contents = done <- newEmptyMVar forkIO $  do writeFile path contents putMVar done () return done
Imperative  code!? Threads, assignment, “return”...  huh ? Haskell is a  multi-paradigm  language Pure by default Imperative when you need it
What’s an MVar? An  atomic  variable Either empty or full takeMVar blocks if empty putMVar blocks if full Nice building block for mutual exclusion
Coding with MVars Higher-order programming modifyMVar: atomic modification Safe critical sections Combine MVars into a list FIFO message channels
FIFO channels (Chan) Writer does not block Reader blocks if channel is empty Duplicate a channel Broadcast to multiple threads
Smokin’ performance From the “Computer Language Benchmark Game” Create 503 threads Circulate token in a ring Iterate 10 million times Language Seconds GHC 6.70 Erlang 7.49 Scala 53.35 C / NPTL 56.74 Ruby 1890.92
Runtime GHC threads are incredibly cheap Run millions at a time File and network APIs are blocking Simple mental model Async I/O underneath
Time for a change That didn’t rewire my brain at all! Where’s the crazy stuff?
Purity and parallelism
Concurrent vs parallel Concurrency Do many unrelated things “at once” Goals are  responsiveness  and  multitasking Parallelism Get a faster answer with multiple CPUs
Pure laziness Haskell is not just  functional  (aka  pure ) It’s  non-strict : work is deferred until needed Implemented via  lazy evaluation Can laziness and parallelism mix?
Laziness is the  default What if something must happen  right now ? Use a special combinator seq  – adds strictness Evaluates its 1st argument, returns its 2nd
A simple use of  seq daxpy k xs ys = zipWith f xs ys where  f x y = k * x + y daxpy’ k xs ys = zipWith f xs ys where  f x y =  let  a = k * x + y in   a  `seq`  a
par “Sparks” its first argument Sparked evaluation occurs  in parallel Returns its second
Our favourite whipping boy pfib n | n <= 1 = 1 pfib n = a  `par`  (b  `pseq`  (a + b + 1)) where  a = pfib (n-1) b = pfib (n-2)
Parallel strategies par  might be cute, but it’s  fiddly Manual annotations are a pain Time for a Haskell hacker’s favourite hobby: Abstraction!
Algorithm + evaluation What’s a  strategy ? How to evaluate an expression Result is in a  normal form
Head normal form “What is my value?” Completely evaluates an expression Similar to traditional languages
Weak  head normal form “What is my  constructor ?” data  Maybe a =  Nothing |  Just  a Does not give us a complete value Only  what constructor it was built with
Combining strategies A strategy is a normal Haskell function Want to apply some strategy in parallel across an entire list? parList strat []  = () parList strat (x:xs) = strat x  `par`  parList strat xs
Strategies at work Map a function over a list in parallel Pluggable evaluation strategy per element using x strat = strat x  `seq`  x parMap strat f xs = map f xs  `using`  parList strat
True or false? Inherent parallelism will save us! Functional programs have  oodles ! All we need to do is exploit it!
Limit studies Gives a maximum  theoretical  benefit Model a resource, predict effect of changing it Years of use in CPU & compiler design Early days for functional languages
So ... true or false? Is there lots of “free” parallelism? Very doubtful Why? A familiar plague Data dependencies Code not  written  to be parallel  isn’t
Current research Feedback-directed implicit parallelism Automated  par  annotations Tuned via profiled execution Results to date are fair Up to 2x speedups in some cases
Parallelism is hard Embarrassingly parallel: not so bad Hadoop, image convolution Regular, but squirrelly: pretty tough Marching cube isosurface interpolation, FFT Irregular or nested: really nasty FEM crack propagation, coupled climate models
Current state of the art Most parallelism added by hand Manual coordination & data layout MPI is akin to assembly language Difficult to use, even harder to tune Irregular data is especially problematic
Nested data parallelism Parallel functions invoke other parallel code One SIMD “thread of control” Friendly programming model
NPH automation Compiler transforms code and data Irregular, nested data becomes flat, regular Complexity hidden from the programmer
Current status Work in progress Exciting work, lots of potential Attack  both  performance and usability Haskell’s purity is a critical factor
Fixing threaded programming
Concurrency is hard Race conditions Data corruption Deadlock
Transactional memory Fairly new as a practical programming tool Implemented for several languages Typically comes with weird quirks Haskell’s implementation is  beautiful
Atomic execution Either an entire block succeeds, or it all fails Failed transactions retry automatically Type system forbids non-atomic actions No file or network access
How does retry occur? When to wake a thread and retry a transaction? No programmer input needed Runtime tracks variables read by a failed transaction, retries  automatically
Composability All transactions are  flat Calling transactional code from the current transaction is normal This simply extends the current transaction
Early abort The  retry  action manually aborts a transaction early It will still automatically retry Handy if we know the transaction must fail
Choosing an alternative The  orElse  action combines two transactions If the first succeeds, both succeed Otherwise, it tries the second If the second succeeds, both succeed If both fail, the first will be retried
STM and IPC TVar – simple shared variable TMVar  –  atomic variable (like an MVar) TChan – FIFO channel If the enclosing transaction retries... ...then so does any modification
A useful analogy Concurrency Mutexes, semaphores, condition variables Software transactional memory Memory management malloc, free, manual refcounting Garbage collection
Manual / auto tradeoffs Memory management Performance, footprint Safety against memory leaks, corruption Concurrency Fine tuning for high contention Safety against deadlocks, corruption
Brief recap Concurrency Fast, cheap threads Blocking I/O and STM are  friendly to your brain Multicore parallelism Explicit control or a strategic approach NPH offers an exciting future

More Related Content

What's hot

Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
Bryan O'Sullivan
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
Bryan O'Sullivan
 
Real World Haskell: Lecture 3
Real World Haskell: Lecture 3Real World Haskell: Lecture 3
Real World Haskell: Lecture 3
Bryan O'Sullivan
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog
3Pillar Global
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Philip Schwarz
 
Python
PythonPython
Python
Kumar Gaurav
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
Bryan O'Sullivan
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
Mario Fusco
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Philip Schwarz
 
Lisp
LispLisp
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
chenge2k
 
Python ppt
Python pptPython ppt
Python ppt
Anush verma
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
Philip Schwarz
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
Devnology
 

What's hot (20)

Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
Real World Haskell: Lecture 3
Real World Haskell: Lecture 3Real World Haskell: Lecture 3
Real World Haskell: Lecture 3
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
 
Python
PythonPython
Python
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
 
Lisp
LispLisp
Lisp
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Python ppt
Python pptPython ppt
Python ppt
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 

Viewers also liked

The other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang peopleThe other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang people
Bryan O'Sullivan
 
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CCTechnologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
EwaB
 
Your Skin Is Not The Edge Of You
Your Skin Is Not The Edge Of YouYour Skin Is Not The Edge Of You
Your Skin Is Not The Edge Of You
Richard Sandford
 
Les tic a l'educació. una nova oportunitat per al canvi
Les tic a l'educació. una nova oportunitat per al canviLes tic a l'educació. una nova oportunitat per al canvi
Les tic a l'educació. una nova oportunitat per al canvi
Gemma Tur
 
Antibeeps
AntibeepsAntibeeps
Antibeeps
Richard Sandford
 
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwania
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwaniaKonferencja PK Koszalin 2008 - Długi ogon wyszukiwania
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwania
EwaB
 
Consciousness Based Educ 2 A Deans
Consciousness Based Educ 2 A DeansConsciousness Based Educ 2 A Deans
Consciousness Based Educ 2 A Deans
AMTR
 
Trg Ebook Healthcare And Social Media
Trg Ebook Healthcare And Social MediaTrg Ebook Healthcare And Social Media
Trg Ebook Healthcare And Social Media
Jaci Russo
 
David Eisenberg Christchurch 8 Sep 2008
David Eisenberg Christchurch 8 Sep 2008David Eisenberg Christchurch 8 Sep 2008
David Eisenberg Christchurch 8 Sep 2008
twbishop
 
Origens i consolidació del catalanisme
Origens i consolidació del catalanismeOrigens i consolidació del catalanisme
Origens i consolidació del catalanisme
Gemma Ajenjo Rodriguez
 
Micro-Interactions
Micro-InteractionsMicro-Interactions
Micro-Interactions
Critical Mass
 
Web Marketing Week5
Web Marketing Week5Web Marketing Week5
Web Marketing Week5
cghb1210
 
10 business models that rocked in 2010
10 business models that rocked in 201010 business models that rocked in 2010
10 business models that rocked in 2010
supermanchander
 
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa BiałekBadanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
EwaB
 
SXSW 2010 Creative Inspiration
SXSW 2010 Creative InspirationSXSW 2010 Creative Inspiration
SXSW 2010 Creative Inspiration
Critical Mass
 
Wedgeofmisery V1b
Wedgeofmisery V1bWedgeofmisery V1b
Wedgeofmisery V1b
guest4cea8c
 
An Inside Look at Campaign 2008
An Inside Look at Campaign 2008An Inside Look at Campaign 2008
An Inside Look at Campaign 2008
tarekrizk
 
Devg Tot Brn F Acad Exceln Lynch
Devg Tot Brn F Acad Exceln    LynchDevg Tot Brn F Acad Exceln    Lynch
Devg Tot Brn F Acad Exceln Lynch
AMTR
 
Montaje ask tx rx simple
Montaje ask tx rx simpleMontaje ask tx rx simple
Montaje ask tx rx simple
Amaury Méndez
 
Biblioteka-Slupsk-Ewa-Bialek
Biblioteka-Slupsk-Ewa-BialekBiblioteka-Slupsk-Ewa-Bialek
Biblioteka-Slupsk-Ewa-Bialek
EwaB
 

Viewers also liked (20)

The other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang peopleThe other side of functional programming: Haskell for Erlang people
The other side of functional programming: Haskell for Erlang people
 
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CCTechnologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
Technologia Informacyjna - ćwiczenia, wyszukiwanie informacji, CC
 
Your Skin Is Not The Edge Of You
Your Skin Is Not The Edge Of YouYour Skin Is Not The Edge Of You
Your Skin Is Not The Edge Of You
 
Les tic a l'educació. una nova oportunitat per al canvi
Les tic a l'educació. una nova oportunitat per al canviLes tic a l'educació. una nova oportunitat per al canvi
Les tic a l'educació. una nova oportunitat per al canvi
 
Antibeeps
AntibeepsAntibeeps
Antibeeps
 
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwania
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwaniaKonferencja PK Koszalin 2008 - Długi ogon wyszukiwania
Konferencja PK Koszalin 2008 - Długi ogon wyszukiwania
 
Consciousness Based Educ 2 A Deans
Consciousness Based Educ 2 A DeansConsciousness Based Educ 2 A Deans
Consciousness Based Educ 2 A Deans
 
Trg Ebook Healthcare And Social Media
Trg Ebook Healthcare And Social MediaTrg Ebook Healthcare And Social Media
Trg Ebook Healthcare And Social Media
 
David Eisenberg Christchurch 8 Sep 2008
David Eisenberg Christchurch 8 Sep 2008David Eisenberg Christchurch 8 Sep 2008
David Eisenberg Christchurch 8 Sep 2008
 
Origens i consolidació del catalanisme
Origens i consolidació del catalanismeOrigens i consolidació del catalanisme
Origens i consolidació del catalanisme
 
Micro-Interactions
Micro-InteractionsMicro-Interactions
Micro-Interactions
 
Web Marketing Week5
Web Marketing Week5Web Marketing Week5
Web Marketing Week5
 
10 business models that rocked in 2010
10 business models that rocked in 201010 business models that rocked in 2010
10 business models that rocked in 2010
 
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa BiałekBadanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
Badanie zapytań do wyszukiwarek internetowych - artykuł - Ewa Białek
 
SXSW 2010 Creative Inspiration
SXSW 2010 Creative InspirationSXSW 2010 Creative Inspiration
SXSW 2010 Creative Inspiration
 
Wedgeofmisery V1b
Wedgeofmisery V1bWedgeofmisery V1b
Wedgeofmisery V1b
 
An Inside Look at Campaign 2008
An Inside Look at Campaign 2008An Inside Look at Campaign 2008
An Inside Look at Campaign 2008
 
Devg Tot Brn F Acad Exceln Lynch
Devg Tot Brn F Acad Exceln    LynchDevg Tot Brn F Acad Exceln    Lynch
Devg Tot Brn F Acad Exceln Lynch
 
Montaje ask tx rx simple
Montaje ask tx rx simpleMontaje ask tx rx simple
Montaje ask tx rx simple
 
Biblioteka-Slupsk-Ewa-Bialek
Biblioteka-Slupsk-Ewa-BialekBiblioteka-Slupsk-Ewa-Bialek
Biblioteka-Slupsk-Ewa-Bialek
 

Similar to BayFP: Concurrent and Multicore Haskell

Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
Takayuki Muranushi
 
The Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms ProgrammingThe Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms Programming
Juan J. Merelo
 
ParaSail
ParaSail  ParaSail
ParaSail
AdaCore
 
Java 8 - A step closer to Parallelism
Java 8 - A step closer to ParallelismJava 8 - A step closer to Parallelism
Java 8 - A step closer to Parallelism
jbugkorea
 
The Joy Of Functional Programming
The Joy Of Functional ProgrammingThe Joy Of Functional Programming
The Joy Of Functional Programming
jasondew
 
Stay fresh
Stay freshStay fresh
Stay fresh
Ahmed Mohamed
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
Sentifi
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
Zvi Avraham
 
Evolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded ProgrammingEvolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded Programming
GlobalLogic Ukraine
 
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
MLconf
 
Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016
Chris Fregly
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
siouxhotornot
 
"Hints" talk at Walchand College Sangli, March 2017
"Hints" talk at Walchand College Sangli, March 2017"Hints" talk at Walchand College Sangli, March 2017
"Hints" talk at Walchand College Sangli, March 2017
Neeran Karnik
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
Ted Leung
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
stasimus
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
Prof. Wim Van Criekinge
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
oscon2007
 
Concurrent programming1
Concurrent programming1Concurrent programming1
Concurrent programming1
Nick Brandaleone
 
Rust presentation convergeconf
Rust presentation convergeconfRust presentation convergeconf
Rust presentation convergeconf
Krishna Kumar Thokala
 

Similar to BayFP: Concurrent and Multicore Haskell (20)

Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
The Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms ProgrammingThe Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms Programming
 
ParaSail
ParaSail  ParaSail
ParaSail
 
Java 8 - A step closer to Parallelism
Java 8 - A step closer to ParallelismJava 8 - A step closer to Parallelism
Java 8 - A step closer to Parallelism
 
The Joy Of Functional Programming
The Joy Of Functional ProgrammingThe Joy Of Functional Programming
The Joy Of Functional Programming
 
Stay fresh
Stay freshStay fresh
Stay fresh
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
Evolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded ProgrammingEvolution of JDK Tools for Multithreaded Programming
Evolution of JDK Tools for Multithreaded Programming
 
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
 
Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
 
"Hints" talk at Walchand College Sangli, March 2017
"Hints" talk at Walchand College Sangli, March 2017"Hints" talk at Walchand College Sangli, March 2017
"Hints" talk at Walchand College Sangli, March 2017
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Concurrent programming1
Concurrent programming1Concurrent programming1
Concurrent programming1
 
Rust presentation convergeconf
Rust presentation convergeconfRust presentation convergeconf
Rust presentation convergeconf
 

Recently uploaded

Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
The Digital Insurer
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
ScyllaDB
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
Liveplex
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
Vijayananda Mohire
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
SeasiaInfotech2
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
Edge AI and Vision Alliance
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 

Recently uploaded (20)

Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 

BayFP: Concurrent and Multicore Haskell

  • 2. Concurrent Haskell For responsive programs that multitask Plain old threads, with a few twists Popular programming model
  • 3. A simple example backgroundWrite path contents = done <- newEmptyMVar forkIO $ do writeFile path contents putMVar done () return done
  • 4. Imperative code!? Threads, assignment, “return”... huh ? Haskell is a multi-paradigm language Pure by default Imperative when you need it
  • 5. What’s an MVar? An atomic variable Either empty or full takeMVar blocks if empty putMVar blocks if full Nice building block for mutual exclusion
  • 6. Coding with MVars Higher-order programming modifyMVar: atomic modification Safe critical sections Combine MVars into a list FIFO message channels
  • 7. FIFO channels (Chan) Writer does not block Reader blocks if channel is empty Duplicate a channel Broadcast to multiple threads
  • 8. Smokin’ performance From the “Computer Language Benchmark Game” Create 503 threads Circulate token in a ring Iterate 10 million times Language Seconds GHC 6.70 Erlang 7.49 Scala 53.35 C / NPTL 56.74 Ruby 1890.92
  • 9. Runtime GHC threads are incredibly cheap Run millions at a time File and network APIs are blocking Simple mental model Async I/O underneath
  • 10. Time for a change That didn’t rewire my brain at all! Where’s the crazy stuff?
  • 12. Concurrent vs parallel Concurrency Do many unrelated things “at once” Goals are responsiveness and multitasking Parallelism Get a faster answer with multiple CPUs
  • 13. Pure laziness Haskell is not just functional (aka pure ) It’s non-strict : work is deferred until needed Implemented via lazy evaluation Can laziness and parallelism mix?
  • 14. Laziness is the default What if something must happen right now ? Use a special combinator seq – adds strictness Evaluates its 1st argument, returns its 2nd
  • 15. A simple use of seq daxpy k xs ys = zipWith f xs ys where f x y = k * x + y daxpy’ k xs ys = zipWith f xs ys where f x y = let a = k * x + y in a `seq` a
  • 16. par “Sparks” its first argument Sparked evaluation occurs in parallel Returns its second
  • 17. Our favourite whipping boy pfib n | n <= 1 = 1 pfib n = a `par` (b `pseq` (a + b + 1)) where a = pfib (n-1) b = pfib (n-2)
  • 18. Parallel strategies par might be cute, but it’s fiddly Manual annotations are a pain Time for a Haskell hacker’s favourite hobby: Abstraction!
  • 19. Algorithm + evaluation What’s a strategy ? How to evaluate an expression Result is in a normal form
  • 20. Head normal form “What is my value?” Completely evaluates an expression Similar to traditional languages
  • 21. Weak head normal form “What is my constructor ?” data Maybe a = Nothing | Just a Does not give us a complete value Only what constructor it was built with
  • 22. Combining strategies A strategy is a normal Haskell function Want to apply some strategy in parallel across an entire list? parList strat [] = () parList strat (x:xs) = strat x `par` parList strat xs
  • 23. Strategies at work Map a function over a list in parallel Pluggable evaluation strategy per element using x strat = strat x `seq` x parMap strat f xs = map f xs `using` parList strat
  • 24. True or false? Inherent parallelism will save us! Functional programs have oodles ! All we need to do is exploit it!
  • 25. Limit studies Gives a maximum theoretical benefit Model a resource, predict effect of changing it Years of use in CPU & compiler design Early days for functional languages
  • 26. So ... true or false? Is there lots of “free” parallelism? Very doubtful Why? A familiar plague Data dependencies Code not written to be parallel isn’t
  • 27. Current research Feedback-directed implicit parallelism Automated par annotations Tuned via profiled execution Results to date are fair Up to 2x speedups in some cases
  • 28. Parallelism is hard Embarrassingly parallel: not so bad Hadoop, image convolution Regular, but squirrelly: pretty tough Marching cube isosurface interpolation, FFT Irregular or nested: really nasty FEM crack propagation, coupled climate models
  • 29. Current state of the art Most parallelism added by hand Manual coordination & data layout MPI is akin to assembly language Difficult to use, even harder to tune Irregular data is especially problematic
  • 30. Nested data parallelism Parallel functions invoke other parallel code One SIMD “thread of control” Friendly programming model
  • 31. NPH automation Compiler transforms code and data Irregular, nested data becomes flat, regular Complexity hidden from the programmer
  • 32. Current status Work in progress Exciting work, lots of potential Attack both performance and usability Haskell’s purity is a critical factor
  • 34. Concurrency is hard Race conditions Data corruption Deadlock
  • 35. Transactional memory Fairly new as a practical programming tool Implemented for several languages Typically comes with weird quirks Haskell’s implementation is beautiful
  • 36. Atomic execution Either an entire block succeeds, or it all fails Failed transactions retry automatically Type system forbids non-atomic actions No file or network access
  • 37. How does retry occur? When to wake a thread and retry a transaction? No programmer input needed Runtime tracks variables read by a failed transaction, retries automatically
  • 38. Composability All transactions are flat Calling transactional code from the current transaction is normal This simply extends the current transaction
  • 39. Early abort The retry action manually aborts a transaction early It will still automatically retry Handy if we know the transaction must fail
  • 40. Choosing an alternative The orElse action combines two transactions If the first succeeds, both succeed Otherwise, it tries the second If the second succeeds, both succeed If both fail, the first will be retried
  • 41. STM and IPC TVar – simple shared variable TMVar – atomic variable (like an MVar) TChan – FIFO channel If the enclosing transaction retries... ...then so does any modification
  • 42. A useful analogy Concurrency Mutexes, semaphores, condition variables Software transactional memory Memory management malloc, free, manual refcounting Garbage collection
  • 43. Manual / auto tradeoffs Memory management Performance, footprint Safety against memory leaks, corruption Concurrency Fine tuning for high contention Safety against deadlocks, corruption
  • 44. Brief recap Concurrency Fast, cheap threads Blocking I/O and STM are friendly to your brain Multicore parallelism Explicit control or a strategic approach NPH offers an exciting future