Answered step by step
Verified Expert Solution
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 suminparallel.py sums the values from 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 suminparallel.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 to using 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 sumProdfinallist, numList:
currSum
for i in numList:
currSum ii
finallist.appendcurrSum
if namemain:
numProc intsysargv
N intsysargv
#printTotal available number of processors: multiprocessing.cpucount
secSize intNnumProc
##Start parallel
pstart time.time
manager multiprocessing.Manager
finallist manager.list
#finalval manager.Value
manager Manager
myProcs
currProcID
for i in range numProc:
currArg rangeisecSizeisecSize
currP ProcesstargetsumProd, argsfinallist, currArg
currP.start
myProcs.appendcurrP
for p in myProcs:
pjoin #Blocks execution of main process until process is done
printTime for parallel: strtimetime pstart
##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
Please help!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started