#conn.sendto( arraystring , addr_list[i] ) #Sends array string c.sendto(arraystring, addr_list[i]) #Sends array string print 'Data sent, sorting array...' array = MergeSort.mergesort( sections[procID]) #Sorts section and stores it in array print 'Array sorted.' for i in range(procno - 1): #Receives sorted sections from each client arraystring = '' print 'Receiving data from clients...' cc = conn_list[i] while 1: data = cc.recv(4096) #Receives data in chunks arraystring += data #Adds data to array string if ']' in data: #When end of data is received break print 'Data received, merging arrays...' array = MergeSort.merge( array, eval(arraystring)) #Merges current array with section from client print 'Arrays merged.' cc.close() #conn.close() time_taken = time.time() - start_time #Calculates and records time_taken print 'Time taken to sort is ', time_taken, 'seconds.' #print 'Result : ', array
def test_merge(self): list_1 = [1, 2, 3, 8, 11, 13, 24] list_2 = [4, 5, 6, 7, 9] self.assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 24], MergeSort.merge(list_1, list_2))
start_time = time.time() #Records start time sections = breakarray(array, procno) #splits array into sections for every client for i in range(procno - 1): #Converts array section into string to be sent arraystring = repr(sections[i+1]) conn.sendto( arraystring , addr_list[i] ) #Sends array string print 'Data sent, sorting array...' array = MergeSort.mergesort(sections[procID]) #Sorts section and stores it in array print 'Array sorted.' for i in range(procno - 1): #Receives sorted sections from each client arraystring = '' print 'Receiving data from clients...' while 1: data = conn.recv(4096) #Receives data in chunks arraystring += data #Adds data to array string if ']' in data: #When end of data is received break print 'Data received, merging arrays...' array = MergeSort.merge(array, eval(arraystring)) #Merges current array with section from client print 'Arrays merged.' conn.close() time_taken = time.time() - start_time #Calculates and records time_taken print 'Time taken to sort is ', time_taken, 'seconds.'