<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 -&gt; Main.Eval a<br><br>data Eval a = Done a<br><br>instance Monad Main.Eval where<br>&nbsp;&nbsp;&nbsp; return x = Main.Done x<br>&nbsp;&nbsp;&nbsp; Main.Done x &gt;&gt;= k = k x<br><br>runEval :: Main.Eval a -&gt; a<br>runEval (Main.Done a) = a<br><br>using :: a -&gt; Main.Strategy a -&gt; 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>--&nbsp; :t rseq 100 :: Num a =&gt; Eval a<br><br>rdeepseq :: NFData a =&gt; 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 =&gt; Eval a<br><br>dot :: Main.Strategy a -&gt; Main.Strategy a -&gt; Main.Strategy a<br>strat2 `dot` strat1 = strat2 . Main.runEval . strat1<br><br>------<br><br>normalize [] = []<br>normalize (False : xs) = <br>&nbsp; let ns = normalize xs<br>&nbsp; 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>&nbsp; let s = xor (xor x y) ci<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; co = (x &amp;&amp; y) || ((x || y) &amp;&amp; ci) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = (addc xs ys co)<br>&nbsp; in if s == False &amp;&amp; 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>&nbsp; let d = xor (xor x (not y)) (not ci)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; co = ((not x) &amp;&amp; y) || (((not x) || y) &amp;&amp; ci)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = (subc xs ys co) <br>&nbsp; in if d == False &amp;&amp; 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>&nbsp; let ns = normalize xs<br>&nbsp; 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>&nbsp;(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>&nbsp;where<br>&nbsp; l = (min (length xs) (length ys)) `div` 2<br>&nbsp; (xs0, xs1) = splitAt l xs<br>&nbsp; (ys0, ys1) = splitAt l ys<br>&nbsp; if l &gt; 32 then<br>&nbsp;&nbsp; strategy res = do<br>&nbsp;&nbsp;&nbsp; rpar (normalize (mulk3 xs0 ys0))<br>&nbsp;&nbsp;&nbsp; rpar (normalize (mulk3 xs1 ys1)) <br>&nbsp;&nbsp;&nbsp; rpar ((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1)))<br>&nbsp;&nbsp;&nbsp; rdeepseq res<br>&nbsp; else<br>&nbsp;&nbsp; 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>&nbsp;Cheers,<br>Burak.<br><br>import Control.Parallel<br>import Control.Parallel.Strategies<br><br>normalize [] = []<br>normalize (False : xs) = <br>&nbsp; let ns = normalize xs<br>&nbsp; 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>&nbsp;(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>&nbsp;where<br>&nbsp; l = (min (length xs) (length ys)) `div` 2<br>&nbsp; (xs0, xs1) = splitAt l xs<br>&nbsp; (ys0, ys1) = splitAt l ys<br>&nbsp; if l &gt; 32 then<br>&nbsp;&nbsp; (normalize (mulk3 xs0 ys0)) `par`<br>&nbsp;&nbsp; (normalize (mulk3 xs1 ys1)) `par`<br>&nbsp;&nbsp; ((mulk3 (add xs0 xs1) (add ys0 ys1)) `sub` (normalize (mulk3 xs0 ys0)) `sub` (normalize (mulk3 xs1 ys1)))<br>&nbsp; else<br>&nbsp;&nbsp; mul xs ys<br><br><br>                                               </div></div>                                               </div></body>
</html>