# MATRIX_ASSEMBLE_SPMD SPMD (Single Program/Multiple Data) Matrix Assembly

MATRIX_ASSEMBLE_SPMD is a MATLAB program which uses the SPMD (single program, multiple data) command to assemble a large matrix as a collection of strips which are joined at the end of the computation.

The MxN Hilbert matrix is to be computed. Supposing we have K SPMD workers, each worker will generate a strip of size Mx(N/K). The SPMD client can concatenate these strips at the end of the computation.

Of course, this is a fairly trivial calculation, and not a terribly exciting exhibition of parallelism. However, it is one step in a process of trying to figure out how a finite element code could use parallelism to assemble the system matrix, for instance.

The function has the form:

function a = hilbert_fun ( m, n )
where
• m, n are the number of rows and columns;
• a is the computed matrix.

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 a remote cluster, using the batch command;
• indirectly, and on the FSU HPC cluster, using the fsuClusterMatlab command;

### Languages:

MATRIX_ASSEMBLE_SPMD is available in a MATLAB version.

### Related Data and Programs:

CONTRAST_SPMD, a MATLAB program which demonstrates the SPMD parallel programming feature for image operations; the client reads an image, the workers increase contrast over separate portions, and the client assembles and displays the results.

CONTRAST2_SPMD, a MATLAB program which demonstrates the SPMD parallel programming feature for image operations; this improves the contrast_spmd program by allowing the workers to share some data; this makes it possible to eliminate artificial "seams" in the processed image.

DIJKSTRA_SPMD, a MATLAB program which uses the SPMD feature to parallelize a simple example of Dijkstra's minimum distance algorithm for graphs.

FACE_SPMD, a MATLAB program which demonstrates the SPMD parallel programming feature; the client has a 3D box that has been dissected into tetrahedrons. Multiple workers cooperate to construct a list of the triangular faces that lie on the boundaries of the box.

FD2D_HEAT_EXPLICIT_SPMD, a MATLAB program which uses the finite difference method and explicit time stepping to solve the time dependent heat equation in 2D. A black and white image is used as the "initial condition". MATLAB's SPMD facility is used to carry out the computation in parallel.

IMAGE_DENOISE_SPMD, a MATLAB program which demonstrates the SPMD parallel programming feature for image operations; the client reads an image, the workers process portions of it, and the client assembles and displays the results.

LINEAR_SOLVE_DISTRIBUTED, 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, MATLAB programs which illustrate "local" parallel programming on a single computer with MATLAB's Parallel Computing Toolbox.

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

PLOT_SPMD, a MATLAB library which demonstrates the SPMD parallel programming feature, by having a number of labs compute parts of a sine plot, which is then displayed by the client process.

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

QUAD_SPMD, a MATLAB library which demonstrates the SPMD parallel programming feature, by having a number of labs each estimate part of an integral using quadrature.

### 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

• 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:

HILBERT is a simple example of matrix assembly, in which the calculation of the individual entries does not take very much time. (A better example might have fewer matrix entries which each take up much more time to calculate).

• hilbert_fun.m, a MATLAB function which returns the MxN Hilbert matrix, using the available SPMD workers.

### Source Code:

• hilbert_pool.m a script which uses the MATLABPOOL command to run the function locally and interactively.
• hilbert_script.m, a MATLAB script file which simply invokes the function with M = N = 100.
• hilbert_batch_local.m, a batch command to run the job indirectly on the local system, plus a few more commands to monitor its progress, print the diary, and destroy the job at the end.
• hilbert_fsu.m a script which uses the fsuClusterMatlab command to run the function indirectly on the FSU HPC cluster.

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

Last revised on 26 February 2011.