def Driver():
    arrLeft = CreateArrLeft()
    arrRight = CreateArrRight()

    arrLeft = BubbleSort(arrLeft)
    arrRight = BubbleSort(arrRight)

    arr = merge(arrLeft, arrRight)

    WriteArr(arr)
    Check(arr, arrLeft, arrRight)
示例#2
0
def merge_multi(list_part_left, list_part_right):
    manager_list.append(merge(list_part_left, list_part_right))
示例#3
0
    start_time_final_merge = time.time()
    p = []
    ''' For a core count greater than 2, we can use multiprocessing
        again to merge sublists in parallel '''
    if len(manager_list) > 2:
        while len(manager_list) > 0:
            ''' we remove sublists from the "manager_list" list and pass it as input to the
                "merge_multi" wrapper function of "merge" '''
            proc = Process(target=merge_multi,
                           args=(manager_list.pop(0), manager_list.pop(0)))
            p.append(proc)
        # again starting and joining ( this seems like a pattern, doesn't it ... ? )
        for proc in p:
            proc.start()
        for proc in p:
            proc.join()
    # the last two sublists that needs to be merged
    array = merge(manager_list[0], manager_list[1])

    final_merge_time = time.time() - start_time_final_merge
    print('Final merge duration : ', final_merge_time)
    multi_core_time = time.time() - start_time
    print("multi core time", multi_core_time)
    #print("the sorted array is ",array)
    #print('Array sorted, sending data...')
    #Converts array into string to be sent back to server
    arraystring = repr(array)
    s.sendall(arraystring.encode('utf-8'))  #Sends array string
    print('Data sent.')
    s.close()
示例#4
0
 
        ''' For a core count greater than 2, we can use multiprocessing
        again to merge sublists in parallel '''
        if len(manager_list) > 2:
            while len(manager_list) > 0:
                ''' we remove sublists from the "manager_list" list and pass it as input to the
                "merge_multi" wrapper function of "merge" '''
                proc = Process( target=merge_multi, args=(manager_list.pop(0),manager_list.pop(0)) )
                p.append(proc)
            # again starting and joining ( this seems like a pattern, doesn't it ... ? )
            for proc in p:
                proc.start()
            for proc in p:
                proc.join()
        # the last two sublists that needs to be merged
        array_pi  = merge(manager_list[0], manager_list[1])
 
        final_merge_time = time.time() - start_time_final_merge
        print('Final merge duration : ', final_merge_time)
        multi_core_time = time.time() - start_time
        print("multi core time",multi_core_time)
       

arraystring = '' 
print('Receiving data from client...') 
while 1:
	data = conn.recv(4096)	#Receives data in chunks 
	d = data.decode('utf-8')
 
	arraystring += d	#Adds data to array string 
	if ']' in d:	#When end of data is received	
示例#5
0
文件: test.py 项目: MiguelazoDS/pps
from MergeSort import merge

primero = merge([1, 2, 4, 6], [0, 5, 7, 9, 11])
segundo = merge([6, 8, 3], [2, 4, 7])
print("Recibe dos listas ordenadas:", primero)
print("Recibe dos listas desordenadas:", segundo)