码迷,mamicode.com
首页 > 其他好文 > 详细

Erlang实现Mapreduce

时间:2015-09-06 01:14:29      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:


-module(pmap).
-export([pmap/2]).


pmap(F, L) -> 
  S = self(),
  Pids = lists:map(fun(I) -> 
    spawn(fun() -> do_fun(S, F, I) end)
  end, L),
  gather(Pids).


gather([H|T]) ->
  receive
    {H, Result} -> [Result|gather(T)]
  end;
gather([]) ->
  [].



do_fun(Parent, F, I) ->					    
    Parent ! {self(), (catch F(I))}.


Erlang实现Mapreduce

标签:

原文地址:http://my.oschina.net/yang1992/blog/501468

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!