Module: Enumerable

Defined in:
lib/parallelize/enumerable_ext.rb

Defined Under Namespace

Modules: Parallelize

Instance Method Summary collapse

Instance Method Details

#peach(num_threads, collect_exceptions = false, &block) ⇒ Array

Divides the Enumerable objects into pieces and execute with multiple threads

Parameters:

  • num_threads (Fixnum)

    Number of concurrent threads

  • collect_exceptions (Boolean) (defaults to: false)

    If true, waits for all threads to complete even in case of exception, and throws ParallelException at the end. If false exception is immediately thrown.

Returns:

  • (Array)

    Threads.



85
86
87
# File 'lib/parallelize/enumerable_ext.rb', line 85

def peach num_threads, collect_exceptions = false, &block
  Parallelize.it self, num_threads, :each, collect_exceptions, &block
end

#pmap(num_threads, collect_exceptions = false, &block) ⇒ Array

Parallelized map.

Parameters:

  • num_threads (Fixnum)

    Number of concurrent threads

  • collect_exceptions (Boolean) (defaults to: false)

    If true, waits for all threads to complete even in case of exception, and throws ParallelException at the end. If false exception is immediately thrown.

Returns:

  • (Array)

    Map function output for each element



93
94
95
# File 'lib/parallelize/enumerable_ext.rb', line 93

def pmap num_threads, collect_exceptions = false, &block
  Parallelize.it self, num_threads, :map, collect_exceptions, &block
end