prime_openmp, a C++ code 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 | 
In the BASH shell, the program could be run with 2 threads using the commands:
        export OMP_NUM_THREADS=2
        ./prime_openmp
      
    
    The information on this web page is distributed under the MIT license.
prime_openmp is available in a C version and a C++ version and a Fortran90 version.
openmp_test, a C++ code which uses the OpenMP application program interface for parallel computations in a shared memory environment.
prime, a C++ code which counts the number of primes between 1 and N, intended as a starting point for the creation of a parallel version.
prime_mpi, a C++ code which counts the number of primes between 1 and N, using MPI for parallel execution.