PRIME_NUMBER_OPEN_MP is a FORTRAN77 program which counts the number of primes between 1 and N, using OpenMP to carry out the calculation in parallel.
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.
This program is mainly a starting point for investigations into parallelization.
Here are the counts of the number of primes for some selected values of N:
| N | Pi(N), Number of Primes |
|---|---|
| 1 | 0 |
| 2 | 1 |
| 4 | 2 |
| 8 | 4 |
| 16 | 6 |
| 32 | 11 |
| 64 | 18 |
| 128 | 31 |
| 256 | 54 |
| 512 | 97 |
| 1024 | 172 |
| 2048 | 309 |
| 4096 | 564 |
| 8192 | 1028 |
| 16384 | 1900 |
| 32768 | 3512 |
| 65536 | 6542 |
| 131072 | 12251 |
The following results were observed for the elapsed time on a machine that had 2 cores:
| N | Pi(N) | Time (1 Thread) | Time (2 Threads) | Time (4 Threads) |
|---|---|---|---|---|
| 16384 | 1900 | 0.377 | 0.293 | 0.220 |
| 32768 | 3512 | 1.392 | 1.061 | 0.824 |
| 65536 | 6542 | 5.221 | 3.883 | 3.012 |
| 131072 | 12251 | 19.727 | 14.592 | 11.672 |
In the BASH shell, the program could be run with 2 threads using the commands:
export OMP_NUM_THREADS=2
./prime_number_open_mp
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
FFT_OPEN_MP is a FORTRAN77 program which demonstrates the computation of a Fast Fourier Transform in parallel, using OpenMP.
MD_OPEN_MP is a FORTRAN77 program which carries out a molecular dynamics simulation in parallel, using OpenMP.
MXV_OPEN_MP is a FORTRAN77 program which compares the performance of plain vanilla Fortran and the FORTRAN90 intrinsic routine MATMUL, for the matrix multiplication problem y=A*x, with and without parallelization by OpenMP.
OPEN_MP FORTRAN77 programs which illustrate the use of the OpenMP application program interface for carrying out parallel computations in a shared memory environment.
OPEN_MP_ITHACA FORTRAN77 programs which illustrate the use of OpenMP on the Virginia Tech ITHACA cluster.
PRIME_NUMBER is a FORTRAN77 program which counts the number of primes between 1 and N.
PRIME_NUMBER_MPI is a FORTRAN77 program which counts the number of primes between 1 and N, using MPI for parallel execution.
PRIME_NUMBER_OPEN_MP is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version.
PRIME_NUMBER_PARALLEL is a MATLAB program which counts the number of primes between 1 and N; it runs in parallel using MATLAB's "parfor" facility.
QUAD_OPEN_MP is a FORTRAN77 program which approximates an integral using a quadrature rule, and carries out the computation in parallel using OpenMP.
RANDOM_OPEN_MP, FORTRAN77 programs which illustrate and explore issues involving the generation of random numbers in a parallel program using OpenMP.
SATISFIABILITY_OPEN_MP is a FORTRAN77 program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, using OpenMP for parallel execution.
SGEFA_OPEN_MP is a FORTRAN77 program which reimplements the SGEFA/SGESL linear algebra routines from LINPACK for use with OpenMP.
TIMER is a directory of FORTRAN77 programs which demonstrate how to compute CPU time or elapsed time.
ZIGGURAT_OPEN_MP, a FORTRAN77 program which demonstrates how the ZIGGURAT library can be used to generate random numbers in an OpenMP parallel program.
PRIME_NUMBER_OPEN_MP_RUN runs PRIME_NUMBER_OPEN_MP interactively.
PRIME_NUMBER_OPEN_MP_BATCH runs PRIME_NUMBER_OPEN_MP through the batch system.
You can go up one level to the FORTRAN77 source codes.