<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div style="font-family: arial; font-size: 10pt; ">Thank, Daniel</div><div style="font-family: arial; font-size: 10pt; "><br></div><div style="font-family: arial; font-size: 10pt; ">Multiple threads are in evidence in my system monitor, but I wonder why I'm getting two different answers, one twice the other. The first is the parallel solution and the second is the non.</div><div style="font-family: arial; font-size: 10pt; "><br></div><div style="font-family: arial; font-size: 10pt; ">Michael</div><div style="font-family: arial; font-size: 10pt; "><br></div><div style="font-family: arial; font-size: 10pt; ">===========</div><div style="font-family: arial; font-size: 10pt; "><br></div><div><div><font class="Apple-style-span" face="arial" size="2">{-</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">import
Control.Parallel</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"><br></font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">nfib :: Int -> Int</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">nfib n | n <= 1 = 1</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"> | otherwise = par n1 (pseq n2 (n1 + n2 + 1))</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"> where n1 = nfib (n-1)</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"> n2 = nfib
(n-2)</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">-}</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"><br></font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">nfib :: Int -> Int</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">nfib n | n <= 1 = 1</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"> | otherwise = nfib (n-1) + nfib (n-2)</font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif"><br></font></div><div><font class="Apple-style-span" size="2" face="courier, monaco, monospace, sans-serif">main = do putStrLn $ show $ nfib 39</font></div></div><div><font class="Apple-style-span" face="arial"
size="2"><br></font></div><div><font class="Apple-style-span" face="arial" size="2">=============</font></div><div style="font-family: arial; font-size: 10pt; "><br></div><div style="font-family: arial; font-size: 10pt; ">[michael@hostname ~]$ ghc --make -threaded nfib.hs</div><div style="font-family: arial; font-size: 10pt; ">[1 of 1] Compiling Main ( nfib.hs, nfib.o )</div><div style="font-family: arial; font-size: 10pt; ">Linking nfib ...</div><div style="font-family: arial; font-size: 10pt; ">[michael@hostname ~]$ ./nfib +RTS -N3</div><div style="font-family: arial; font-size: 10pt; ">204668309</div><div style="font-family: arial; font-size: 10pt; ">[michael@hostname ~]$ ghc --make nfib.hs</div><div style="font-family: arial; font-size: 10pt; ">[1 of 1] Compiling Main ( nfib.hs, nfib.o )</div><div style="font-family: arial; font-size: 10pt; ">Linking nfib
...</div><div style="font-family: arial; font-size: 10pt; ">[michael@hostname ~]$ ./nfib</div><div style="font-family: arial; font-size: 10pt; ">102334155</div><div style="font-family: arial; font-size: 10pt; ">[michael@hostname ~]$ </div><div style="font-family: arial; font-size: 10pt; "><br></div><br><font class="Apple-style-span" face="arial" size="2">--- On </font><b style="font-family: arial; font-size: 10pt; ">Thu, 5/26/11, Daniel Fischer <i><daniel.is.fischer@googlemail.com></i></b><font class="Apple-style-span" face="arial" size="2"> wrote:</font><br><blockquote style="font-family: arial; font-size: 10pt; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; "><br>From: Daniel Fischer <daniel.is.fischer@googlemail.com><br>Subject: Re: [Haskell-cafe] Parallel compilation and execution?<br>To: haskell-cafe@haskell.org<br>Cc: "michael rice"
<nowgate@yahoo.com><br>Date: Thursday, May 26, 2011, 8:16 AM<br><br><div class="plainMail">On Thursday 26 May 2011 13:24:09, michael rice wrote:<br>> How do I compile and run this parallel program?<br>> Michael<br>> ===========================<br>> import Control.Parallel<br>> nfib :: Int -> Int<br>> nfib n | n <= 1 = 1 <br>> | otherwise = par n1 (seq n2 (n1 + n2 + 1))<br><br>The 'seq' here should be a 'pseq' to ensure that n2 is (started to be) <br>calculated before (n1 + n2 +1) is evaluated (iirc, currently, both work <br>with ghc, but it's not guaranteed for seq).<br> <br>> where <br>> n1 = nfib (n-1) <br>> n2 = nfib (n-2)<br>> {-nfib :: Int -> Intnfib n | n <= 1 =
1<br>> | otherwise = nfib (n-1) + nfib (n-2)-}<br>> <br>> main = do putStrLn $ show $ nfib 39<br>> ===========================<br>> [michael@hostname ~]$ ghc --make -threaded nfib.hs<br>> [michael@hostname ~]$ ./nfib +RTS -N3<br><br>In principle, that is the correct way to compile and run it (note that with <br>ghc-7, you don't need the --make).<br><br>> nfib: the flag -N3 requires the program to be built with<br>> -threaded<br><br>Have you previously compiled the programme without -threaded?<br>Unless you snipped the compilation messages, their absence strongly <br>indicates so.<br><br>If that is the case, you fell victim to ghc's recompilation-avoidance which <br>doesn't keep track of the flags a programme/module was compiled with, so it <br>saw that nothing [as far as it knows] changed, hence didn't recompile.<br><br>Then removing .o and .hi or passing -fforce-recomp will make it
recompile <br>and link with the threaded runtime.<br></div></blockquote></td></tr></table>