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.
Here are the counts of the number of primes for some selected values of N:
| N | Number of Primes |
|---|---|
| 5 | 3 |
| 50 | 15 |
| 500 | 95 |
| 5,000 | 669 |
| 50,000 | 5,133 |
| 500,000 | 41,538 |
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":
| N | 1+0 | 1+1 | 1+2 | 1+4 |
|---|---|---|---|---|
| 50 | 0.067 | 0.179 | 0.176 | 0.278 |
| 500 | 0.008 | 0.023 | 0.027 | 0.032 |
| 5,000 | 0.100 | 0.142 | 0.097 | 0.061 |
| 50,000 | 7.694 | 9.811 | 5.251 | 2.719 |
| 500,000 | 609.764 | 826.534 | 432.233 | 222.284 |
On the Ithaca cluster with the MATLAB Parallel Toolbox version 4.1, running in "local" mode, the following results were observed:
| N | 1+0 | 1+1 | 1+2 | 1+4 | 1+8 |
|---|---|---|---|---|---|
| 5 | 0.000 | 0.325 | 0.270 | 0.338 | 0.363 |
| 50 | 0.000 | 0.039 | 0.043 | 0.083 | 0.285 |
| 500 | 0.002 | 0.046 | 0.038 | 0.045 | 0.083 |
| 5,000 | 0.125 | 0.126 | 0.108 | 0.096 | 0.075 |
| 50,000 | 6.335 | 6.537 | 3.425 | 2.243 | 1.164 |
| 500,000 | 517.494 | 530.206 | 277.850 | 178.036 | 91.553 |
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:
| N | 1+8 | 1+16 | 1+32 | 1+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 |
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
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.
PRIME_NUMBER_LOCAL_RUN runs the program on a single machine, in "local" mode. A sample use might be
prime_number_local_run ( 5, 500000, 10, 4 )to run the program in local mode with 4 workers.
PRIME_NUMBER_ITHACA_RUN runs the program on the Ithaca cluster, in "interactive" mode. A sample use might be
prime_number_ithaca_run ( 5, 500000, 10, 16 )to run the program with 16 workers.
PRIME_NUMBER_BATCH_RUN runs the program on the Ithaca cluster, using the "batch" command. A sample use might be
batch ( 'prime_number_batch_run.m', 'Configuration', 'ithaca', 'matlabpool', 4 )where the 'ithaca' configuration must be set up and validated first.
You can go up one level to the MATLAB source codes.