<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div>Hi Alex,</div><div><br></div>I had previously looked at OpenMP (Fortran) and when I saw par and seq in Control.Parallel I got a sense of common terminology, sections of code that can be executed in parallel and sections of code that must be executed sequentially. I haven't looked at Control.Concurrent yet.<div><br></div><div>The original reason I took a look at Haskell (and Erlang) was multi-core CPUs were becoming common and I wanted to learn to take advantage of them, but Haskell's learning curve has been so steep I've been occupied with learning other aspects of the language and only now have turned again to try my hand at its parallelizing features.</div><div><br></div><div>Thanks,</div><div><br></div><div>Michael&nbsp;<br><br>--- On <b>Fri, 5/27/11, Alex Mason <i>&lt;axman6@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid
 rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Alex Mason &lt;axman6@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] Parallel compilation and execution?<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: "David Virebayre" &lt;dav.vire+haskell@gmail.com&gt;, haskell-cafe@haskell.org, "Daniel Fischer" &lt;daniel.is.fischer@googlemail.com&gt;<br>Date: Friday, May 27, 2011, 6:05 AM<br><br><div id="yiv337701939">Hi Michael,<div><br></div><div>OpenMP is a very different beast, and was developed to help get over the shortcomings that languages like C and FORTRAN have with respect to parallel and concurrent programming (pthreads were about all there was before OpenMP). OpenMP lets you specify regions of code that should be run in multiple threads at once, each with a unique ID. &nbsp;Here is an example of (part of) a parallel merge sort I've been working on</div><div><br></div><div><blockquote type="cite"><div><font
 class="yiv337701939Apple-style-span" color="#000000">static void</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">pmergesort(long int * in, long int * tmp, long int n, int nthread)</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">{</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;long int nhalf = n/2;</font></div><div><font class="yiv337701939Apple-style-span" color="#000000"><br></font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;if(n &lt;= N_small)</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;{</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;insertsort1(in, n);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return;</font></div><div><font
 class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="yiv337701939Apple-style-span" color="#000000"><br></font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;if(nthread &gt; 1)</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;{</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;#pragma omp parallel num_threads(2)</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(omp_get_thread_num() == 0)</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pmergesort(tmp, &nbsp; &nbsp; &nbsp; in, &nbsp; &nbsp;
 &nbsp; &nbsp; nhalf, nthread&gt;&gt;1);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else pmergesort(tmp+nhalf, in+nhalf, n-nhalf, nthread&gt;&gt;1);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;} else {</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mergesort3(tmp, &nbsp; &nbsp; &nbsp; in, &nbsp; &nbsp; &nbsp; &nbsp; nhalf);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mergesort3(tmp+nhalf, in+nhalf, n-nhalf);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="yiv337701939Apple-style-span"
 color="#000000"><br></font></div><div><font class="yiv337701939Apple-style-span" color="#000000">&nbsp;&nbsp; &nbsp;merge( tmp, in, nhalf, n);</font></div><div><font class="yiv337701939Apple-style-span" color="#000000">}</font></div></blockquote></div><div><br></div><div>The approach that Control.Concurrent takes is very different, preferring a style where the programmer says what things might be advantageous to run in parallel, but the runtime makes no guarantees that they will be, allowing the programmer to break work down into smaller chunks, and letting the runtime sort out which parts should be run concurrently. This allows for a much easier style of parallel programming, but is only really possible in a pure language like Haskell.&nbsp;</div><div><br></div><div>On a side note, the Cilk language, which adds a small number of keywords like fork and sync to the C language takes an approach closer to what Control.Parallel does, but it's not a
 graceful, and IMO not as easy to use.</div><div><br></div><div>Hope that helps. I've been having a lot of fun over the last few weeks playing with OpenMP for a university assignment, and I've got to say I greatly prefer the haskell way of doing things.</div><div><br></div><div>Cheers,</div><div>Alex Mason</div><div><br><div><div>On 27/05/2011, at 10:23, michael rice wrote:</div><br class="yiv337701939Apple-interchange-newline"><blockquote type="cite"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit;">Are the tools of Control.Parallel comparable to OpenMP?<div><br></div><div>Michael<br><br>--- On <b>Thu, 5/26/11, michael rice <i>&lt;<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;"><br>From: michael rice &lt;<a
 rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;<br>Subject: Re: [Haskell-cafe] Parallel compilation and execution?<br>To: "David Virebayre" &lt;<a rel="nofollow" ymailto="mailto:dav.vire+haskell@gmail.com" target="_blank" href="/mc/compose?to=dav.vire+haskell@gmail.com">dav.vire+haskell@gmail.com</a>&gt;<br>Cc: "Daniel Fischer" &lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;, <a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>Date: Thursday, May 26, 2011, 9:32 AM<br><br><div id="yiv337701939"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit;">Fair question. I copied the parallel version
 from:<br><br><a rel="nofollow" target="_blank" href="http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html"></a><div><a rel="nofollow" target="_blank" href="http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html">http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html</a><div><br></div><div><a rel="nofollow" target="_blank" href="http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html"></a>but pulled the non-parallel version from a text.</div><div><br></div><div>Michael</div><div><br></div><div><br>--- On <b>Thu, 5/26/11, David Virebayre <i>&lt;<a rel="nofollow" ymailto="mailto:dav.vire+haskell@gmail.com" target="_blank" href="/mc/compose?to=dav.vire+haskell@gmail.com">dav.vire+haskell@gmail.com</a>&gt;</i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;"><br>From: David Virebayre &lt;<a rel="nofollow"
 ymailto="mailto:dav.vire+haskell@gmail.com" target="_blank" href="/mc/compose?to=dav.vire+haskell@gmail.com">dav.vire+haskell@gmail.com</a>&gt;<br>Subject: Re:
 [Haskell-cafe] Parallel compilation and execution?<br>To: "michael rice" &lt;<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;<br>Cc: <a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a>, "Daniel Fischer" &lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;<br>Date: Thursday, May 26, 2011, 8:56 AM<br><br><div id="yiv337701939"><br><br><div class="yiv337701939gmail_quote">2011/5/26 michael rice <span dir="ltr">&lt;<a rel="nofollow">nowgate@yahoo.com</a>&gt;</span><br><blockquote class="yiv337701939gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><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></td></tr></tbody></table>
</blockquote><div><br></div><div>Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the non-parallel one ?</div><div>&nbsp;</div><blockquote class="yiv337701939gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit;"><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 class="yiv337701939im"><div><font face="arial" size="2">{-</font></div><div><font size="2" face="courier, monaco, monospace, sans-serif">import
 Control.Parallel</font></div><div><font size="2" face="courier, monaco, monospace, sans-serif"><br></font></div><div><font size="2" face="courier, monaco, monospace, sans-serif">nfib :: Int -&gt; Int</font></div><div><font size="2" face="courier, monaco, monospace, sans-serif">nfib n | n &lt;= 1 = 1</font></div>
</div><div><font size="2" face="courier, monaco, monospace, sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;| otherwise = par n1 (pseq n2 (n1 + n2 + 1))</font></div><div class="yiv337701939im"><div><font size="2" face="courier, monaco, monospace, sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where n1 = nfib (n-1)</font></div>
<div><font size="2" face="courier, monaco, monospace, sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n2 = nfib
 (n-2)</font></div><div><font size="2" face="courier, monaco, monospace, sans-serif">-}</font></div><div><font size="2" face="courier, monaco, monospace, sans-serif"><br></font></div></div><div class="yiv337701939im"><div><font size="2" face="courier, monaco, monospace, sans-serif">nfib :: Int -&gt; Int</font></div>
<div><font size="2" face="courier, monaco, monospace, sans-serif">nfib n | n &lt;= 1 = 1</font></div></div><div class="yiv337701939im"><div><font size="2" face="courier, monaco, monospace, sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;| otherwise = nfib (n-1) + nfib (n-2)</font></div>
<div><font size="2" face="courier, monaco, monospace, sans-serif"><br></font></div><div><font size="2" face="courier, monaco, monospace, sans-serif">main = do putStrLn $ show $ nfib 39</font></div></div></div><div class="yiv337701939im">
<div><font face="arial" size="2"><br></font></div><div><font 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><div style="font-family:arial;font-size:10pt;">[1 of 1] Compiling Main &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( nfib.hs, nfib.o )</div><div style="font-family:arial;font-size:10pt;">Linking nfib ...</div><div class="yiv337701939im"><div style="font-family:arial;font-size:10pt;">
[michael@hostname ~]$ ./nfib +RTS -N3</div></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 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( 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 ~]$&nbsp;</div>
<div style="font-family:arial;font-size:10pt;"><br></div></td></tr></tbody></table></blockquote></div><font class="yiv337701939Apple-style-span" size="3"><br></font>
</div></blockquote></div></div></td></tr></tbody></table></div><br>-----Inline Attachment Follows-----<br><br><div class="yiv337701939plainMail">_______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow">Haskell-Cafe@haskell.org</a><br><a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></blockquote></div></td></tr></tbody></table>_______________________________________________<br>Haskell-Cafe mailing list<br><a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></div></div></blockquote></div></td></tr></table>