%% quad_timings.m

  jmax = 4;
  imax = 23;

  tvec = zeros(imax,jmax);
  nvec = zeros(imax);

  wvec = [ 0, 1, 2, 4 ];

  for j = 1 : 4

    w = wvec(j);
  
    a = 0.0;
    b = 2.0;
    f = @(x) (4*x+1)*(11-4*x)/8;

    if ( 0 < w )
      matlabpool ( 'open', 'local', w );
    end

    n = 1;
    for i = 1 : imax
      tic
      q = quad_parfor ( a, b, n, f );
      tvec(i,j) = toc;
      nvec(i) = n;
      n = 2 * n;
    end

    if ( 0 < w )
      matlabpool ( 'close' )
    end

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '         N      0         1         2         4\n' );
  fprintf ( 1, '\n' );
  for i = 1 : imax
    fprintf ( 1, '  %8d', nvec(i) );
    for j = 1 : jmax
      fprintf ( 1, '  %8.4f', tvec(i,j) );
    end
    fprintf ( 1, '\n' );
  end

  clf
  hold on
  figure ( 1 )
  plot ( log2(nvec), tvec(:,1) ./ tvec(:,1), ...
         log2(nvec), tvec(:,1) ./ tvec(:,2), ...
         log2(nvec), tvec(:,1) ./ tvec(:,3), ...
         log2(nvec), tvec(:,1) ./ tvec(:,4), 'Linewidth', 2 );
  grid on
  xlabel ( '<---Log2(N)--->' );
  ylabel ( '<---Log2(Wallclock Seconds)--->' );
  title ( 'Computational Rates Relative to Sequential Code, with 1, 2, and 4 Workers ' )
  hold off
  filename = 'quad_timings.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 'Plot saved as "%s"\n', filename );

