parallel 0.8.4 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dfa83f77faeb4b7a88c8fe48f4c4c761a698a79
4
- data.tar.gz: b671b7078d94652f32c4d3926389ae49a8757ec2
3
+ metadata.gz: 6c50a58c0a8fadc833892eba309cad741926e435
4
+ data.tar.gz: 54c53c532e86976aa6e478a16a74216793929669
5
5
  SHA512:
6
- metadata.gz: d2cf2bef92031948c03f45f6fae48637f16042ed84eaf97aa88894ac35e1db35fcd8e4e12b43819efdf8a9fccfc3af4aa23329808ac174935c8184a349ee1660
7
- data.tar.gz: 5baf3578ead853ac7643d176ffcfd38e9f73a3c96c622e2af14517f0dbad756e85ae2b62b45582b9be32fae9d1c4e3c9309dfb2bf93fc546a15178baedf6adae
6
+ metadata.gz: 8cde8af228e3aa3b16be2d510de4332e61e6c569dd3dd927b8c87640b625fc8416962d9344a83e408578de14d5370d4b9b4c043a2e165cf395d9835be4c0f7e1
7
+ data.tar.gz: 342c63a9672f02c3b46cb30fffb72f646a98d49f3041611a128139a4ea4333b0c0143e2f0340577cec576a4b779fdd5aafcb58ec738078bd919b62506917fdb7
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ����[ő6£�&�ɠ�
data.tar.gz.sig ADDED
Binary file
data/lib/parallel.rb CHANGED
@@ -48,7 +48,7 @@ module Parallel
48
48
  begin
49
49
  Marshal.load(read)
50
50
  rescue EOFError
51
- raise Parallel::DeadWorker
51
+ raise DeadWorker
52
52
  end
53
53
  end
54
54
  end
@@ -89,18 +89,26 @@ module Parallel
89
89
  def map(array, options = {}, &block)
90
90
  array = array.to_a # turn Range and other Enumerable-s into an Array
91
91
 
92
- if options[:in_threads]
92
+ if RUBY_PLATFORM =~ /java/ and not options[:in_processes]
93
+ method = :in_threads
94
+ size = options[method] || processor_count
95
+ elsif options[:in_threads]
93
96
  method = :in_threads
94
97
  size = options[method]
95
98
  else
96
99
  method = :in_processes
97
- size = options[method] || processor_count
100
+ if Process.respond_to?(:fork)
101
+ size = options[method] || processor_count
102
+ else
103
+ $stderr.puts "Warning: Process.fork is not supported by this Ruby"
104
+ size = 0
105
+ end
98
106
  end
99
107
  size = [array.size, size].min
100
108
 
101
- return work_direct(array, options, &block) if size == 0
102
-
103
- if method == :in_threads
109
+ if size == 0
110
+ work_direct(array, options, &block)
111
+ elsif method == :in_threads
104
112
  work_in_threads(array, options.merge(:count => size), &block)
105
113
  else
106
114
  work_in_processes(array, options.merge(:count => size), &block)
@@ -111,43 +119,80 @@ module Parallel
111
119
  map(array, options.merge(:with_index => true), &block)
112
120
  end
113
121
 
122
+ # Number of processors seen by the OS and used for process scheduling.
123
+ #
124
+ # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
125
+ # * BSD: /sbin/sysctl
126
+ # * Cygwin: /proc/cpuinfo
127
+ # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
128
+ # * HP-UX: /usr/sbin/ioscan
129
+ # * IRIX: /usr/sbin/sysconf
130
+ # * Linux: /proc/cpuinfo
131
+ # * Minix 3+: /proc/cpuinfo
132
+ # * Solaris: /usr/sbin/psrinfo
133
+ # * Tru64 UNIX: /usr/sbin/psrinfo
134
+ # * UnixWare: /usr/sbin/psrinfo
135
+ #
114
136
  def processor_count
115
- @processor_count ||= case RbConfig::CONFIG['host_os']
116
- when /darwin9/
117
- `hwprefs cpu_count`.to_i
118
- when /darwin/
119
- (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
120
- when /linux|cygwin/
121
- `grep -c ^processor /proc/cpuinfo`.to_i
122
- when /(net|open|free)bsd/
123
- `sysctl -n hw.ncpu`.to_i
124
- when /mswin|mingw/
125
- require 'win32ole'
126
- wmi = WIN32OLE.connect("winmgmts://")
127
- cpu = wmi.ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
128
- cpu.to_enum.first.NumberOfLogicalProcessors
129
- when /solaris2/
130
- `psrinfo -p`.to_i # this is physical cpus afaik
131
- else
132
- $stderr.puts "Unknown architecture ( #{RbConfig::CONFIG["host_os"]} ) assuming one processor."
133
- 1
137
+ @processor_count ||= begin
138
+ os_name = RbConfig::CONFIG["target_os"]
139
+ if os_name =~ /mingw|mswin/
140
+ require 'win32ole'
141
+ result = WIN32OLE.connect("winmgmts://").ExecQuery(
142
+ "select NumberOfLogicalProcessors from Win32_Processor")
143
+ result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
144
+ elsif File.readable?("/proc/cpuinfo")
145
+ IO.read("/proc/cpuinfo").scan(/^processor/).size
146
+ elsif File.executable?("/usr/bin/hwprefs")
147
+ IO.popen(%w[/usr/bin/hwprefs thread_count]).read.to_i
148
+ elsif File.executable?("/usr/sbin/psrinfo")
149
+ IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
150
+ elsif File.executable?("/usr/sbin/ioscan")
151
+ IO.popen(%w[/usr/sbin/ioscan -kC processor]) do |out|
152
+ out.read.scan(/^.*processor/).size
153
+ end
154
+ elsif File.executable?("/usr/sbin/pmcycles")
155
+ IO.popen(%w[/usr/sbin/pmcycles -m]).read.count("\n")
156
+ elsif File.executable?("/usr/sbin/lsdev")
157
+ IO.popen(%w[/usr/sbin/lsdev -Cc processor -S 1]).read.count("\n")
158
+ elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
159
+ IO.popen(%w[/usr/sbin/sysconf NPROC_ONLN]).read.to_i
160
+ elsif File.executable?("/usr/sbin/sysctl")
161
+ IO.popen(%w[/usr/sbin/sysctl -n hw.ncpu]).read.to_i
162
+ elsif File.executable?("/sbin/sysctl")
163
+ IO.popen(%w[/sbin/sysctl -n hw.ncpu]).read.to_i
164
+ else
165
+ $stderr.puts "Unknown platform: " + RbConfig::CONFIG["target_os"]
166
+ $stderr.puts "Assuming 1 processor."
167
+ 1
168
+ end
134
169
  end
135
170
  end
136
171
 
172
+ # Number of physical processor cores on the current system.
173
+ #
137
174
  def physical_processor_count
138
175
  @physical_processor_count ||= begin
139
- ppc = case RbConfig::CONFIG['host_os']
176
+ ppc = case RbConfig::CONFIG["target_os"]
140
177
  when /darwin1/
141
- `sysctl -n hw.physicalcpu`.to_i
178
+ IO.popen(%w[/usr/sbin/sysctl -n hw.physicalcpu]).read.to_i
142
179
  when /linux/
143
- cores_per_physical = `grep cores /proc/cpuinfo`[/\d+/].to_i
144
- physicals = `grep 'physical id' /proc/cpuinfo |sort|uniq|wc -l`.to_i
145
- physicals * cores_per_physical
180
+ cores = {} # unique physical ID / core ID combinations
181
+ phy = 0
182
+ IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
183
+ if ln.start_with?("physical")
184
+ phy = ln[/\d+/]
185
+ elsif ln.start_with?("core")
186
+ cid = phy + ":" + ln[/\d+/]
187
+ cores[cid] = true if not cores[cid]
188
+ end
189
+ end
190
+ cores.count
146
191
  when /mswin|mingw/
147
192
  require 'win32ole'
148
- wmi = WIN32OLE.connect("winmgmts://")
149
- cpu = wmi.ExecQuery("select NumberOfProcessors from Win32_Processor")
150
- cpu.to_enum.first.NumberOfProcessors
193
+ result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
194
+ "select NumberOfCores from Win32_Processor")
195
+ result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
151
196
  else
152
197
  processor_count
153
198
  end
@@ -166,10 +211,6 @@ module Parallel
166
211
  results
167
212
  end
168
213
 
169
- def hwprefs_available?
170
- `which hwprefs` != ''
171
- end
172
-
173
214
  def work_in_threads(items, options, &block)
174
215
  results = []
175
216
  current = -1
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '0.8.4'
2
+ VERSION = Version = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2013-09-26 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
14
+ YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
15
+ MB4XDTEzMDIwMzE4MTMxMVoXDTE0MDIwMzE4MTMxMVowPzEQMA4GA1UEAwwHbWlj
16
+ aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
17
+ dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
18
+ MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
19
+ cPLaZbjUjljJ3cQR3B8Yn1veV5IhG86QseTBjymzJWsLpqJ1UZGpfB9tXcsFtuxO
20
+ 6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
21
+ h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
22
+ FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJxE38z/DRsd9R
23
+ /88CAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUsiNnXHtKeMYYcr4yJVmQ
24
+ WONL+IwwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAlyN7kKo/NQCQ0
25
+ AOzZLZ3WAePvStkCFIJ53tsv5Kyo4pMAllv+BgPzzBt7qi605mFSL6zBd9uLou+W
26
+ Co3s48p1dy7CjjAfVQdmVNHF3MwXtfC2OEyvSQPi4xKR8iba8wa3xp9LVo1PuLpw
27
+ /6DsrChWw74HfsJN6qJOK684hJeT8lBYAUfiC3wD0owoPSg+XtyAAddisR+KV5Y1
28
+ NmVHuLtQcNTZy+gRht3ahJRMuC6QyLmkTsf+6MaenwAMkAgHdswGsJztOnNnBa3F
29
+ y0kCSWmK6D+x/SbfS6r7Ke07MRqziJdB9GuE1+0cIRuFh8EQ+LN6HXCKM5pon/GU
30
+ ycwMXfl0
31
+ -----END CERTIFICATE-----
32
+ date: 2013-10-16 00:00:00.000000000 Z
12
33
  dependencies: []
13
34
  description:
14
35
  email: michael@grosser.it
metadata.gz.sig ADDED
Binary file