Hi Ashley,<div>You might give fprof a whirl (<a href="http://www.erlang.org/doc/man/fprof.html">http://www.erlang.org/doc/man/fprof.html</a>).</div><div><br></div><div>JK<br><br><div class="gmail_quote">On Thu, Aug 9, 2012 at 6:45 AM, Ashley Holman <span dir="ltr"><<a href="mailto:dscvlt@gmail.com" target="_blank">dscvlt@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Argh, silly me!  I think I just figured out what's happening.  It's the final multiplication in fac_multi_collect/2 that's having to run after the third process returns.  It is multiplying some pretty massive numbers so that would explain it.<div>

<br></div><div>This raises a more general question though - are there some profiling tools out there so that I can more easily find out where the time is going and when things are executing?</div><div><br></div><div>Thanks very much.<div>
<div class="h5"><br>
<br><div class="gmail_quote">On Thu, Aug 9, 2012 at 11:02 PM, Ashley Holman <span dir="ltr"><<a href="mailto:dscvlt@gmail.com" target="_blank">dscvlt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<div><br></div><div>(code attached)<br><div><br></div><div>I've just began learning Erlang over the last few days and so far a really enjoyed programming in it.  As a learning exercise, I decided to implement the classic "factorial" function: fac(N) = N*fac(N-1); F(0) = 1.  For calculating large factorials, this takes a long time (fac(200000) takes 42 secs on my laptop).</div>



<div><br></div><div>So, I made some optimisations (using condense_terms/1 and shuffle/1 - but you can basically ignore those).  However, it still was only using 100% of 1 cpu core, and I have 2 cores, so this was a good opportunity to learn an important feature of Erlang, spawning processes!  I partitioned the list into 3 sublists and spawned a process to multiply each sublist.  eg. [pseudo code] Proc1([1,2,3]) * Proc2([4, 5, 6]) * Proc3(7, 8, 9) should give me the result of fac(9) using 3 processes.</div>



<div><br></div><div>This appears to be working but I'm completely confused about certain delays in execution I'm seeing - I'm not sure where it is spending some of its time in the code.  I put in some debugging, and it appears that the child processes (fac_multi_actor) are finishing their calculations and returning the results, but the receiver (fac_multi_collect) doesn't return for several seconds later.   </div>



<div><br></div><div>The whole point of this was to try to optimise it, so I would like to know where these few seconds are going (~30% of execution time).</div><div><br></div><div>fac:fac(200000) is taking ~9.5s using the three processes, but based on the debugging it looks like it should be completing in 6.  Something else hangs around using 100% of one core for several seconds later.  I've attached the code in case anyone is able to take a look at this behaviour.</div>


<div><br></div><div>PS. I realise it will take some effort for someone to actually bother reading the code and trying to reproduce my problem, so no problem if I don't get any answers.  In case anyone feels like helping though it would be much appreciated because I'm a bit confused at the moment!</div>



<div><br></div><div>Thanks</div><div>Ash</div></div>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>