jazcap53
BAN USERJust a thought:
If each node knows its own node ID, and how many nodes are in the system, you might handle the problem this way:
Imagine the nodes arranged in a circle.
Part A: Node 1 starts by sending its val to node 2. Node 2 sends the val it receives, plus its own val, to node 3. Node n sends the total of vals to node 1.
Part B: Node 1 receives a message from node n, which contains the sum of the vals. It passes this sum to node 2, which resends the message around the circle.
Each node (except node 1) knows that the *second* message it receives will be the total sum. Node 1 knows that the *first* message it receives is the total sum, and the *second* message it receives means that all nodes have been informed of the sum.
So each node has essentially the same code, and the algorithm is linear; it sends twice as many messages as there are nodes.
You're right. And very nice Python solution.
- jazcap53 February 20, 2013