Question: 6. Describe the difference(s) between processes and threads. Illustrate your answer by modifying the Pi estimation code to run with: (a) 4 processes and (b)
6. Describe the difference(s) between processes and threads. Illustrate your answer by modifying the Pi estimation code to run with: (a) 4 processes and (b) 4 threads
import random as r
import math as m
npoints = 100000000 # larger => more precision
count = 0
for j in range(npoints):
x = r.random() # (0.0, 1.0]
y = r.random()
#is point(x,y) inside a circle r=1.0 centering on point(0,0)
if m.sqrt(x*x + y*y) < 1.0:
count = count + 1
PI = 4.0 * count / npoints #estimating PI
print (Monte Carlo estimation of pi: , PI)
6. Explain and demonstrate with Python code how you achieve a speedup > 1.0 for code in the previous question. Would it be possible to achieve a speedup > n/2 for n processes/threads used? Why or why not.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
