Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

surface _ s . go contain: / / Surface computes an SVG rendering of a 3 - D surface function. package main import (

surface_s.go contain: // Surface computes an SVG rendering of a 3-D surface function.
package main
import (
"fmt"
"math"
)
const (
width, height =600,320// axis ranges (-xyrange..+xyrange)
cells =100// canvas size in pixels
xyrange =30.0// number of grid cells
xyscale = width /2/ xyrange // pixels per x or y unit
zscale = height *0.4// pixels per z unit
angle = math.Pi /6// angle of x, y axes (=30\deg )
)
var sin30, cos30= math.Sin(angle), math.Cos(angle)// sin(30\deg ), cos(30\deg )
func main(){
fmt.Printf("", width, height)
for i :=0; i < cells; i++{
for j :=0; j < cells; j++{
ax, ay := corner(i+1, j)
bx, by := corner(i, j)
cx, cy := corner(i, j+1)
dx, dy := corner(i+1, j+1)
fmt.Printf("
",
ax, ay, bx, by, cx, cy, dx, dy)
}
}
fmt.Println("")
}
func corner(i, j int)(float64, float64){
// Find point (x,y) at corner of cell (i,j).
x := xyrange *(float64(i)/cells -0.5)
y := xyrange *(float64(j)/cells -0.5)
// Compute surface height z.
z := f(x, y)
// Project (x,y,z) isometrically onto 2-D SVG canvas (sx,sy).
sx := width/2+(x-y)*cos30*xyscale
sy := height/2+(x+y)*sin30*xyscale - z*zscale
return sx, sy
}
func f(x, y float64) float64{
r := math.Hypot(x, y)// distance from (0,0)
return math.Sin(r)/ r
}
Take the 3D surface computation code from Section 3.2 of the Go book as an existing CPU-bound sequential
program and call it surface_s.go. First, remove all I/O 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, i.e. cells) to 3000 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 surface_p.go, in which you execute the main loop concurrently using goroutines. Measure how much faster it runs on a multiprocessor t2.2xlarge instance in AWS.
While developing your code locally on your own computer, first determine how many CPUs your computer
has (check nproc and cat /proc/cpuinfo) and find the optimal number of goroutines to use for your
machine. Read about GOMAXPROCS in Section 9.8.3 in detail and measure the performance of your parallel
program versus various values of GOMAXPROCS. Finally, determine the optimal GOMAXPROCS value for
the t2.2xlarge instance and measure its performance in AWS.
Write your surface_p.go 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 speed-up 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 t2.2xlarge. 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

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

ISBN: 3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago