PRIME_NUMBER_PARALLEL
Parallel Program to Count Primes


PRIME_NUMBER_PARALLEL is a MATLAB program which counts the number of primes between 1 and N.

The algorithm is completely naive. For each integer I, it simply checks whether any smaller J evenly divides it. The total amount of work for a given N is thus roughly proportional to 1/2*N^2.

There is very little memory traffic and no communication, so this program is a good test for the pure computational speedup offered by MATLAB's Parallel Programming Toolbox.

On a single computer, using the MATLAB Parallel Toolbox, the following results were observed for the elapsed time using 1 client and 0, 1, 2 and 4 "labs" or "workers":
N1+01+11+21+4
500.0670.1790.1760.278
5000.0080.0230.0270.032
5,0000.1000.1420.0970.061
50,0007.6949.8115.2512.719
500,000609.764826.534432.233222.284

On the Ithaca cluster with the MATLAB Parallel Toolbox version 4.1, running with the "ithaca" configuration across multiple nodes, the following results were observed:
N1+81+161+321+64
5 0.377 0.357 0.360 0.412
50 0.221 0.433 0.430 0.504
500 0.056 0.121 0.199 0.416
5,000 0.058 0.087 0.215 0.428
50,000 1.080 0.564 0.326 0.357
500,000 81.649 39.987 19.237 9.808

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:

BIRTHDAY_REMOTE, a MATLAB program which runs a Monte Carlo simulation of the birthday paradox, and includes instructions on how to run the job, via MATLAB's BATCH facility, on a remote system such as Virginia Tech's ITHACA cluster.

COLLATZ_PARALLEL is a MATLAB program which seeks the maximum Collatz sequence between 1 and N; it runs in parallel using MATLAB's "parfor" facility.

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.

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, using MATLAB's "PARFOR" feature.

PRIME_NUMBER is a MATLAB program which counts the number of primes between 1 and N.

PRIME_NUMBER_OPEN_MP is a C program which counts the number of primes between 1 and N, using OpenMP for parallel execution.

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.

QUAD_SPMD is a MATLAB program which estimates an integral using quadrature; 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:

Examples and Tests:

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


Last revised on 03 February 2010.