[erlang-questions] Tilera 64-core chip - let's help them help us!

Hugh Perkins hughperkins@REDACTED
Fri Sep 7 00:51:45 CEST 2007


On 9/7/07, Sean Hinde <sean.hinde@REDACTED> wrote:
> You don't need to care about how many cores you have to make a
> parallel map function in erlang, you only need to care about cores
> when you start the emulator.
>
> Parallel map is really really simple in erlang. No loss of
> abstraction at all. Just stick this function in a small library file
> and away you go (code lifted from Luke Gorries blog: http://
> lukego.livejournal.com/).
>
>    pmap(F,List) ->
>        [wait_result(Worker) || Worker <- [spawn_worker(self(),F,E) ||
> E <- List]].
>
>    spawn_worker(Parent, F, E) ->
>        erlang:spawn_monitor(fun() -> Parent ! {self(), F(E)} end).
>
>    wait_result({Pid,Ref}) ->
>        receive
>           {'DOWN', Ref, _, _, normal} -> receive {Pid,Result} -> Result end;
>           {'DOWN', Ref, _, _, Reason} -> exit(Reason)
>        end.
>
> The VM will take care of passing out the work around the cores as
> described by Kenneth a few posts ago.

Well... this will spawn a process for every item in the map.  How
efficient would that be if there are, say, 10 million elements in the
map and only 64 processor cores?



More information about the erlang-questions mailing list