tiamat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGES.rdoc +7 -0
  2. data/MANIFEST +42 -0
  3. data/README.rdoc +194 -0
  4. data/Rakefile +19 -0
  5. data/bin/tiamat-server +31 -0
  6. data/devel/jumpstart.rb +987 -0
  7. data/install.rb +2 -0
  8. data/lib/tiamat.rb +43 -0
  9. data/lib/tiamat/autoconfig.rb +8 -0
  10. data/lib/tiamat/child_server.rb +21 -0
  11. data/lib/tiamat/config/ruby_parser.rb +6 -0
  12. data/lib/tiamat/connector.rb +23 -0
  13. data/lib/tiamat/error.rb +24 -0
  14. data/lib/tiamat/farm.rb +32 -0
  15. data/lib/tiamat/local_child_farm.rb +23 -0
  16. data/lib/tiamat/local_child_server.rb +25 -0
  17. data/lib/tiamat/local_child_worker.rb +11 -0
  18. data/lib/tiamat/remote_farm.rb +11 -0
  19. data/lib/tiamat/remote_worker.rb +10 -0
  20. data/lib/tiamat/server.rb +42 -0
  21. data/lib/tiamat/tiamat.rb +49 -0
  22. data/lib/tiamat/tiamat_server.rb +48 -0
  23. data/lib/tiamat/util.rb +37 -0
  24. data/lib/tiamat/version.rb +4 -0
  25. data/lib/tiamat/worker.rb +61 -0
  26. data/spec/connector_spec.rb +11 -0
  27. data/spec/drb_connection_spec.rb +18 -0
  28. data/spec/local_child_farm_spec.rb +29 -0
  29. data/spec/local_child_server_path_spec.rb +37 -0
  30. data/spec/local_child_server_spec.rb +24 -0
  31. data/spec/local_child_worker_spec.rb +140 -0
  32. data/spec/pure_spec.rb +59 -0
  33. data/spec/readme_spec.rb +29 -0
  34. data/spec/remote_farm_spec.rb +36 -0
  35. data/spec/remote_worker_spec.rb +59 -0
  36. data/spec/server_spec.rb +48 -0
  37. data/spec/tiamat_open_local_spec.rb +77 -0
  38. data/spec/tiamat_open_remote_spec.rb +67 -0
  39. data/spec/tiamat_server_spec.rb +51 -0
  40. data/spec/tiamat_spec_base.rb +36 -0
  41. data/spec/util_spec.rb +29 -0
  42. data/spec/worker_spec.rb +19 -0
  43. metadata +209 -0
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ describe Tiamat::RemoteWorker do
4
+ before :each do
5
+ @uris = (47055..47060).map { |n|
6
+ "druby://localhost:#{n}"
7
+ }
8
+ # pretend these servers were running beforehand
9
+ @servers = @uris.map { |uri|
10
+ Tiamat::LocalChildServer.new(uri, *Tiamat.compiler.reverse)
11
+ }
12
+ end
13
+
14
+ after :each do
15
+ @servers.each { |server|
16
+ server.close
17
+ }
18
+ end
19
+
20
+ it "should compute without block" do
21
+ Tiamat::RemoteWorker.open(*@uris)
22
+ begin
23
+ pure(Pure::Parser::RubyParser) do
24
+ def f(x, y)
25
+ x + y
26
+ end
27
+
28
+ def x
29
+ 33
30
+ end
31
+
32
+ def y
33
+ 44
34
+ end
35
+ end.compute(Tiamat::RemoteWorker).f.should == 77
36
+ ensure
37
+ Tiamat::RemoteWorker.close
38
+ end
39
+ end
40
+
41
+ it "should compute with block" do
42
+ Tiamat::RemoteWorker.open(*@uris) do
43
+ Pure.worker.object_id.should eql(Tiamat::RemoteWorker.object_id)
44
+ pure(Pure::Parser::RubyParser) do
45
+ def f(x, y)
46
+ x + y
47
+ end
48
+
49
+ def x
50
+ 33
51
+ end
52
+
53
+ def y
54
+ 44
55
+ end
56
+ end.compute.f.should == 77
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ describe Tiamat::Server do
4
+ before :all do
5
+ @url = "druby://localhost:27272"
6
+ @remote_server = Tiamat::LocalChildServer.new(
7
+ @url, *Tiamat.compiler.reverse
8
+ )
9
+ @server = Tiamat::Server.new(@url)
10
+ end
11
+
12
+ after :all do
13
+ @remote_server.close
14
+ @server.close
15
+ end
16
+
17
+ it "should connect to remote server" do
18
+ @server.instance_eval {
19
+ @drb_object.ping
20
+ }
21
+ end
22
+
23
+ it "should evaluate a pure function spec" do
24
+ mod = pure(Pure::Parser::RubyParser) do
25
+ def f
26
+ 33 + 44
27
+ end
28
+ end
29
+ spec = Pure::ExtractedFunctions[Pure::Parser::RubyParser][mod][:f]
30
+
31
+ @server.evaluate_function(spec).should == 77
32
+ end
33
+
34
+ it "should fail with undumpable objects by default" do
35
+ DRb.primary_server.should be_nil
36
+
37
+ lambda {
38
+ @server.evaluate_function(STDOUT)
39
+ }.should raise_error(DRb::DRbConnError, %r!DRbServerNotFound!)
40
+ end
41
+
42
+ it "should ignore subsequent calls to close()" do
43
+ lambda {
44
+ @server.close
45
+ @server.close
46
+ }.should_not raise_error
47
+ end
48
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ require 'benchmark'
4
+
5
+ epsilon = 0.25 + TiamatSpecBase.slow_platform_epsilon
6
+
7
+ describe Tiamat do
8
+ before :all do
9
+ @mod = Pure.define do
10
+ def total(left, right)
11
+ left + right
12
+ end
13
+ def left
14
+ (1..100_000).inject(0) { |acc, n| acc + n }
15
+ end
16
+ def right
17
+ (1..100_000).inject(0) { |acc, n| acc + n }
18
+ end
19
+ end
20
+ end
21
+
22
+ describe ".open_local" do
23
+ describe "with block" do
24
+ it "should launch local servers" do
25
+ one_cpu = Benchmark.realtime { @mod.compute(2).total }
26
+ two_cpu = Tiamat.open_local(2) {
27
+ Pure.worker.should eql(Tiamat::LocalChildWorker)
28
+ Pure.worker.closed?.should eql(false)
29
+ Benchmark.realtime { @mod.compute.total }
30
+ }
31
+ (two_cpu/one_cpu).should be_close(0.5, epsilon)
32
+ Tiamat::LocalChildWorker.closed?.should eql(true)
33
+ end
34
+ end
35
+
36
+ describe "without block" do
37
+ it "should launch local servers" do
38
+ one_cpu = Benchmark.realtime { @mod.compute(2).total }
39
+ Pure.worker = Tiamat.open_local(2)
40
+ begin
41
+ Pure.worker.should eql(Tiamat::LocalChildWorker)
42
+ Pure.worker.closed?.should eql(false)
43
+ two_cpu = Benchmark.realtime { @mod.compute.total }
44
+ (two_cpu/one_cpu).should be_close(0.5, epsilon)
45
+ ensure
46
+ Pure.worker.close
47
+ Pure.worker = Pure::NativeWorker
48
+ end
49
+ Tiamat::LocalChildWorker.closed?.should eql(true)
50
+ end
51
+ end
52
+
53
+ it "should accept require list" do
54
+ mod = pure do
55
+ def f(s)
56
+ Base64.encode64(Matrix[[s]][0, 0])
57
+ end
58
+ end
59
+
60
+ Tiamat.open_local(1) {
61
+ lambda {
62
+ mod.compute(:s => "abc").f
63
+ }.should raise_error(NameError, %r!Base64!)
64
+ }
65
+
66
+ Tiamat.open_local(1, 'base64') {
67
+ lambda {
68
+ mod.compute(:s => "abc").f
69
+ }.should raise_error(NameError, %r!Matrix!)
70
+ }
71
+
72
+ Tiamat.open_local(1, 'base64', 'matrix') {
73
+ mod.compute(:s => "abc").f.should == "YWJj\n"
74
+ }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ require 'benchmark'
4
+
5
+ epsilon = 0.25 + TiamatSpecBase.slow_platform_epsilon
6
+
7
+ describe Tiamat do
8
+ before :all do
9
+ @mod = Pure.define do
10
+ def total(left, right)
11
+ left + right
12
+ end
13
+ def left
14
+ (1..100_000).inject(0) { |acc, n| acc + n }
15
+ end
16
+ def right
17
+ (1..100_000).inject(0) { |acc, n| acc + n }
18
+ end
19
+ end
20
+ end
21
+
22
+ describe ".open_remote" do
23
+ before :all do
24
+ @uris = (47055..47060).map { |n|
25
+ "druby://localhost:#{n}"
26
+ }
27
+ @servers = @uris.map { |uri|
28
+ Tiamat::LocalChildServer.new(uri, *Tiamat.compiler.reverse)
29
+ }
30
+ end
31
+
32
+ after :all do
33
+ @servers.each { |t| t.close }
34
+ Tiamat::RemoteWorker.close
35
+ end
36
+
37
+ describe "with block" do
38
+ it "should connect to remote servers" do
39
+ one_cpu = Benchmark.realtime { @mod.compute(2).total }
40
+ two_cpu = Tiamat.open_remote(*@uris) {
41
+ Pure.worker.should eql(Tiamat::RemoteWorker)
42
+ Pure.worker.closed?.should eql(false)
43
+ Benchmark.realtime { @mod.compute.total }
44
+ }
45
+ (two_cpu/one_cpu).should be_close(0.5, epsilon)
46
+ Tiamat::RemoteWorker.closed?.should eql(true)
47
+ end
48
+ end
49
+
50
+ describe "without block" do
51
+ it "should connect to remote servers" do
52
+ one_cpu = Benchmark.realtime { @mod.compute(2).total }
53
+ Pure.worker = Tiamat.open_remote(*@uris)
54
+ begin
55
+ Pure.worker.should eql(Tiamat::RemoteWorker)
56
+ Pure.worker.closed?.should eql(false)
57
+ two_cpu = Benchmark.realtime { @mod.compute.total }
58
+ (two_cpu/one_cpu).should be_close(0.5, epsilon)
59
+ ensure
60
+ Pure.worker.close
61
+ Pure.worker = Pure::NativeWorker
62
+ end
63
+ Tiamat::RemoteWorker.closed?.should eql(true)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ require 'tiamat/tiamat_server'
4
+
5
+ describe Tiamat::TiamatServer do
6
+ before :all do
7
+ @server = Tiamat::TiamatServer.new(*Tiamat.compiler.reverse)
8
+ end
9
+
10
+ it "should evaluate a pure function spec" do
11
+ mod = pure do
12
+ def f
13
+ 33 + 44
14
+ end
15
+ end
16
+ spec = Pure::ExtractedFunctions[Pure.parser][mod][:f]
17
+ @server.evaluate_function(spec).should == 77
18
+ end
19
+
20
+ it "should handle `fun' definitions with no args" do
21
+ mod = pure do
22
+ fun :f do
23
+ 33 + 44
24
+ end
25
+ end
26
+ spec = Pure::ExtractedFunctions[Pure.parser][mod][:f]
27
+ @server.evaluate_function(spec).should == 77
28
+ end
29
+
30
+ it "should handle `fun' definitions with args" do
31
+ mod = pure do
32
+ fun :f => [:x, :y] do |u, v|
33
+ u*v
34
+ end
35
+ end
36
+ spec = Pure::ExtractedFunctions[Pure.parser][mod][:f]
37
+ @server.evaluate_function(spec, 4, 5).should == 20
38
+ end
39
+
40
+ it "should run" do
41
+ uri = "druby://localhost:27272"
42
+ thread = Thread.new {
43
+ Tiamat::TiamatServer.run(uri, *Tiamat.compiler.reverse)
44
+ }
45
+ Tiamat::Server.new(uri).instance_eval {
46
+ @drb_object.ping
47
+ @drb_object.close
48
+ }
49
+ thread.join
50
+ end
51
+ end
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../devel"
3
+
4
+ require 'pure/dsl'
5
+ require 'tiamat/autoconfig'
6
+ require 'spec/autorun'
7
+ require 'rbconfig'
8
+
9
+ module TiamatSpecBase
10
+ module_function
11
+
12
+ def slow_platform_epsilon
13
+ if RUBY_PLATFORM == "java" or Config::CONFIG["host"] =~ %r!mswin|mingw!
14
+ 99
15
+ else
16
+ 0
17
+ end
18
+ end
19
+
20
+ def with_env(hash)
21
+ previous_env = ENV.inject(Hash.new) { |acc, (key, value)|
22
+ acc.merge!(key => value)
23
+ }
24
+ hash.each_pair { |key, value|
25
+ ENV[key] = value
26
+ }
27
+ begin
28
+ yield
29
+ ensure
30
+ ENV.clear
31
+ previous_env.each_pair { |key, value|
32
+ ENV[key] = value
33
+ }
34
+ end
35
+ end
36
+ end
data/spec/util_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ # rcov hack
4
+ describe Tiamat::Util do
5
+ describe ".run_ruby" do
6
+ it "should pass rcov butchery" do
7
+ previous_host = Config::CONFIG["host"]
8
+ previous_verbose = $VERBOSE
9
+ $VERBOSE = nil
10
+ begin
11
+ Config::CONFIG["host"] = "mingw"
12
+ load File.dirname(__FILE__) + "/../lib/tiamat/util.rb"
13
+ lambda {
14
+ Tiamat::Util.run_ruby("-e", "")
15
+ }.should_not raise_error
16
+ ensure
17
+ Config::CONFIG["host"] = previous_host
18
+ load File.dirname(__FILE__) + "/../lib/tiamat/util.rb"
19
+ $VERBOSE = previous_verbose
20
+ end
21
+ end
22
+
23
+ it "should raise when it fails" do
24
+ lambda {
25
+ Tiamat::Util.run_ruby("-e", "exit 99")
26
+ }.should raise_error(Tiamat::RunRubyError, %r!failed with status 99!)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/tiamat_spec_base'
2
+
3
+ describe Tiamat::Worker do
4
+ it "should raise when open() called while open" do
5
+ count = 0
6
+ mock_farm = Class.new do
7
+ define_method :close do
8
+ count += 1
9
+ end
10
+ end.new
11
+ lambda {
12
+ Tiamat::Worker.open(mock_farm) do
13
+ Tiamat::Worker.open(mock_farm) do
14
+ end
15
+ end
16
+ }.should raise_error(Tiamat::AlreadyOpenError, %r!already open!)
17
+ count.should == 1
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiamat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James M. Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-22 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pure
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby_parser
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: ruby2ruby
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.4
44
+ version:
45
+ description: Tiamat is a worker plugin for the pure functional package (Pure[http://purefunctional. rubyforge.
46
+ email:
47
+ - quixoticsycophant@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ files:
55
+ - CHANGES.rdoc
56
+ - README.rdoc
57
+ - Rakefile
58
+ - bin/tiamat-server
59
+ - devel/jumpstart.rb
60
+ - install.rb
61
+ - lib/tiamat.rb
62
+ - lib/tiamat/autoconfig.rb
63
+ - lib/tiamat/child_server.rb
64
+ - lib/tiamat/config/ruby_parser.rb
65
+ - lib/tiamat/connector.rb
66
+ - lib/tiamat/error.rb
67
+ - lib/tiamat/farm.rb
68
+ - lib/tiamat/local_child_farm.rb
69
+ - lib/tiamat/local_child_server.rb
70
+ - lib/tiamat/local_child_worker.rb
71
+ - lib/tiamat/remote_farm.rb
72
+ - lib/tiamat/remote_worker.rb
73
+ - lib/tiamat/server.rb
74
+ - lib/tiamat/tiamat.rb
75
+ - lib/tiamat/tiamat_server.rb
76
+ - lib/tiamat/util.rb
77
+ - lib/tiamat/version.rb
78
+ - lib/tiamat/worker.rb
79
+ - spec/connector_spec.rb
80
+ - spec/drb_connection_spec.rb
81
+ - spec/local_child_farm_spec.rb
82
+ - spec/local_child_server_path_spec.rb
83
+ - spec/local_child_server_spec.rb
84
+ - spec/local_child_worker_spec.rb
85
+ - spec/pure_spec.rb
86
+ - spec/readme_spec.rb
87
+ - spec/remote_farm_spec.rb
88
+ - spec/remote_worker_spec.rb
89
+ - spec/server_spec.rb
90
+ - spec/tiamat_open_local_spec.rb
91
+ - spec/tiamat_open_remote_spec.rb
92
+ - spec/tiamat_server_spec.rb
93
+ - spec/tiamat_spec_base.rb
94
+ - spec/util_spec.rb
95
+ - spec/worker_spec.rb
96
+ - MANIFEST
97
+ has_rdoc: true
98
+ homepage: http://purefunctional.rubyforge.org
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --main
104
+ - README.rdoc
105
+ - --title
106
+ - "tiamat: Automatic parallelism across multiple cores and machines: a plugin for Pure."
107
+ - --exclude
108
+ - CHANGES.rdoc
109
+ - --exclude
110
+ - README.rdoc
111
+ - --exclude
112
+ - Rakefile
113
+ - --exclude
114
+ - bin/tiamat-server
115
+ - --exclude
116
+ - devel/jumpstart.rb
117
+ - --exclude
118
+ - install.rb
119
+ - --exclude
120
+ - lib/tiamat.rb
121
+ - --exclude
122
+ - lib/tiamat/child_server.rb
123
+ - --exclude
124
+ - lib/tiamat/config/ruby_parser.rb
125
+ - --exclude
126
+ - lib/tiamat/connector.rb
127
+ - --exclude
128
+ - lib/tiamat/error.rb
129
+ - --exclude
130
+ - lib/tiamat/farm.rb
131
+ - --exclude
132
+ - lib/tiamat/local_child_farm.rb
133
+ - --exclude
134
+ - lib/tiamat/local_child_server.rb
135
+ - --exclude
136
+ - lib/tiamat/local_child_worker.rb
137
+ - --exclude
138
+ - lib/tiamat/remote_farm.rb
139
+ - --exclude
140
+ - lib/tiamat/remote_worker.rb
141
+ - --exclude
142
+ - lib/tiamat/server.rb
143
+ - --exclude
144
+ - lib/tiamat/tiamat_server.rb
145
+ - --exclude
146
+ - lib/tiamat/util.rb
147
+ - --exclude
148
+ - lib/tiamat/version.rb
149
+ - --exclude
150
+ - lib/tiamat/worker.rb
151
+ - --exclude
152
+ - spec/connector_spec.rb
153
+ - --exclude
154
+ - spec/drb_connection_spec.rb
155
+ - --exclude
156
+ - spec/local_child_farm_spec.rb
157
+ - --exclude
158
+ - spec/local_child_server_path_spec.rb
159
+ - --exclude
160
+ - spec/local_child_server_spec.rb
161
+ - --exclude
162
+ - spec/local_child_worker_spec.rb
163
+ - --exclude
164
+ - spec/pure_spec.rb
165
+ - --exclude
166
+ - spec/readme_spec.rb
167
+ - --exclude
168
+ - spec/remote_farm_spec.rb
169
+ - --exclude
170
+ - spec/remote_worker_spec.rb
171
+ - --exclude
172
+ - spec/server_spec.rb
173
+ - --exclude
174
+ - spec/tiamat_open_local_spec.rb
175
+ - --exclude
176
+ - spec/tiamat_open_remote_spec.rb
177
+ - --exclude
178
+ - spec/tiamat_server_spec.rb
179
+ - --exclude
180
+ - spec/tiamat_spec_base.rb
181
+ - --exclude
182
+ - spec/util_spec.rb
183
+ - --exclude
184
+ - spec/worker_spec.rb
185
+ - --exclude
186
+ - MANIFEST
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: "0"
194
+ version:
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: "0"
200
+ version:
201
+ requirements: []
202
+
203
+ rubyforge_project: tiamat
204
+ rubygems_version: 1.3.5
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: "Automatic parallelism across multiple cores and machines: a plugin for Pure."
208
+ test_files: []
209
+