Parallel Numerical Integration Spring Semester 2005 Geoffrey Fox Community Grids Laboratory Indiana University 505 N Morton Suite 224 Bloomington IN

Slides:



Advertisements
Similar presentations
Partitioning and Divide-and-Conquer Strategies ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 23, 2013.
Advertisements

Today’s class Romberg integration Gauss quadrature Numerical Methods
Chapter 4 Roots of Equations
Advanced Computer Graphics (Spring 2005) COMS 4162, Lectures 18, 19: Monte Carlo Integration Ravi Ramamoorthi Acknowledgements.
Lecture 3: Integration. Integration of discrete functions
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
8 TECHNIQUES OF INTEGRATION. In defining a definite integral, we dealt with a function f defined on a finite interval [a, b] and we assumed that f does.
INTEGRALS 5. INTEGRALS We saw in Section 5.1 that a limit of the form arises when we compute an area.  We also saw that it arises when we try to find.
Evaluating Hypotheses
16 MULTIPLE INTEGRALS.
Copyright © Cengage Learning. All rights reserved. 5 Integrals.
8 TECHNIQUES OF INTEGRATION. There are two situations in which it is impossible to find the exact value of a definite integral. TECHNIQUES OF INTEGRATION.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Quadrature Greg Beckham. Quadrature Numerical Integration Goal is to obtain the integral with as few computations of the integrand as possible.
Numerical Integration Formulas
19.5 Numeric Integration and Differentiation
1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo
Numerical Integration Simpson’s Method. Trapezoid Method & Polygonal Lines One way to view the trapezoid method for integration is that the curves that.
Integration. Problem: An experiment has measured the number of particles entering a counter per unit time dN(t)/dt, as a function of time. The problem.
Chapter 4, Integration of Functions. Open and Closed Formulas x 1 =a x 2 x 3 x 4 x 5 =b Closed formula uses end points, e.g., Open formulas - use interior.
Numerical Integration In general, a numerical integration is the approximation of a definite integration by a “weighted” sum of function values at discretized.
Integrals 5.
1.00 Lecture 20 More on root finding Numerical lntegration.
3. Numerical integration (Numerical quadrature) .
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly.
1 Chapter 7 NUMERICAL INTEGRATION. 2 PRELIMINARIES We use numerical integration when the function f(x) may not be integrable in closed form or even in.
1 Statistical Mechanics and Multi- Scale Simulation Methods ChBE Prof. C. Heath Turner Lecture 11 Some materials adapted from Prof. Keith E. Gubbins:
D MANCHE Finding the area under curves:  There are many mathematical applications which require finding the area under a curve.  The area “under”
Lecture 19 – Numerical Integration 1 Area under curve led to Riemann sum which led to FTC. But not every function has a closed-form antiderivative.
Chapters 5 and 6: Numerical Integration
Wicomico High School Mrs. J. A. Austin AP Calculus 1 AB Third Marking Term.
Interpolation. Interpolation is important concept in numerical analysis. Quite often functions may not be available explicitly but only the values of.
ME 2304: 3D Geometry & Vector Calculus Dr. Faraz Junejo Double Integrals.
MA2213 Lecture 4 Numerical Integration. Introduction Definition is the limit of Riemann sums I(f)
Area/Sigma Notation Objective: To define area for plane regions with curvilinear boundaries. To use Sigma Notation to find areas.
Integration Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved. 4 Quadratic Functions.
CHAPTER 4 SECTION 4.2 AREA.
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Riemann Sums, Trapezoidal Rule, and Simpson’s Rule Haley Scruggs 1 st Period 3/7/11.
Maybe add in chad’s idea of the area of polygons limiting to the area of a circle. Nice animation to link to online At
5. Integration 2.Quadrature as Box Counting 3.Algorithm: Trapezoid Rule 4.Algorithm: Simpson’s Rule 5.Integration Error 6.Algorithm: Gaussian Quadrature.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
CHAPTER 3 NUMERICAL METHODS
Numerical Integration
The Definite Integral.
Copyright © Cengage Learning. All rights reserved. 4 Integrals.
Calculus Date: 3/7/2014 ID Check Obj: SWBAT connect Differential and Integral Calculus Do Now: pg 307 #37 B #23 HW Requests: SM pg 156; pg 295 #11-17 odds,
INTEGRALS We saw in Section 5.1 that a limit of the form arises when we compute an area. We also saw that it arises when we try to find the distance traveled.
5 INTEGRALS.
Area/Sigma Notation Objective: To define area for plane regions with curvilinear boundaries. To use Sigma Notation to find areas.
In this chapter, we explore some of the applications of the definite integral by using it to compute areas between curves, volumes of solids, and the work.
Chapter 4, Integration of Functions
Parallel Programming for Wave Equation
NUMERICAL DIFFERENTIATION Forward Difference Formula
Lecture 19 – Numerical Integration
Chapter 7 Numerical Differentiation and Integration
Approximate Integration
Numerical Integration Formulas
Parallel Sorting Algorithms
Parallel Matrix Multiplication and other Full Matrix Algorithms
Parallel Sorting Algorithms
Copyright © Cengage Learning. All rights reserved.
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Integration
Chapter 4, Integration of Functions
Presentation transcript:

Parallel Numerical Integration Spring Semester 2005 Geoffrey Fox Community Grids Laboratory Indiana University 505 N Morton Suite 224 Bloomington IN

Links See Chapter 4 of Pacheco’s MPI Book See npac.org/users/gcf/slitex/CPS615NI95/index.htmlhttp:// npac.org/users/gcf/slitex/CPS615NI95/index.html –For a more advanced treatment which we will highlight in these lectures See npac.org/projects/cps615spring00/presentations- html/cps615nic95/ for lectures on Romberg’s methodhttp:// npac.org/projects/cps615spring00/presentations- html/cps615nic95/ There is also software at npac.org/projects/cpsedu/summer98summary/examples/ mpi-c/mpi-c.html (Examples 1 and 2) npac.org/projects/cpsedu/summer98summary/examples/ mpi-c/mpi-c.html

Problem to be Solved Integrals can be done in many dimensions but for the methods discussed here the essential issues are seen in one dimension –Although as advanced references describe in three and especially higher dimensions than that, Monte Carlo Methods become preferred approach We wish to calculate the integral of a function f(x) from x=a to x=b Implicitly we assume f(x) is relatively smooth, set up a set of “interpolation” or grid points x i in region a ≤ x ≤ b and calculate the integral in term of values of f(x) at the grid points ∫ I = f(x) dx a b

Trapezoidal Rule This makes the strong assumption that f(x) is constant I = 0.5*(b-a)*(f(a)+f(b)) x0x X=aX=b f(a) f(b)

Simpson’s Rule This makes the less strong assumption that f(x) is a quadratic function I = (b-a)*(f(a)+ 4f(x c )+f(b))/6 x X=aX=b f(a) f(b) x c = (a+ b)/2 f(X c )

Iterated Rules There are a set of rules (Newton-Cotes and Gaussian) which make higher and higher order polynomial approximations to f(x) –These are hard to program conveniently and not very “robust” (they work very badly if f(x) is varying rapidly in non-polynomial fashion) So in practice one uses iterated Simpson or Trapezoidal Rules – use an odd number of points to apply Simpson’s rule iteratively e.g. Apply Simpson over each of 18 sub intervals delineated by arrows below Trapezoidal iteration would involve 36 separate integrals x0x0 x4x4 x8x8 x 12 x 16 x 20 x 24 x 28 x 32 x 36

Other Choices Gaussian ingeniously chooses the points between x=a and x=b to be exact for very high order polynomials To avoid “tail wagging dog” the points are denser near the endpoints –High order polynomials get large quickly as x increases; to control this “tail” put points at edge of region to be interpolated Gaussian b a Smaller Than This case is exact for polynomials of degree ≤ 13

Monte Carlo Methods Monte Carlo (the most important) un-ingeniously chooses the points at random The Integral is sum of the function values f(x Random-i ) at the randomly chosen x values x Random-i multiplied by the Interval (b-a here) divided by the number of generated points This gives the most robust method (unbiased) that is easiest to apply for multi-dimensional integrals and integrals of badly behaved functions Funny boundaries are easy to take care of –Integrate over convenient region bigger than real region –Define function to be zero outside true integration region –Often makes function discontinuous but OK for Monte Carlo b a

Errors For an integral with N points Monte Carlo has error 1/N 0.5 Iterated Trapezoidal has error 1/N 2 Iterated Simpson has error 1/N 4 Iterated Gaussian is error 1/N 2m for our a basic integration scheme with m points But in d dimensions, for all but Monte Carlo must set up a Grid of N 1/d points on a side; that hardly works above N=3 –Monte Carlo error still 1/N 0.5 –Simpson error becomes 1/N 4/d etc.

Iterated Trapezoidal and Simpson Rule Suppose we have N points x i with I= (b-a) (f(x 0 )+2f(x 1 )+2f(x 2 )+ …… +2f(x (N-2) )+f(x (N-1) )/(2(N-1)) While Simpson’s Rule is I= (b-a) (f(x 0 )+4f(x 1 )+2f(x 2 )+ …… +4f(x (N-2) )+f(x (N-1) )/(3(N-1)) They all add f(x i ) with different weights Note trapezoidal and Simpson rule apply their approximation over a region of size (b-a)/(N-1) (twice this for Simpson) which goes to zero as N gets large so approximation gets better as N geta larger

The weight Functions One is adding up w i f(x i ) and the different algorithms just correspond to different w i Trapezoidal for index values = N-1 has characteristic pattern w i  … Simpson for the same indices and N odd has characteristic pattern w i  …

Parallel Computing Different processors calculating independently different points in the integral and then sum results in each processor Most natural is scenario shown in figure with each processor calculating an integral over a subregion –x 0 to x 8 in processor 0 … x 24 to x 32 in processor 3 etc. –Then total Integral is sum of sub-integrals calculated in each processor However it is also possible to assign POINTS not REGIONS to processors –x 0 x 4 x 8.. x 32 in processor 0 –x 3 x 7 x 11.. x 31 in processor 3 x0x0 x4x4 x8x8 x 12 x 16 x 20 x 24 x 28 x

Issues in Numerical Integration for Parallel Computing This is a classic master worker paradigm with individual processors calculating parts of the integral They need to use MPI rank to decide which part of integration range they are responsible for They calculate integral over this range and then we just sum their contributions over all processors –Global sum can be done by pipeline, tree or by all workers independently sending their results to the master

Calculating Sum I Homework 2

Calculating Sum II

Calculating Sum III Note distribution of A is not done properly here This is not a problem in related parallel integration

Argonne Calculation of π I This comes from npac.org/projects/cdroms/cewes vol2/cps615course/examples/pi.c npac.org/projects/cdroms/cewes vol2/cps615course/examples/pi.c But I think the preamble is dubious so I have changed it below; The code is correct We are calculating π = 4/(1+x*x) dx ∫ 0 1

Argonne Calculation of π II The method evaluates the integral of 4/(1+x*x) between 0 and 1. The method is simple: the integral is approximated by a sum of n intervals; the approximation to the integral in each interval is (1/n)*4/(1+x*x) where x is the midpoint of the integral (this is a variant of the trapezoidal method) n is the total number of points; The master process (rank 0) asks the user for the number of intervals; N proc is number of processors The master should then broadcast this number to all of the other processes. Each process with a given rank then adds up every N proc 'th interval (x = rank/n, rank/n+N proc /n, -rank/n+2N proc /n...). Finally, the sums computed by each process are added together using an MPI reduction. Note this is a case where we assign POINTS not REGIONS to processors and points are not adjacent; note all points have the same weight function in this method

Argonne Calculation of π III

Input n from user Broadcast to all processors Calculate sum in each processor Starting at offset index myid and increasing by numprocs MPI_Reduce with MPI_SUM flag calculates global sum of first argument &mypi and returns to root processor Argonne Calculation of π IV

Simpson’s Rule I 06-vol1/cps615course/index.htmlhttp:// 06-vol1/cps615course/index.html Brief description: Using Simpson's rule we compute the value of π. When using this approach and integrating on a multiprocessor, the logical thing to do would be to partition the interval to subintervals and make each processor run on one of these subintervals. In turn, each processor applies Simpson's rule to its own interval, again, partitioning it into subintervals of equal number to the one above it, etc. Among the processors, one takes charge of receiving and adding up the results

Simpson’s Rule II This time we assign regions to each processor my_rank labels processors Each processor calculates from x1= my_rank/N proc to x2= x1 + 1/N proc N is now the number of Simpson rule intervals in each processors (so we use a total of 2N-1 points in each processor with end points shared Again We are calculating π = 4/(1+x*x) dx ∫ 0 1

Simpson’s Rule III Set the C and MPI Scene

Simpson’s Rule IV Calculate the integral inside each processor We divide the range x1 to x2 in each processor into N sub-integrals and each sub-integral is done by Simpson’s rule using points at each end and the one in the middle of the sub-integral

Simpson’s Rule V Sum results over all processors using simple (non-optimal) method where all processors send to “processor 0”

Simpson’s Rule VI Print out exact value – unimportant for parallel computing and a bit obscure!

Simpson’s Rule VII Here are the auxiliary functions integrate_f is straightforward but the form of simpson is obscure albeit correct There are more efficient (less arguments for simpson) and elegant formulations Note this approach needs special test on i==(n-1) here and adding endpoints in the main body of code