peach icon indicating copy to clipboard operation
peach copied to clipboard

wrong number of parallel threads when number of elements is relatively small compared to degree of parallelism

Open awalland opened this issue 12 years ago • 1 comments

hi!

thanks a lot for peach, i think it's a great way to parallelize things, but there's a bug when the number of elements to be looped is less than 2*threads:

#!/usr/bin/env ruby

require 'peach'


@max_threads=10
@elements=19

exports = Array.new
puts "start"


$i = 0;
$num = @elements;

while $i < $num  do
    exports.push($i)
   $i +=1;
end

puts "array initialized"

def do_export(num)
    print " |export #{num} "
    %x(sleep 5)
end

puts "max_threads: #{@max_threads}"

exports.peach(@max_threads) do |export|
    do_export(export)
end

this code will execute 19 threads instead of 10.

awalland avatar Oct 10 '12 15:10 awalland

see #11

petr-tichy avatar Apr 13 '17 13:04 petr-tichy