<div dir="ltr">I argue to check monitor reference in receive every time. It is not good practice omitting it. You don't know which depthLoop's 'DOWN' message you received. In some particular case it can doesn't matter (as in this concrete do!) but do it is safer and good practice.<br>
<br><div class="gmail_quote">On Tue, Sep 2, 2008 at 9:42 AM, Mats Cronqvist <span dir="ltr"><<a href="mailto:mats.cronqvist@gmail.com">mats.cronqvist@gmail.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;">
<div class="Ih2E3d">Kevin Scaldeferri wrote:<br>
> 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>
><br>
</div> i'm partial to the monitor-exit idiom. gets rid of the Self for one thing.<br>
<br>
mats<br>
<div class="Ih2E3d"><br>
depthLoop(D,M) when D > M -> ok;<br>
depthLoop(D,M) -><br>
</div> erlang:spawn_monitor(fun()-> slave(D, M) end),<br>
depthLoop (D+2,M),<br>
receive {'DOWN',_,_,_,done} -> done end.<br>
<br>
slave(D, M) -><br>
<div class="Ih2E3d"> 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>
</div> exit(done).<br>
<div><div></div><div class="Wj3C7c"><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil<br>
</div>