<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Excuse me, in the last post I forgot to send the last version of the code<br>and some some needed functions.<br><br>So sorry for spamming.<br><br>Here is the code:<br><br>import Control.Parallel<br>import Control.Parallel.Strategies<br>import Control.DeepSeq<br>------<br><br>type Strategy a = a -> Main.Eval a<br><br>data Eval a = Done a<br><br>instance Monad Main.Eval where<br> return x = Main.Done x<br> Main.Done x >>= k = k x<br><br>runEval :: Main.Eval a -> a<br>runEval (Main.Done a) = a<br><br>using :: a -> Main.Strategy a -> a<br>x `using` strat = Main.runEval (strat x)<br><br>rseq :: Main.Strategy a<br>rseq x = x `pseq` Main.Done x<br>-- runEval(rseq 100) = 100<br>-- :t rseq 100 :: Num a => Eval a<br><br>rdeepseq :: NFData a => Main.Strategy a<br>rdeepseq x = rnf x `pseq` return x<br><br>rpar :: Main.Strategy a<br>rpar x = x `par` Main.Done x<br>-- runEval(rpar 100) = 100<br>-- :t rpar 100 :: Num a => Eval a<br><br>dot :: Main.Strategy a -> Main.Strategy a -> Main.Strategy a<br>strat2 `dot` strat1 = strat2 . Main.runEval . strat1<br><br>------<br><br>normalize [] = []<br>normalize (False : xs) = <br> let ns = normalize xs<br> in if ns == [] then [] else (False : ns)<br>normalize (True : xs) = True : (normalize xs)<br><br>mul [] _ = []<br>mul (False : xs) ys = False : (mul xs ys)<br>mul (True : xs) ys = mul (False : xs) ys `add` ys<br><br>addc [] ys ci = add ys (normalize [ci])<br>addc xs [] ci = add xs (normalize [ci])<br>addc (x : xs) (y : ys) ci = <br> let s = xor (xor x y) ci<br> co = (x && y) || ((x || y) && ci) <br> a = (addc xs ys co)<br> in if s == False && a == [] then [] else s : a<br><br>add [] ys = ys<br>add xs [] = xs<br>add xs ys = addc xs ys False<br><br>subc xs [] ci = sub xs (normalize [ci])<br>subc (x : xs) (y : ys) ci = <br> let d = xor (xor x (not y)) (not ci)<br> co = ((not x) && y) || (((not x) || y) && ci)<br> s = (subc xs ys co) <br> in if d == False && s == [] then [] else d : s<br><br>sub xs [] = xs<br>sub xs ys = subc xs ys False<br><br>xor x y = x /= y<br><br>normalize [] = []<br>normalize (False : xs) = <br> let ns = normalize xs<br> in if ns == [] then [] else (False : ns)<br>normalize (True : xs) = True : (normalize xs)<br><br>mul [] _ = []<br>mul (False : xs) ys = False : (mul xs ys)<br>mul (True : xs) ys = mul (False : xs) ys `add` ys<br><br>mulk3 [] _ = []<br>mulk3 _ [] = []<br>mulk3 xs ys =<br> (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))))) using` strategy<br> where<br> l = (min (length xs) (length ys)) `div` 2<br> (xs0, xs1) = splitAt l xs<br> (ys0, ys1) = splitAt l ys<br> if l > 32 then<br> strategy res = do<br> rpar (normalize (mulk3 xs0 ys0))<br> rpar (normalize (mulk3 xs1 ys1)) <br> rpar ((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1)))<br> rdeepseq res<br> else<br> mul xs ys<br><br><div><hr id="stopSpelling">From: ekcburak@hotmail.com<br>To: haskell-cafe@haskell.org<br>Subject: Karatsuba Multiplication Parallel<br>Date: Fri, 16 Sep 2011 10:52:14 +0000<br><br>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}
</style>
<div dir="ltr">
Dear All,<br><br>I am trying to parallelize the below Karatsuba multiplication code. However, <br>at each trial of mine the error message speaking of "incorrect indentation"<br>is returned. I could not come up with ideas to solve the problem.<br><br>I will be more than glad and appreciated, if any of you sheds light on the<br>issue and point out the problem with its solution.<br><br>Many thanks in advance,<br><br> Cheers,<br>Burak.<br><br>import Control.Parallel<br>import Control.Parallel.Strategies<br><br>normalize [] = []<br>normalize (False : xs) = <br> let ns = normalize xs<br> in if ns == [] then [] else (False : ns)<br>normalize (True : xs) = True : (normalize xs)<br><br>mul [] _ = []<br>mul (False : xs) ys = False : (mul xs ys)<br>mul (True : xs) ys = mul (False : xs) ys `add` ys<br><br>mulk3 [] _ = []<br>mulk3 _ [] = []<br>mulk3 xs ys =<br> (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)))))<br> where<br> l = (min (length xs) (length ys)) `div` 2<br> (xs0, xs1) = splitAt l xs<br> (ys0, ys1) = splitAt l ys<br> if l > 32 then<br> (normalize (mulk3 xs0 ys0)) `par`<br> (normalize (mulk3 xs1 ys1)) `par`<br> ((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1)))<br> else<br> mul xs ys<br><br><br>                                            </div></div>                                            </div></body>
</html>