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

Sean Hinde sean.hinde@REDACTED
Thu Sep 6 18:53:22 CEST 2007


On 6 Sep 2007, at 17:17, Hugh Perkins wrote:

>>> What about things like maps?  To what extent can/will Erlang map  
>>> them
>>> across different processors?
>> If you implement a parallell map function your self, which is  
>> really easy
>> you can take advantage of many processors.
>
> Ok.  Of course, this gets away from a desirable abstraction, stated by
> Garry, where we dont have to look up how many processor cores we are
> running on, how many are free at the moment, and then split our map(s)
> accordingly.

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.

Sean




More information about the erlang-questions mailing list