[Haskell-cafe] Karatsuba Multiplication Parallel
Burak Ekici
ekcburak at hotmail.com
Fri Sep 16 12:52:14 CEST 2011
Dear All,
I am trying to parallelize the below Karatsuba multiplication code. However,
at each trial of mine the error message speaking of "incorrect indentation"
is returned. I could not come up with ideas to solve the problem.
I will be more than glad and appreciated, if any of you sheds light on the
issue and point out the problem with its solution.
Many thanks in advance,
Cheers,
Burak.
import Control.Parallel
import Control.Parallel.Strategies
normalize [] = []
normalize (False : xs) =
let ns = normalize xs
in if ns == [] then [] else (False : ns)
normalize (True : xs) = True : (normalize xs)
mul [] _ = []
mul (False : xs) ys = False : (mul xs ys)
mul (True : xs) ys = mul (False : xs) ys `add` ys
mulk3 [] _ = []
mulk3 _ [] = []
mulk3 xs ys =
(normalize (mulk3 xs0 ys0)) `add` (replicate l False ++ (((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1))) `add` (replicate l False ++ (normalize (mulk3 xs1 ys1)))))
where
l = (min (length xs) (length ys)) `div` 2
(xs0, xs1) = splitAt l xs
(ys0, ys1) = splitAt l ys
if l > 32 then
(normalize (mulk3 xs0 ys0)) `par`
(normalize (mulk3 xs1 ys1)) `par`
((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1)))
else
mul xs ys
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110916/78dfeaf5/attachment.htm>
More information about the Haskell-Cafe
mailing list