Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago