parallel 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,7 +1,5 @@
1
- Run any kind of code in parallel Processes or Threads, to speedup computation by factor #{your_cpus} X.
2
-
3
- - Child processes are killed when your main process is killed through Ctrl+c or kill -2
4
- - Processes/threads are workers, they grab the next piece of work when they finish
1
+ Run any code in parallel Processes(> use all CPUs) or Threads(> speedup blocking operations).
2
+ Best suited for map-reduce or e.g. parallel downloads/uploads.
5
3
 
6
4
  Install
7
5
  =======
@@ -9,18 +7,7 @@ Install
9
7
 
10
8
  Usage
11
9
  =====
12
- ### Processes
13
- - Speedup through multiple CPUs
14
- - Speedup for blocking operations
15
- - Protects global data
16
- - Extra memory used
17
-
18
- ### Threads
19
- - Speedup for blocking operations
20
- - Global data can be modified
21
- - No extra memory used
22
-
23
- # 2 CPUs -> finished after 2 runs (a,b + c)
10
+ # 2 CPUs -> work in 2 processes (a,b + c)
24
11
  results = Parallel.map(['a','b','c']) do |one_letter|
25
12
  expensive_calculation(letter)
26
13
  end
@@ -34,6 +21,21 @@ Usage
34
21
  Same can be done with `each`
35
22
  Parallel.each(['a','b','c']){|one_letter| ... }
36
23
 
24
+ ### Processes
25
+ - Speedup through multiple CPUs
26
+ - Speedup for blocking operations
27
+ - Protects global data
28
+ - Extra memory used
29
+ - Child processes are killed when your main process is killed through Ctrl+c or kill -2
30
+
31
+ ### Threads
32
+ - Speedup for blocking operations
33
+ - Global data can be modified
34
+ - No extra memory used
35
+
36
+
37
+ Processes/Threads are workers, they grab the next piece of work when they finish
38
+
37
39
  TODO
38
40
  ====
39
41
  - JRuby / Windows support <-> possible ?
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
data/lib/parallel.rb CHANGED
@@ -51,6 +51,8 @@ class Parallel
51
51
  end
52
52
 
53
53
  def self.map(array, options = {})
54
+ array = array.to_a if array.is_a?(Range)
55
+
54
56
  if options[:in_threads]
55
57
  method = :in_threads
56
58
  size = options[method]
data/parallel.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{parallel}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2009-10-16}
12
+ s.date = %q{2009-10-18}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -22,8 +22,10 @@ Gem::Specification.new do |s|
22
22
  "parallel.gemspec",
23
23
  "rdoc/README.rdoc",
24
24
  "spec/cases/parallel_each.rb",
25
+ "spec/cases/parallel_high_fork_rate.rb",
25
26
  "spec/cases/parallel_influence_outside_data.rb",
26
27
  "spec/cases/parallel_map.rb",
28
+ "spec/cases/parallel_map_range.rb",
27
29
  "spec/cases/parallel_map_sleeping.rb",
28
30
  "spec/cases/parallel_map_uneven.rb",
29
31
  "spec/cases/parallel_raise.rb",
@@ -45,11 +47,13 @@ Gem::Specification.new do |s|
45
47
  "spec/spec_helper.rb",
46
48
  "spec/cases/parallel_raise.rb",
47
49
  "spec/cases/parallel_sleeping_2.rb",
50
+ "spec/cases/parallel_high_fork_rate.rb",
48
51
  "spec/cases/parallel_start_and_kill.rb",
49
52
  "spec/cases/parallel_with_set_processes.rb",
50
53
  "spec/cases/parallel_influence_outside_data.rb",
51
54
  "spec/cases/parallel_map_sleeping.rb",
52
55
  "spec/cases/parallel_map_uneven.rb",
56
+ "spec/cases/parallel_map_range.rb",
53
57
  "spec/cases/parallel_with_detected_cpus.rb",
54
58
  "spec/cases/parallel_map.rb",
55
59
  "spec/cases/parallel_each.rb"
@@ -0,0 +1,5 @@
1
+ require 'spec/spec_helper.rb'
2
+ Parallel.each((0..200).to_a, :in_processes=>200) do |x|
3
+ sleep 1
4
+ end
5
+ print 'OK'
@@ -0,0 +1,6 @@
1
+ require 'spec/spec_helper.rb'
2
+
3
+ result = Parallel.map(1..5) do |x|
4
+ x
5
+ end
6
+ print result
@@ -42,6 +42,10 @@ describe Parallel do
42
42
  pending 'there is some kind of error, but not the original...'
43
43
  `ruby spec/cases/parallel_raise.rb`.should == 'TEST'
44
44
  end
45
+
46
+ it 'can handle to high fork rate' do
47
+ `ruby spec/cases/parallel_high_fork_rate.rb`.should == 'OK'
48
+ end
45
49
  end
46
50
 
47
51
  describe :in_threads do
@@ -88,6 +92,10 @@ describe Parallel do
88
92
  it "can run in threads" do
89
93
  Parallel.map([1,2,3,4,5,6,7,8,9], :in_threads=>4){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
90
94
  end
95
+
96
+ it 'supports ranges' do
97
+ `ruby spec/cases/parallel_map_range.rb`.should == '12345'
98
+ end
91
99
  end
92
100
 
93
101
  describe :each do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 +02:00
12
+ date: 2009-10-18 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,8 +29,10 @@ files:
29
29
  - parallel.gemspec
30
30
  - rdoc/README.rdoc
31
31
  - spec/cases/parallel_each.rb
32
+ - spec/cases/parallel_high_fork_rate.rb
32
33
  - spec/cases/parallel_influence_outside_data.rb
33
34
  - spec/cases/parallel_map.rb
35
+ - spec/cases/parallel_map_range.rb
34
36
  - spec/cases/parallel_map_sleeping.rb
35
37
  - spec/cases/parallel_map_uneven.rb
36
38
  - spec/cases/parallel_raise.rb
@@ -73,11 +75,13 @@ test_files:
73
75
  - spec/spec_helper.rb
74
76
  - spec/cases/parallel_raise.rb
75
77
  - spec/cases/parallel_sleeping_2.rb
78
+ - spec/cases/parallel_high_fork_rate.rb
76
79
  - spec/cases/parallel_start_and_kill.rb
77
80
  - spec/cases/parallel_with_set_processes.rb
78
81
  - spec/cases/parallel_influence_outside_data.rb
79
82
  - spec/cases/parallel_map_sleeping.rb
80
83
  - spec/cases/parallel_map_uneven.rb
84
+ - spec/cases/parallel_map_range.rb
81
85
  - spec/cases/parallel_with_detected_cpus.rb
82
86
  - spec/cases/parallel_map.rb
83
87
  - spec/cases/parallel_each.rb