sparse_parfor


sparse_parfor a MATLAB code which constructs a sparse matrix by evaluating individual blocks in parallel with the parfor() command, and then assembled (on a single processor) using the sparse() command.

This script is a demonstration of how one can take advantage of MATLAB's parallel programming features when constructing a sparse matrix.

We construct a rectangular sparse matrix. This matrix can be thought of as a diagonal block matrix, with each diagonal block being of arbitrary size and shape.

In this example, it is assumed that the computation of the individual matrix elements is expensive, and worth doing in parallel.

On the other hand, once the elements have been computed, the "sparse()" command is called on a single processor to "assemble" the computed matrix elements into a single MATLAB sparse matrix data structure.

This problem was posed by Vitor Nunes, 18 August 2011.

Notice that there are many ways to set up a matrix, which seem reasonable, but which MATLAB's parfor() command will not accept, because the matrix is not properly ``sliced''. By using cell arrays, this example is able to divide the problem into indexed segments (blocks) that the parfor() and sparse() commands can usefully process.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

sparse_parfor is available in a MATLAB version.

Related Data and Programs:

sparse_parfor_test

collatz_parfor, a MATLAB code which seeks the maximum Collatz sequence between 1 and N, running in parallel using the parfor() command.

heated_plate_parfor, a MATLAB code which solves the steady (time independent) heat equation in a 2D rectangular region, using parfor() to run in parallel.

hello_parfor, a MATLAB code which prints out "Hello, world!" multiple times, using parfor() for parallel execution.

high_card_parfor, a MATLAB code 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.

matrix_assemble_parfor, a MATLAB code which uses parfor() for parallel execution to assemble the Hilbert matrix in a parallel loop.

md_parfor, a MATLAB code which carries out a molecular dynamics simulation, running in parallel using the parfor() feature.

ode_sweep_parfor, a MATLAB code which uses parfor() to parallelize the computation of a grid of solutions to a parameterized system of ordinary differential equations (ODE).

prime_parfor, a MATLAB code which counts the number of primes between 1 and N; running in parallel using the parfor() feature.

quad_parfor, a MATLAB code which estimates an integral using quadrature; running in parallel using the parfor() feature.

satisfy_parfor, a MATLAB code which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, running in parallel using the parfor() feature.

sparse_parfor, a MATLAB code 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.

Author:

Gene Cliff, Virginia Tech

Reference:

  1. John Gilbert, Cleve Moler, Robert Schreiber,
    Sparse Matrices in MATLAB: Design and Implementation,
    SIAM Journal on Matrix Analysis and Applications,
    Volume 13, Number 1, 1992, pages 333-356.
  2. 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:


Last revised on 15 December 2023.