diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-08 01:51:54 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-12-08 01:51:54 +0000 |
commit | 99353021c0ff0b0f087be9a1a5289e3f07a02fa8 (patch) | |
tree | 4c3217112eea66883fb84fc2b5b8490c2a186114 /ws2015/ffp/blaetter | |
parent | 790b6131100d121a5d0e952dd498356cf4032523 (diff) | |
download | uni-99353021c0ff0b0f087be9a1a5289e3f07a02fa8.tar uni-99353021c0ff0b0f087be9a1a5289e3f07a02fa8.tar.gz uni-99353021c0ff0b0f087be9a1a5289e3f07a02fa8.tar.bz2 uni-99353021c0ff0b0f087be9a1a5289e3f07a02fa8.tar.xz uni-99353021c0ff0b0f087be9a1a5289e3f07a02fa8.zip |
FFP - 08
Diffstat (limited to 'ws2015/ffp/blaetter')
-rw-r--r-- | ws2015/ffp/blaetter/08/FFP_U08_Parallel.hs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/ws2015/ffp/blaetter/08/FFP_U08_Parallel.hs b/ws2015/ffp/blaetter/08/FFP_U08_Parallel.hs index 8615dad..34a77d2 100644 --- a/ws2015/ffp/blaetter/08/FFP_U08_Parallel.hs +++ b/ws2015/ffp/blaetter/08/FFP_U08_Parallel.hs | |||
@@ -114,7 +114,17 @@ main_A7_1seq = do | |||
114 | 114 | ||
115 | 115 | ||
116 | main_A7_1par :: IO () -- parallele Version | 116 | main_A7_1par :: IO () -- parallele Version |
117 | main_A7_1par = undefined -- !!! TODO !!! | 117 | main_A7_1par = do |
118 | rets <- runParIO $ mapM (\(a, b) -> spawnP $ length $ hanoi difficulty a b) args >>= mapM get | ||
119 | putStrLn $ unlines $ zipWith (\a r -> show a ++ ": " ++ show r) args rets | ||
120 | where | ||
121 | difficulty = 25 | ||
122 | args = [ (1, 2) | ||
123 | , (1, 3) | ||
124 | , (2, 3) | ||
125 | , (3, 1) | ||
126 | ] | ||
127 | |||
118 | 128 | ||
119 | 129 | ||
120 | -- Hilfsfunktionen, zur Erzeugung von Rechnenlast, bitte nicht verändern: | 130 | -- Hilfsfunktionen, zur Erzeugung von Rechnenlast, bitte nicht verändern: |
@@ -150,7 +160,15 @@ quicksortS (x:xs) = result | |||
150 | hisort = quicksortS [y | y <- xs, y >= x] | 160 | hisort = quicksortS [y | y <- xs, y >= x] |
151 | 161 | ||
152 | quicksortP :: [Integer] -> [Integer] | 162 | quicksortP :: [Integer] -> [Integer] |
153 | quicksortP xs = undefined -- !!! TODO !!! | 163 | quicksortP [] = [] |
164 | quicksortP (x:xs) = runEval $ do | ||
165 | lows <- strat $ quicksortP [y | y <- xs, y < x] | ||
166 | highs <- strat $ quicksortP [y | y <- xs, y >= x] | ||
167 | return $ lows ++ (x : highs) | ||
168 | where | ||
169 | strat = rparWith rdeepseq -- rpar, rseq | ||
170 | -- rparWith rdeepseq < rpar ~~ rseq | ||
171 | -- rpar macht nur minimale arbeit innerhalb des sparks (nur WHNF), der rest der arbeit wird am ende (bei return) in einem thread gemacht | ||
154 | 172 | ||
155 | 173 | ||
156 | main_A7_2 = do | 174 | main_A7_2 = do |
@@ -203,7 +221,10 @@ payL acc 0 coins = [acc] | |||
203 | payL acc _ [] = [] | 221 | payL acc _ [] = [] |
204 | payL acc val ((c,qty):coins) | 222 | payL acc val ((c,qty):coins) |
205 | | c > val = payL acc val coins | 223 | | c > val = payL acc val coins |
206 | | otherwise = left ++ right | 224 | | otherwise = let -- speedup by ~100% compared to (left ++ right) |
225 | l = right `par` left | ||
226 | r = right | ||
227 | in l ++ r | ||
207 | where | 228 | where |
208 | left = payL (c:acc) (val - c) coins' | 229 | left = payL (c:acc) (val - c) coins' |
209 | right = payL acc val coins | 230 | right = payL acc val coins |