prime_parfor


prime_parfor, a MATLAB code which counts the prime numbers from 1 to n, using the parfor() statement to run 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.

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.

The basic function has the form:

function total = prime_parfor ( n )
where

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

prime_for is available in a MATLAB version.

Related Data and Programs:

prime_parfor_test

collatz_parfor, a MATLAB code which seeks the maximum Collatz sequence between 1 and N, running in parallel using the parfor() command.

heated_plate_parfor, a MATLAB code which solves the steady (time independent) heat equation in a 2D rectangular region, using parfor() to run in parallel.

hello_parfor, a MATLAB code which prints out "Hello, world!" multiple times, using parfor() for parallel execution.

high_card_parfor, a MATLAB code which uses the parfor() statement to compute in parallel the statistics for a card game in which you are required to guess the location of the highest card.

matrix_assemble_parfor, a MATLAB code which uses parfor() for parallel execution to assemble the Hilbert matrix in a parallel loop.

md_parfor, a MATLAB code which carries out a molecular dynamics simulation, running in parallel using the parfor() feature.

ode_sweep_parfor, a MATLAB code which uses parfor() to parallelize the computation of a grid of solutions to a parameterized system of ordinary differential equations (ODE).

prime_parfor, a MATLAB code which counts the number of primes between 1 and N; running in parallel using the parfor() feature.

quad_parfor, a MATLAB code which estimates an integral using quadrature; running in parallel using the parfor() feature.

satisfy_parfor, a MATLAB code which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, running in parallel using the parfor() feature.

sparse_parfor, a MATLAB code which demonstrates how a sparse matrix can be constructed by evaluating individual blocks in parallel with the parfor() command, and then assembled (on a single processor) using the sparse() command.

Reference:

Source Code:


Last revised on 11 December 2023.