Documente Academic
Documente Profesional
Documente Cultură
7 ianuarie 2010
Mihai Maruseac
2
Sumar
• Paralelism și Haskell
o De ce paralelism?
o De ce Haskell? De ce nu Haskell?
• Construcții specifice
o Threads. MVars,. Chans
o seq, par
• Communicating Haskell Processes
3
Paralelism (1)
4
Paralelism (2)
5
Pro Haskell
6
Contra Haskell
7
Threads (1)
8
Threads (2)
9
Threads (3)
10
Operatorii seq si par (1)
• De ce 2 funcții?
11
Operatorii seq si par (2)
import Control.Parallel
import System.Environment (getArgs)
main = do
args <- getArgs
let n = read $ head args
putStrLn $ show $ fact n
putStrLn $ show $ prod2 n
12
Communicating Haskell Processes
• Canalele sincrone
13
CHP – terminarea algoritmilor
14
CHP – Exemplu
filterDiv :: Integer -> Chanin Integer -> Chanout Integer -> CHP ()
filterDiv n input output = forever $ do
x <- readChannel input
when (x `mod` n /= 0) $ writeChannel output x
end :: Chanin Integer -> Chanout Integer -> CHP ()
end input output = do
x <- readChannel input
writeChannel output x
(filterDiv x |->| end) input output
genStream :: Chanout Integer -> CHP ()
genStream output = mapM_ (writeChannel output) [2..]
15
Bibliografie
• http://www.embedded.com/design/multicore/201500267
• http://www.embedded.com/design/multicore/201804960
• http://www.embedded.com/design/multicore/201806715
• http://chplib.wordpress.com/
• http://book.realworldhaskell.org/read/
16
The End
?
07.01.09 17