parallelize 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/parallelize.rb +1 -1
- data/lib/parallelize/enumerable_ext.rb +13 -10
- data/lib/parallelize/parallel_exception.rb +8 -8
- data/test/test_parallelize.rb +4 -0
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/parallelize.rb
CHANGED
@@ -6,6 +6,6 @@ require 'parallelize/enumerable_ext'
|
|
6
6
|
# @param [Fixnum] num_threads Number of concurrent threads
|
7
7
|
# @param [Boolean] collect_exceptions 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.
|
8
8
|
def parallelize num_threads, collect_exceptions = false, &block
|
9
|
-
|
9
|
+
num_threads.times.peach(num_threads, collect_exceptions, &block)
|
10
10
|
end
|
11
11
|
|
@@ -19,8 +19,11 @@ module Enumerable
|
|
19
19
|
|
20
20
|
begin
|
21
21
|
prev_trap = trap('INT') { Thread.current.raise Interrupt }
|
22
|
-
enum.
|
23
|
-
|
22
|
+
count = enum.count{true}
|
23
|
+
return [] if count == 0
|
24
|
+
|
25
|
+
enum.each_slice((count / num_threads.to_f).ceil) do |slice|
|
26
|
+
threads <<
|
24
27
|
case block.arity
|
25
28
|
when 2
|
26
29
|
Thread.new(slice, threads.length) { |my_slice, thread_idx|
|
@@ -75,18 +78,18 @@ module Enumerable
|
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
# Divides the Enumerable objects into pieces and execute with multiple threads
|
82
|
+
# @return [Array] Threads.
|
83
|
+
# @param [Fixnum] num_threads Number of concurrent threads
|
84
|
+
# @param [Boolean] collect_exceptions 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.
|
85
|
+
def peach num_threads, collect_exceptions = false, &block
|
83
86
|
Parallelize.it self, num_threads, :each, collect_exceptions, &block
|
84
87
|
end
|
85
88
|
|
86
89
|
# Parallelized map.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
# @return [Array] Map function output for each element
|
91
|
+
# @param [Fixnum] num_threads Number of concurrent threads
|
92
|
+
# @param [Boolean] collect_exceptions 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.
|
90
93
|
def pmap num_threads, collect_exceptions = false, &block
|
91
94
|
Parallelize.it self, num_threads, :map, collect_exceptions, &block
|
92
95
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class ParallelException < Exception
|
2
|
-
|
3
|
-
|
2
|
+
# @return [Hash] Hash of exceptions thrown. Indexed by thread index.
|
3
|
+
attr_reader :exceptions
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(exceptions)
|
6
|
+
@exceptions = exceptions
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def to_s
|
10
|
+
"Exceptions thrown during parallel execution: [#{@exceptions.inspect}]"
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
|
data/test/test_parallelize.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallelize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
segments:
|
83
83
|
- 0
|
84
|
-
hash:
|
84
|
+
hash: 3252524563698678207
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.25
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
96
|
summary: Simple multi-threading for Ruby
|