Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions