# ODE_SWEEP_PARFOR A Parallel MATLAB Function Using PARFOR

ODE_SWEEP_PARFOR is a directory which illustrates how a MATLAB function using the PARFOR statement can be run in parallel.

Consider the parameterized second order differential equation:

```        m x'' + b x' + k x = 0
```
which represents the behavior of a spring mass system with a mass of m, a spring constant of k and a damping coefficient b.

We now suppose that we are interested in properties of the solution x(t) over the time interval from 0 to 25 seconds, as we vary the physical properties b and k. In particular, we would like to know the maximum value of x(t) over the time interval for each choice of the physical parameters.

To answer this question, we must solve the ODE for each choice of the parameters. Each solution is an independent computation, and one way to carry out the computations in parallel is to use MATLAB's parfor statement.

The basic function has the form:

function peakVals = ode_fun ( bVals, kVals )
where
• bVals is an array of B values;
• kVals is an array of K values;
• peakVals is an array containing the maximum value of the ODE solution for each combination of B and K.

Depending on the situation, the function could be executed in parallel:

• interactively, and locally, using the matlabpool command;
• indirectly, and locally, using the batch command;
• indirectly, and on the Ithaca cluster, using the batch command;
• indirectly, and on the FSU HPC cluster, using the fsuClusterMatlab command;

### Languages:

ODE_SWEEP_PARFOR is available in a MATLAB version.

### Related Data and Programs:

COLLATZ_PARFOR, a MATLAB program which seeks the maximum Collatz sequence between 1 and N, running in parallel using MATLAB's parfor feature.

HEATED_PLATE_PARFOR, a MATLAB program which solves the steady (time independent) heat equation in a 2D rectangular region, using MATLAB's parfor facility to run in parallel.

HELLO_PARFOR, a MATLAB program which prints out "Hello, world!" multiple times, using MATLAB's parfor command for parallel execution.

HIGH_CARD_PARFOR, a MATLAB program which uses the parfor statement to compute in parallel the statistics for a card game in which you are required to guess the location of the highest card.

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

MATLAB_RANDOM_PARALLEL, MATLAB programs which illustrate the use of Matlab's random number generator (RNG) functions when using parallel features such as parfor or spmd.

MATRIX_ASSEMBLE_PARFOR, a MATLAB program which demonstrates the parfor parallel programming feature by assembling the Hilbert matrix in a parallel loop.

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

ODE_SWEEP_SERIAL, a MATLAB program which computes a grid of solutions to a parameterized system of ordinary differential equations (ODE's).

PRIME_PARFOR, a MATLAB program which counts the number of primes between 1 and N; running in parallel using MATLAB's "PARFOR" feature.

QUAD_PARFOR, a MATLAB program which estimates an integral using quadrature; running in parallel using MATLAB's "PARFOR" feature.

SATISFY_PARFOR, 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.

SPARSE_PARFOR, a MATLAB library which demonstrates how a sparse matrix can be constructed by evaluating individual blocks in parallel with the parfor command, and then assembled (on a single processor) using the sparse() command.

### Reference:

The User's Guide for the Parallel Computing Toolbox is available at http://www.mathworks.com/access/helpdesk/help/pdf_doc/distcomp/distcomp.pdf

1. Gaurav Sharma, Jos Martin,
MATLAB: A Language for Parallel Computing,
International Journal of Parallel Programming,
Volume 37, Number 1, pages 3-36, February 2009.

### Source Code:

• ode_fun.m, the function which performs the calculations.
• ode_system.m, a function which redefines the second order ODE as a pair of first order ODE's, suitable for treatment by MATLAB's ODE solvers.
• ode_display.m, a script which displays a contour plot of the results of the parameter sweep.
• ode_display.png, a surface plot of the data XMAX(B,K) computed by the program.

### Examples and Tests:

ODE_POOL executes the function locally and interactively.

ODE_BATCH_LOCAL executes the function locally and noninteractively.

ODE_FSU executes the function on the FSU HPC cluster.

• ode_fsu.m a script which uses the fsuClusterMatlab command to run the function indirectly on the FSU HPC cluster.

ODE_ITHACA executes the function on the Virginia Tech Ithaca cluster.

• ode_ithaca.m a script which runs the function on the Virginia Tech Ithaca cluster.

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

Last revised on 26 March 2010.