PRIME_SERIAL is a MATLAB program which counts the number of primes between 1 and N, and is intended as a starting point for a parallel version.
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.
Here are the counts of the number of primes for some selected values of N:
|N||Number of Primes|
The following results were observed for the elapsed time, running on a Macintosh PowerPC G5:
total = prime ( n )where
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
PRIME_SERIAL is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version.
COLLATZ, a MATLAB library which computes and analyzes the Collatz sequence (or "hailstone" sequence or "3n+1 sequence");
FFT_SERIAL, a MATLAB program which demonstrates the computation of a Fast Fourier Transform, and is intended as a starting point for implementing a parallel version.
FIRE_SERIAL, a MATLAB program which simulates a forest fire over a rectangular array of trees, starting at a single random location. It is intended as a starting point for the development of a parallel version.
MD, a MATLAB program which carries out a molecular dynamics simulation, and is intended as a starting point for implementing a parallel version.
MXM, a MATLAB program which sets up a matrix multiplication problem A=B*C, intended as a starting point for implementing a parallel version.
POISSON_SERIAL, a MATLAB program which computes an approximate solution to the Poisson equation in a rectangle, and is intended as the starting point for the creation of a parallel version.
PRIME_PARFOR, a MATLAB program which counts the number of primes between 1 and N; it runs in parallel using MATLAB's "parfor" facility.
PRIME_PLOT a MATLAB program which displays a box plot of the prime and composite numbers.
PRIME_SPMD, a MATLAB program which counts the number of primes between 1 and N; running in parallel using MATLAB's "SPMD" feature.
QUAD_SERIAL, a MATLAB program which approximates an integral using a quadrature rule, and is intended as a starting point for parallelization exercises.
QUAD2D_SERIAL, a MATLAB program which approximates an integral over a 2D region using a product quadrature rule, and is intended as a starting point for parallelization exercises.
SATISFY, a MATLAB program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem.
SEARCH_SERIAL, a MATLAB program which searches the integers from A to B for a value J such that F(J) = C. this version of the program is intended as a starting point for a parallel approach.
TIMER, MATLAB programs which demonstrate how to compute CPU time or elapsed time.
You can go up one level to the MATLAB source codes.