
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](https://content.bartleby.com/qna-images/question/7c3fcf34-465a-4c45-8648-05a4e6544f7f/23794ff6-69e2-4ce7-bfba-7775223396f4/s1ukpy5_thumbnail.png)

Step by stepSolved in 4 steps with 3 images

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
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
- Can you use Python programming language to wirte this code? Thank you very much!arrow_forwardPython Question: Identify the loops that will iterate 5 times. A. for x in range(0,101,20): B. for x in range(1,6): C. for x in range(50,0,-10): D. for x in range(5,25,5):arrow_forwardWrite a python program that determines the length of a user inputted string. Note: This program should NOT use the len() function Sample output: Enter a word: capybara The length of capybara is 8 This problem will help you practice using for loops. Remember the for and in keywords.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





