QUAD_SPMD
SPMD (Single Program/Multiple Data) Quadrature


QUAD_SPMD is a MATLAB program which uses the SPMD (single program, multiple data) command to estimate an integral using quadrature.

The SPMD command allows a programmer to set up parallel computations that require more user control than the simple parfor command. In particular, users familiar with MPI will see many features that are similar to that parallel programming model, including the ability to send and receive messages. (Messages will NOT be exhibited in this simple example, however!)

The algorithm carried out estimates the integral of a function f(x) from 0 to 1 by the trapezoidal rule:

        Integral ( a <= x <= b ) f(x) dx = ( b - a ) / ( 2 * ( n - 1 ) )
          * ( f(x1) + 2*f(x2) + 2*f(x3) + ... + 2*f(xn-2) + 2*f(xn-1) + f(xn) )
      
where xi is the i-th point equally spaced between a and b, with the endpoints included.

It's clear that this calculation can be done in parallel, and in fact, simply by defining appropriate values of ai and bi, we can have parallel process i carry out the trapezoidal rule over [ai,bi] and sum the results to get the answer.

This example demonstrates how MATLAB's SPMD facility can be used to implement this parallel calculation. No attempt is made to compare the timings of the parallel code to a sequential calculation. The point here is simply the mechanics of setting up an SPMD calculation, and showing what you can expect.

Several points are worth mentioning:

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Related Data and Programs:

COLLATZ_PARALLEL is a MATLAB program which seeks the maximum Collatz sequence between 1 and N; running in parallel using MATLAB's "PARFOR" feature.

FDI_OPT, a MATLAB program which demonstrates the use of MATLAB's FMINCON constrained minimization function, taking advantage of MATLAB's Parallel Computing Toolbox for faster execution.

FLOYD_PARALLEL is a MATLAB program which attempts to run a parallel implementation of Floyd's algorithm for finding the shortest distance between pairs of nodes on a directed graph.

JTB_CODIST, a MATLAB program which demonstrates how the linear system associated with a finite element problem can be treated as a codistributed array whose entries are assigned to different MATLAB workers, so that the matrix is assembled in parallel.

LINEAR_SOLVE_DISTRIBUTED is a MATLAB program which solves a linear system A*x=b using MATLAB's spmd facility, so that the matrix A is "distributed" across multiple MATLAB workers.

MATLAB_PARALLEL, examples which illustrate "local" parallel programming on a single computer with MATLAB's Parallel Computing Toolbox.

MD_PARALLEL is a MATLAB program which carries out a molecular dynamics simulation in parallel, running in parallel using MATLAB's "PARFOR" feature.

PRIME_NUMBER_PARALLEL is a MATLAB program which counts the number of primes from 2 to N, running in parallel using MATLAB's "PARFOR" feature.

PRIME_NUMBER_SPMD is a MATLAB program which counts the number of primes between 1 and N; running in parallel using MATLAB's "SPMD" feature.

SATISFIABILITY_PARALLEL is a MATLAB program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, running in parallel using MATLAB's "PARFOR" feature.

TIMING_PARALLEL is a directory of MATLAB programs which illustrates how to time a parallel MATLAB program.

Reference:

MathWorks documentation for the Parallel Computing Toolbox is available at http://www.mathworks.com/products/parallel-computing/.

Source Code:

You can go up one level to the MATLAB source codes.


Last revised on 04 February 2010.