<div>This is a random idea, that's probably not going to work, but I don't have a way of testing it so I'll just post it!</div>
<div>How about using unsafeInterleaveIO to get a lazy suspension of the result of each action, and then using par to spark off each of them? If that works you can reuse the existing task-parallel system of GHC to do the heavily lifting for you, instead of having to write your own.<br>
<br></div>
<div class="gmail_quote">On Tue, Apr 7, 2009 at 11:25 AM, Neil Mitchell <span dir="ltr"><<a href="mailto:ndmitchell@gmail.com">ndmitchell@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hi,<br><br>I've written a parallel_ function, code attached. I'm looking for<br>criticism, suggestions etc on how to improve the performance and<br>
fairness of this parallel construct. (If it turns out this construct<br>is already in a library somewhere, I'd be interested in that too!)<br><br>The problem I'm trying to solve is running system commands in<br>parallel. Importantly (unlike other Haskell parallel stuff) I'm not<br>
expecting computationally heavy Haskell to be running in the threads,<br>and only want a maximum of n commands to fire at a time. The way I'm<br>trying to implement this is with a parallel_ function:<br><br>parallel_ :: [IO a] -> IO ()<br>
<br>The semantics are that after parallel_ returns each action will have<br>been executed exactly once. The implementation (attached) creates a<br>thread pool of numCapabililties-1 threads, each of which reads from a<br>task pool and attempts to do some useful work. I use an idempotent<br>
function to ensure that all work is done at most one, and a sequence_<br>to ensure all work is done at least once.<br><br>Running a benchmark of issuing 1 million trivial tasks (create,<br>modify, read and IO ref) the version without any parallelism is really<br>
fast (< 0.1 sec), and the version with parallelism is slow (> 10 sec).<br>This could be entirely due to space leaks etc when queueing many<br>tasks.<br><br>I'm useful for any thoughts people might have!<br><br>Thanks in advance,<br>
<font color="#888888"><br>Neil<br></font><br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Sebastian Sylvan<br>+44(0)7857-300802<br>UIN: 44640862<br>