Question: The Python script provided ( sum _ in _ parallel.py ) sums the values from 1 up to N , where N is parameter that

The Python script provided (sum_in_parallel.py) sums the values from 1 up to N, where N is parameter that you give it. The code is designed to divide the work evenly across P processes on different cores (it is actually threads, but we can treat it as cores for now). A process is a single worker for your CPU. To call this program, run python sum_in_parallel.py P N, with P and N being integers. The program will then calculate the sum and provide you with the time that it required to run in parallel with the given number of processes. You might need to install the multiprocessing library. Using this program, calculate how long it takes to sum values from 1 to 10,000,000using different number of processes. Complete the following table with your times. Perform one run without recording the time to make sure that all data is loaded into memory. To measure the time for each setup, calcfrom multiprocessing import Process, Manager
import multiprocessing
import os
import time
import sys
def sumProd(final_list, numList):
currSum =0
for i in numList:
currSum +=(i*i)
final_list.append(currSum)
if __name__=='__main__':
numProc = int(sys.argv[1])
N = int(sys.argv[2])
#print("Total available number of processors: ", multiprocessing.cpu_count())
secSize = int(N/numProc)
##Start parallel
p_start = time.time()
manager = multiprocessing.Manager()
final_list = manager.list()
#final_val = manager.Value()
manager = Manager()
myProcs =[]
currProcID =0
for i in range (numProc):
currArg = range(i*(secSize),(i+1)*secSize)
currP = Process(target=sumProd, args=(final_list, currArg))
currP.start()
myProcs.append(currP)
for p in myProcs:
p.join() #Blocks execution of main process until process is done
print("Time for parallel: "+ str(time.time()- p_start)+'
')
##end parallel
The code is provided in the question but i get an error when running it and i am not sure why, i Need the time for these number of processes
1
2
4
8
16
32
64
Please help!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!