def abort(): c = input("Close the whole node-system? [y/n]:") if c.upper() == "Y": print("END OF PROGRAM!") # send the stop calculation signal to all nodes send_to_all_nodes((outside_ip, common_port, "stop_calc"), ids) time.sleep(1) # send the TERMINATE signal to all host server send_to_all_host_server(("", "", "terminate"), host_server_addrs) time.sleep(3) # send the TERMINATE to the init server send_to_socket((outside_ip, "", "terminate"), (outside_ip, init_server_port)) else: abort()
def send_to_all_host_server(readable_msg, addr_list): for addr in addr_list: send_to_socket(readable_msg, addr)
def send_to_all_nodes(readable_msg, ids): for id in ids: addr = ip_port_map[int(id)] send_to_socket(readable_msg, addr)
# send orders to nodes A_sys_complete = -1 * degree print("A_sys complete: " + str(A_sys_complete)) B_sys_complete = adjacent print("B_sys complete" + str(B_sys_complete)) x_0_complete = np.asmatrix(np.random.randint(10, size=(n, 1))) print("X_0 complete" + str(x_0_complete)) # send the init signal/data to all nodes i = 0 for id in ids: state_names = ['x_' + str(i)] msg = (outside_ip, common_port, "init", (ip_port_map, adjacent, state_names, A_sys_complete[i,i], B_sys_complete[i], x_0_complete[i], h, (outside_ip, init_server_port))) send_to_socket(msg, ip_port_map[int(id)]) i += 1 time.sleep(2) # send the broadcast x_0 signal to all nodes send_to_all_nodes((outside_ip, common_port, "broadcast_x_0"), ids) time.sleep(2) # send the start calculation signal to all nodes send_to_all_nodes((outside_ip, common_port, "start_calc"), ids) # totally stop the third node: #time.sleep(5) #send_to_socket((outside_ip, common_port, "stop_calc"), ip_port_map[int(ids[3])])