Answered step by step
Verified Expert Solution
Question
1 Approved Answer
surface _ s . go contain: / / Surface computes an SVG rendering of a 3 - D surface function. package main import (
surfacesgo contain: Surface computes an SVG rendering of a D surface function.
package main
import
fmt
"math"
const
width, height axis ranges xyrange..xyrange
cells canvas size in pixels
xyrange number of grid cells
xyscale width xyrange pixels per x or y unit
zscale height pixels per z unit
angle math.Pi angle of x y axes deg
var sin cos math.Sinangle math.Cosangle sindeg cosdeg
func main
fmtPrintf width, height
for i :; i cells; i
for j :; j cells; j
ax ay : corneri j
bx by : corneri j
cx cy : corneri j
dx dy : corneri j
fmtPrintf
ax ay bx by cx cy dx dy
fmtPrintln
func corneri j intfloat float
Find point xy at corner of cell ij
x : xyrange floaticells
y : xyrange floatjcells
Compute surface height z
z : fx y
Project xyz isometrically onto D SVG canvas sxsy
sx : widthxycosxyscale
sy : heightxysinxyscale zzscale
return sx sy
func fx y float float
r : math.Hypotx y distance from
return math.Sinr r
Take the D surface computation code from Section of the Go book as an existing CPUbound sequential
program and call it surfacesgo First, remove all IO operations, such as Printfs, to make sure that it
is purely CPU bound. Next, increase the problem size number of iterations of the loop that you will later parallelize, ie cells to so that the execution time is more substantial. Finally, measure the execution time
of the sequential program using the time shell command and record the reported real wall clock value.
In addition, write a parallel version called surfacepgo in which you execute the main loop concurrently using goroutines. Measure how much faster it runs on a multiprocessor txlarge instance in AWS.
While developing your code locally on your own computer, first determine how many CPUs your computer
has check nproc and cat proccpuinfo and find the optimal number of goroutines to use for your
machine. Read about GOMAXPROCS in Section in detail and measure the performance of your parallel
program versus various values of GOMAXPROCS. Finally, determine the optimal GOMAXPROCS value for
the txlarge instance and measure its performance in AWS.
Write your surfacepgo in a flexible way so that the number of goroutines is passed as a command line
argument. Make sure that the parallel version performs exactly the same calculation as the sequential version.
For debugging purposes, you can temporarily print their SVG image outputs and see if they match. Since
the parallel version will print lines nondeterministically, you can sort the lines of output before comparing.
Finally, analyze the speedup that the parallel version achieves execution time of sequential version divided by
the execution time of parallel version for various numbers of goroutines: starting from two, in increments of
two, until twice the number of cores or virtual processors for txlarge. For more reliable results, repeat
each experiment multiple times minimum three replicates and average the results of different runs for each
case. Clear your caches before each execution in order to eliminate any effect of caching
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