For some reason i keep getting 0.0 for the series time and the delta time intervals USING PYTHON MODIFY CODE SO DESIRED OUTPUT IS REACHED  DESIRED OUTPUT : correct time calculation to find series and the paralell allow user input to find sequence and time intervals  ******************************************************************************************************************************* import multiprocessing as mp import json import time import sys def fib(n: int) -> int:              #Calculate n'th number in Fibonacci secuence         #return n'th number          if n < 2:         return 1     else:         return fib(n - 1) + fib(n - 2) def parallel(num1: int, num2: int) -> list:              #Calculates Fibonacci sequence between num1 and num2 parallel         #return list of time taken by calculation, results          pool = mp.Pool(processes=mp.cpu_count())     a: float = time.time()     results = [pool.map(fib, (x for x in range(num1-1, num2)))]     b: float = time.time()     print("parallel: "+str(results))     print(f'parallel time:{b-a}')     return [b-a, results] def normal(num1: int, num2: int) -> list:              #Calculates Fibonacci sequence between num1 and num2 series         #return time taken by calculation          results = []     for x in range(num1-1, num2):         results.append(fib(x))     a: float = time.time()     b: float = time.time()     print(f'series time:{b-a}')     return [b-a, results] def resulter(num1: int, num2: int) -> tuple:              #Makes calculations series and parallel         #return num1, num2, series calc time, parallel calc time, series/parallel          b: float = parallel(num1, num2)[0]     a: float = normal(num1, num2)[0]     print(f'delta time (series/parallel):{a/b}')     return (num1, num2, a, b, a/b)         #Main that sets the values           def main():     data_start: int = 0     data_end: int = 0     print(f"cpu core count:{mp.cpu_count()}")     try:         data_start = int(sys.argv[1])         data_end = int(sys.argv[2])         print(f"values are {data_start} - {data_end}")     except:         data_start = 4         data_end = 20         print("values are 4 - 20")     return resulter(data_start, data_end) if __name__ == '__main__':     main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

For some reason i keep getting 0.0 for the series time and the delta time intervals

USING PYTHON MODIFY CODE SO DESIRED OUTPUT IS REACHED 

DESIRED OUTPUT : correct time calculation to find series and the paralell

allow user input to find sequence and time intervals 

*******************************************************************************************************************************

import multiprocessing as mp
import json
import time
import sys


def fib(n: int) -> int:
    
        #Calculate n'th number in Fibonacci secuence
        #return n'th number
    
    if n < 2:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)


def parallel(num1: int, num2: int) -> list:
    
        #Calculates Fibonacci sequence between num1 and num2 parallel
        #return list of time taken by calculation, results
    
    pool = mp.Pool(processes=mp.cpu_count())
    a: float = time.time()
    results = [pool.map(fib, (x for x in range(num1-1, num2)))]
    b: float = time.time()
    print("parallel: "+str(results))
    print(f'parallel time:{b-a}')
    return [b-a, results]


def normal(num1: int, num2: int) -> list:
    
        #Calculates Fibonacci sequence between num1 and num2 series
        #return time taken by calculation
    
    results = []
    for x in range(num1-1, num2):
        results.append(fib(x))
    a: float = time.time()
    b: float = time.time()
    print(f'series time:{b-a}')
    return [b-a, results]


def resulter(num1: int, num2: int) -> tuple:
    
        #Makes calculations series and parallel
        #return num1, num2, series calc time, parallel calc time, series/parallel
    
    b: float = parallel(num1, num2)[0]
    a: float = normal(num1, num2)[0]
    print(f'delta time (series/parallel):{a/b}')
    return (num1, num2, a, b, a/b)

        #Main that sets the values 
        
def main():
    data_start: int = 0
    data_end: int = 0
    print(f"cpu core count:{mp.cpu_count()}")
    try:
        data_start = int(sys.argv[1])
        data_end = int(sys.argv[2])
        print(f"values are {data_start} - {data_end}")
    except:
        data_start = 4
        data_end = 20
        print("values are 4 - 20")
    return resulter(data_start, data_end)


if __name__ == '__main__':
    main()

cpu core count:2
values are 4 - 20
parallel: [[3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]]
parallel time: 0.2512378692626953
series time: 0.0
delta time (series/parallel):0.0
Transcribed Image Text:cpu core count:2 values are 4 - 20 parallel: [[3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]] parallel time: 0.2512378692626953 series time: 0.0 delta time (series/parallel):0.0
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

can you modify it to use more than two cpus, i compiled and ran and the time intervals are still showing 0.0 but everything else is done as desired thank you. i think it shows the 0.0 time becuase of my computer, i see on yours your cpu count is 8

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education