0

I am trying to graph the output of serial and parallel execution times but keep getting

TypeError: unsupported operand type(s) for /: 'list' and 'list'.

How do i divide contents of the list so so i don't get this error


TypeError Traceback (most recent call last) in 49 50 # Compute the ratio of these times ---> 51 ratio.append(serialTime/parallelTime) 52 53

TypeError: unsupported operand type(s) for /: 'list' and 'list'

import numpy as np
import multiprocessing as mp
import time
import matplotlib.pyplot as plt

# Sleep for t seconds
def burnTime(t):
    time.sleep(t)

# Main
if __name__ == '__main__':
    N = 16 # The number of jobs
    P = 4  # The number of processes

    # A thread pool of P processes
    pool = mp.Pool(P)

  # Use a variety of wait times
    ratio = []
    wait_time = [1, 2, 3, 4, 5, 6, 7, 8]

    #serial results    
    print("Serial Execution Times")
    for _ in range(N):
        start_time = time.time()
        serialTime = [burnTime(t) for t in wait_time]
        print("---- {} seconds ---- ".format(time.time() - start_time))


    print("\n")

    #parallel results
    print("Parallel Execution Times")
    for _ in range(N):
        start_time = time.time()
        parallelTime = pool.map(burnTime, wait_time)
        print("---- {} seconds ---- ".format(time.time() - start_time))



    for t in wait_time:
          pass
    # Compute jobs serially and in parallel
    # Use time.time() to compute the elapsed time for each
       # serialTime = 1
        #parallelTime = 1



    # Compute the ratio of these times
    ratio.append(serialTime/parallelTime)


    # Plot the results
    plt.plot(wait_time, ratio, '-ob')
    plt.xscale('log')
    plt.xlabel('Wait Time (sec)')
    plt.ylabel('Serial Time (sec) / Parallel Time (sec)')
    plt.title('Speedup versus function time')
    plt.show()

Output of SerialTime
---- 6.604194641113281e-05 seconds ---- 
---- 1.9073486328125e-06 seconds ---- 
---- 9.5367431640625e-07 seconds ---- 
---- 2.1457672119140625e-06 seconds ---- 
---- 2.1457672119140625e-06 seconds ---- 
---- 1.9073486328125e-06 seconds ---- 
---- 9.5367431640625e-07 seconds ---- 
---- 2.1457672119140625e-06 seconds ---- 
---- 1.9073486328125e-06 seconds ---- 
---- 9.5367431640625e-07 seconds ---- 
---- 1.1920928955078125e-06 seconds ---- 
---- 2.1457672119140625e-06 seconds ---- 
---- 1.9073486328125e-06 seconds ---- 
---- 1.1920928955078125e-06 seconds ---- 
---- 2.1457672119140625e-06 seconds ---- 
---- 1.9073486328125e-06 seconds ---- 

output of ParalleTime
---- 12.006800889968872 seconds ---- 
---- 12.004575967788696 seconds ---- 
---- 12.00544810295105 seconds ---- 
---- 12.006248950958252 seconds ---- 
---- 12.003881216049194 seconds ---- 
---- 12.005573749542236 seconds ---- 
---- 12.003982067108154 seconds ---- 
---- 12.003642082214355 seconds ---- 
---- 12.004355192184448 seconds ---- 
---- 12.00377106666565 seconds ---- 
---- 12.003960132598877 seconds ---- 
---- 12.004532098770142 seconds ---- 
---- 12.003446578979492 seconds ---- 
---- 12.003416776657104 seconds ---- 
---- 12.004649877548218 seconds ---- 
---- 12.004476070404053 seconds ---- 
3
  • why are dividing a list by another list, what exactly do you want to happen in ratio.append(serialTime/parallelTime) Commented Feb 28, 2019 at 3:54
  • I want to divide serial execution times by parallel execution times so I can graph them against wait times. I'm sure there is a better approach but I am stuck Commented Feb 28, 2019 at 3:56
  • can you check my solution. Commented Feb 28, 2019 at 3:57

2 Answers 2

1

Rather than dividing two lists, you can do the following to get the ratio of two lists:

ratio.append([x / y for x, y in zip(serialTime, parallelTime)])
Sign up to request clarification or add additional context in comments.

8 Comments

I get a different error now - TypeError: unsupported operand type(s) for /: 'function' and 'NoneType'
can you share the items inside the list serialTime and parallelTime
I added it to the original post
can you just print something like this print(serialTime) and print(parallelTime)
that won't print out the execution time
|
0

divide serial execution times by parallel execution times

result = list(map(lambda x: x[0]/x[1], zip(serialTime, parallelTime)))

btw, I have tried your code and got:

>>> serialTime
[<function burnTime at 0x103221e18>, True, [1, 2, 3, 4, 5, 6, 7, 8]]
>>> parallelTime
[None, None, None, None, None, None, None, None]

check it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.