lec22_parallel1

lec22_parallel1 - # Parallel program for estimating PI by...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# Parallel program for estimating PI by numerical integration # Uses 'Parallel Python' module (pp) for parallelization import pp import time, math, sys numstrips=1*10**7 # Integral of this from 0 -> 1 = PI/4 def f(x): return 1.0/(1.0+x**2) #Modify intgral funct so range is broken up into numcpus pieces #(one piece for each cpu) def mypi(xStart,numstrips,numcpus): h=1.0/numstrips sum=0.0 for i in range(numstrips//numcpus): x=h*i + xStart sum+=h*f(x) return 4.0*sum # Compute 'as normal' for comparison start_time = time.time() result=mypi(0.0,numstrips,1) onecputime=time.time()-start_time error=math.fabs(result-math.pi)/math.pi * 10.0**6 print "="*40 print "Estimation of PI is %1.3e panels is: %1.9f" % (numstrips,result) print "Error is %1.3f ppm" % error print "Time for a serial run: ",onecputime print "="*40 print #Create a list of servers on which 'ppserver.py' is running. #Name by domain name or IP address. Local machine is automatically included. #ppservers=("planck.ncpa.olemiss.edu",)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

lec22_parallel1 - # Parallel program for estimating PI by...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online