prime


prime, a Python code 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.

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

prime is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

fire_serial, a Python code 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.

prime_mpi, a Python code which counts the number of primes between 1 and N, using MPI for parallel execution.

quad_serial, a Python code which approximates an integral using a quadrature rule, and is intended as a starting point for parallelization exercises.

search_serial, a Python code which searches integers between A and B for a value J such that F(J) = C, intended as a starting point for the creation of a parallel version.

Reference:

  1. Eratosthenes,
    A Method For Finding Prime Numbers,
    Papyrus 487,
    code of Alexandria.

Source Code:


Last revised on 21 October 2019.