Skip to content

Instantly share code, notes, and snippets.

@rramsden
Created June 30, 2012 05:27
Show Gist options
  • Save rramsden/3022456 to your computer and use it in GitHub Desktop.
Save rramsden/3022456 to your computer and use it in GitHub Desktop.
% Symmetric Push-Sum Protocol
loop(#node{name=Name, value=Value, weight=Weight} = State) ->
receive
{push, From, {V0, W0}} ->
V1 = Value/2,
W1 = Weight/2,
From ! {symmetric_push, self(), {V1, W1}},
loop(update(V0 + V1 , W0 + W1, State));
{symmetric_push, {V0, W0}} ->
loop(update(V0 + Value, W0 + Weight, State));
Neighbour when is_pid(Neighbour) ->
V1 = Value/2,
W1 = Weight/2,
Neighbour ! {push, self(), {V1, W1}},
loop(update(V1, W1, State));
stop ->
io:format("~p: w = ~p, v = ~p~n", [Name, Weight, Value]),
State
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment