collatz_parfor


collatz_parfor, a MATLAB code using the parfor() statement for parallel execution, to find the longest Collatz sequence in the range 1 through N.

A Collatz sequence starting at the integer I computes the next term by halving the number if it is even, or tripling and adding 1 if it is odd. The sequence stops when the value 1 is reached.

The number of steps required to reach 1 varies greatly. No formula has been determined, and in fact, it hasn't actually been proved that the value of 1 will always be reached.

An interesting question, suitable for parallel execution, is to ask for the length of the longest Collatz sequence between 1 and N.

Depending on the situation, the function could be executed in parallel:

Usage:

The basic calculation is done by collatz_parfor and has the form:

j_max = collatz_parfor ( n )
where

Licensing:

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

Languages:

collatz_parfor is available in a MATLAB version.

Related Data and codes:

collatz_parfor_test

collatz, a MATLAB code which computes and analyzes the Collatz sequence (or "hailstone" sequence or "3n+1 sequence");

collatz_recursive, a MATLAB code which demonstrates recursive programming by considering the simple Collatz 3n+1 problem.

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.

matlab_parallel, a MATLAB code which illustrates "local" parallel programming on a single computer with MATLAB's Parallel Computing Toolbox.

matlab_random_parallel, a MATLAB code which uses random number generator (RNG) functions when using parallel features such as parfor or spmd.

matrix_assemble_parfor, a MATLAB code which demonstrates the parfor parallel programming feature by assembling 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 demonstrates how parfor() can be used to parallelize the computation of a grid of solutions to a parameterized system of ODE's.

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.

trapz_parfor, a MATLAB code which shows how a parfor() loop can be used to call the trapz() function, to compute several integral approximations in parallel.

  1. Gaurav Sharma, Jos Martin,
    MATLAB: A Language for Parallel Computing,
    International Journal of Parallel Programming,
    Volume 37, Number 1, pages 3-36, February 2009.
  2. Michael Quinn,
    Parallel programming in C with MPI and OpenMP,
    McGraw-Hill, 2004,
    ISBN13: 978-0071232654,
    LC: QA76.73.C15.Q55.
  3. Eric Weisstein,
    "The Collatz Problem",
    CRC Concise Encyclopedia of Mathematics,
    CRC Press, 2002,
    Second edition,
    ISBN: 1584883472,
    LC: QA5.W45.

Source Code:


Last modified on 30 November 2023.