Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Q1. In either Java or Python, implement a distributed algorithm for finding the maximum number between nodes. - Nodes generate a random 64-bit number at start up, and must form a consensus about the...

1 answer below »
Q1. In either Java or Python, implement a distributed algorithm for finding the maximum number between nodes.

- Nodes generate a random 64-bit number at start up, and must form a consensus about the maximum number across all nodes.
- Each node should be modeled as a thread (so pick a programming language that has threads).
- Nodes can only communicate with each other using message passing (so pick a programming language with channels, or model message passing using FIFO queues).
- Nodes can only communicate with 1/10th of the other nodes (you can decide how to configure them).
- Nodes should print out the maximum number when they have it. Each node can only print once. Not all nodes need to print the correct number, but the more, the better.
- The program should be a command-line tool, that accepts the number of nodes as an argument.

Focus on an implementation that achieves consensus consistently. Remember to check all concurrent data access for data-races.
Answered Same Day May 19, 2020

Solution

Abr Writing answered on May 21 2020
144 Votes
# Importing necessary packages
import random # For generating a random 64-bit number using: random.getrandbits(64)
import sys
import threading
class Node():
    def __init__(self, node):
        # Storing the name of the node
        self.name = node
        # Storing the nodes idea about the node with maximum numbe
        self.max = node
        # Storing the value of node that is known to have the maximum value
        self.num = random.getrandbits(64)
        # The list of all the nodes about which the node have idea
        self.checkedList = list()
        # The list of all the nodes with which the node have communicated
        self.communicatedList = list()
    
    # Changing the node's idea about node with maximum value
    def changeMax(self, node):
        self.max = node.max
        self.num = node.num
        
    # Adding to checked list
    def addtoCheckedList(self,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here