<div dir="ltr">Um, dunno if this helps, but have you looked at rpc:pmap/3?<br><br><div class="gmail_quote">On Mon, Sep 1, 2008 at 8:33 PM, Kevin Scaldeferri <span dir="ltr"><<a href="mailto:kevin@scaldeferri.com">kevin@scaldeferri.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">First,  I don't think it's been mentioned here, but the language<br>
benchmarks shootout finally got some multi-core hardware!<br>
<br>
<a href="http://shootout.alioth.debian.org/u64q/" target="_blank">http://shootout.alioth.debian.org/u64q/</a><br>
<br>
At the moment, though, there are almost no submissions of parallelized<br>
code, so the results are about the same as the existing hardware.<br>
<br>
I figured (slightly spurred on by the Haskell community) that we<br>
should try to submit some modified versions that actually use the<br>
multiple cores.  So, for example, I made a slight change to the binary<br>
trees code and got a nearly 2x speedup on my 2-core machine.  In doing<br>
so, I did run into one of those little things that I've never really<br>
known the preferred approach for.  My modified function looks like this:<br>
<br>
depthLoop(D,M) when D > M -> ok;<br>
depthLoop(D,M) -><br>
     Self = self(),<br>
     spawn(fun() -><br>
                   N = 1 bsl (M-D + ?Min),<br>
                   io:fwrite("~w\t trees of depth ~w\t check: ~w~n",<br>
                             [ 2*N, D, sumLoop(N,D,0) ]),<br>
                   Self ! done<br>
           end),<br>
     depthLoop (D+2,M),<br>
     receive done -> done end.<br>
<br>
<br>
parallelizing would only require the addition of the spawn, except<br>
that if I do that, the function finishes executing and the program<br>
exits before most of the processes run at all.  So, I need to add the<br>
call to self(), the send, and the receive in order to prevent<br>
premature termination.  So, what I'm wondering is, is there a better<br>
idiom for achieving this goal?<br>
<br>
<br>
Thanks,<br>
<br>
-kevin<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>For every expert there is an equal and opposite expert - Arthur C. Clarke<br>
</div>