function collatz_parfor_test ( )

%*****************************************************************************80
%
%% collatz_parfor_test() uses parpool() to run the collatz() code in parallel.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 November 2023
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../collatz_parfor' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'collatz_parfor_test():\n' );
  fprintf ( 1, '  collatz_parfor() seeks the longest Collatz sequence\n' );
  fprintf ( 1, '  over the range 1 to N.\n' );
  fprintf ( 1, '  The parfor() function is used for parallel execution.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Workers   Wall time\n' );
  fprintf ( 1, '\n' );

  for w = [ 1, 2, 4, 8 ]

    n = 10000000;

    pool = parpool ( w );

    tic
    jmax = collatz_parfor ( n );
    tw = toc;

    fprintf ( 1, '  %6d  %2d  %g\n', jmax, w, tw );
    delete ( pool );

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'collatz_parfor_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../collatz_parfor' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the YcollatzHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2022
%
%  Author:
%
%    John Burkardt
%
  t = now ( );
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

