Distributes enum
across threads
and calls the
passed block with args:
Unitary object from enum
Index of the unitary object
Index of the acting thread
# File lib/miga/parallel.rb, line 22 def distribute(enum, threads, &blk) process(threads) { |thr| thread_enum(enum, threads, thr, &blk) } end
Executes the passed block with the thread number as argument (0-numbered)
in threads
processes
# File lib/miga/parallel.rb, line 10 def process(threads) threads.times do |i| Process.fork { yield(i) } end Process.waitall end
Enum through enum
executing the passed block only for thread
with index thr
, one of threads
threads. The
passed block has the same arguments as the one in #distribute
# File lib/miga/parallel.rb, line 30 def thread_enum(enum, threads, thr) enum.each_with_index do |obj, idx| yield(obj, idx, thr) if idx % threads == thr end end