parallel 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4335cc7d93938d3aafdb07fee7a4aa32e7b586c7
4
- data.tar.gz: 718327edc760a05b8d8502ed1afdb334a1fb1ef1
3
+ metadata.gz: f6ea4deb03b39b10b4efc968f86c86d8fba2c42f
4
+ data.tar.gz: b32876b86f9acc449bb45d28b154708f9af0dee1
5
5
  SHA512:
6
- metadata.gz: 1d4c4d72297c1e8e0da33d05e111d7eb32e58c0f7d759329abd1c5f9a90c17711bf23202f75ad647414194284747b8d493073a11cc024e4351633a743526f6aa
7
- data.tar.gz: 2dc97cc4d85eb122faa0cdade2de92d5889a14eed7fe08527c4cc3562d5fc8c2ae7571842a3c44bfc69fdb726aab5e19a90102a164a7884de93ac0291558df46
6
+ metadata.gz: 92021663b44c16d0ce0f9dfa0c616f3852f9e2a6f7c85521c06283f2fd5daad75f7dbf95703241c926b71eb98a44619eefdcc62d3039e4311d8ba4389fb06649
7
+ data.tar.gz: c48fdaebf240f24722a41868688e0373349f78eb1de8e9329cdd0e458cdaf0458e1cbc6cbbfd4f3b5707c5363706e4755ed66c543332c03b39b2be909ccd0132
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ]��� a��FmS%�Mϓh���u���M�m���BE��#��&.X��S�ၓ38aa�J~�>�巣�����=���nD;{EhMzsp�R��; ���:�C�^Gώ����Y��&2��H4�~����"e�݈���O��1�ɖPtR
2
- �!��$d�-�B��<�L� "�ȗ�Z{�c���ԃ�~�F/�'t"�brM�h��.9�k-5"o�� �a�|�kt\#9�xt�4�_е�����*�qI/�F
1
+ ����jVz �W—��~~u7�)�&W�K�e� �����NO��4T(M�G������㕥�Y̔3�U)���̺�F�Sjh�5s�iϑb0��E�ݏ�6�ٙϝr8n~�Ԕ�2�ɰM��Vyy��2LT�ހH5�`�;b��D3���g*&��;m����/����?\�.��� 8Oڕ��<��FB@r�>Lߞ�Ϧ�f�`5?ӺJ-`|át&�7MXk�����&F���)u�
@@ -1,8 +1,11 @@
1
1
  require 'thread' # to get Thread.exclusive
2
2
  require 'rbconfig'
3
3
  require 'parallel/version'
4
+ require 'parallel/processor_count'
4
5
 
5
6
  module Parallel
7
+ extend Parallel::ProcessorCount
8
+
6
9
  class DeadWorker < StandardError
7
10
  end
8
11
 
@@ -84,7 +87,7 @@ module Parallel
84
87
  end
85
88
 
86
89
  def each(array, options={}, &block)
87
- map(array, options.merge(:preserve_results => !!options[:finish]), &block)
90
+ map(array, options.merge(:preserve_results => false), &block)
88
91
  array
89
92
  end
90
93
 
@@ -113,6 +116,7 @@ module Parallel
113
116
  end
114
117
  size = [array.size, size].min
115
118
 
119
+ options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
116
120
  add_progress_bar!(array, options)
117
121
 
118
122
  if size == 0
@@ -144,88 +148,6 @@ module Parallel
144
148
  map(array, options.merge(:with_index => true), &block)
145
149
  end
146
150
 
147
- # Number of processors seen by the OS and used for process scheduling.
148
- #
149
- # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
150
- # * BSD: /sbin/sysctl
151
- # * Cygwin: /proc/cpuinfo
152
- # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
153
- # * HP-UX: /usr/sbin/ioscan
154
- # * IRIX: /usr/sbin/sysconf
155
- # * Linux: /proc/cpuinfo
156
- # * Minix 3+: /proc/cpuinfo
157
- # * Solaris: /usr/sbin/psrinfo
158
- # * Tru64 UNIX: /usr/sbin/psrinfo
159
- # * UnixWare: /usr/sbin/psrinfo
160
- #
161
- def processor_count
162
- @processor_count ||= begin
163
- os_name = RbConfig::CONFIG["target_os"]
164
- if os_name =~ /mingw|mswin/
165
- require 'win32ole'
166
- result = WIN32OLE.connect("winmgmts://").ExecQuery(
167
- "select NumberOfLogicalProcessors from Win32_Processor")
168
- result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
169
- elsif File.readable?("/proc/cpuinfo")
170
- IO.read("/proc/cpuinfo").scan(/^processor/).size
171
- elsif File.executable?("/usr/bin/hwprefs")
172
- IO.popen("/usr/bin/hwprefs thread_count").read.to_i
173
- elsif File.executable?("/usr/sbin/psrinfo")
174
- IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
175
- elsif File.executable?("/usr/sbin/ioscan")
176
- IO.popen("/usr/sbin/ioscan -kC processor") do |out|
177
- out.read.scan(/^.*processor/).size
178
- end
179
- elsif File.executable?("/usr/sbin/pmcycles")
180
- IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
181
- elsif File.executable?("/usr/sbin/lsdev")
182
- IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
183
- elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
184
- IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
185
- elsif File.executable?("/usr/sbin/sysctl")
186
- IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
187
- elsif File.executable?("/sbin/sysctl")
188
- IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
189
- else
190
- $stderr.puts "Unknown platform: " + RbConfig::CONFIG["target_os"]
191
- $stderr.puts "Assuming 1 processor."
192
- 1
193
- end
194
- end
195
- end
196
-
197
- # Number of physical processor cores on the current system.
198
- #
199
- def physical_processor_count
200
- @physical_processor_count ||= begin
201
- ppc = case RbConfig::CONFIG["target_os"]
202
- when /darwin1/
203
- IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
204
- when /linux/
205
- cores = {} # unique physical ID / core ID combinations
206
- phy = 0
207
- IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
208
- if ln.start_with?("physical")
209
- phy = ln[/\d+/]
210
- elsif ln.start_with?("core")
211
- cid = phy + ":" + ln[/\d+/]
212
- cores[cid] = true if not cores[cid]
213
- end
214
- end
215
- cores.count
216
- when /mswin|mingw/
217
- require 'win32ole'
218
- result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
219
- "select NumberOfCores from Win32_Processor")
220
- result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
221
- else
222
- processor_count
223
- end
224
- # fall back to logical count if physical info is invalid
225
- ppc > 0 ? ppc : processor_count
226
- end
227
- end
228
-
229
151
  private
230
152
 
231
153
  def work_direct(array, options)
@@ -249,13 +171,13 @@ module Parallel
249
171
  index = Thread.exclusive { current += 1 }
250
172
  break if index >= items.size
251
173
 
252
- with_instrumentation items[index], index, options do
253
- begin
254
- results[index] = call_with_index(items, index, options, &block)
255
- rescue StandardError => e
256
- exception = e
257
- break
174
+ begin
175
+ results[index] = with_instrumentation items[index], index, options do
176
+ call_with_index(items, index, options, &block)
258
177
  end
178
+ rescue StandardError => e
179
+ exception = e
180
+ break
259
181
  end
260
182
  end
261
183
  end
@@ -436,11 +358,11 @@ module Parallel
436
358
  def call_with_index(array, index, options, &block)
437
359
  args = [array[index]]
438
360
  args << index if options[:with_index]
439
- if options[:preserve_results] == false
361
+ if options[:return_results]
440
362
  block.call(*args)
441
- nil # avoid GC overhead of passing large results around
442
363
  else
443
364
  block.call(*args)
365
+ nil # avoid GC overhead of passing large results around
444
366
  end
445
367
  end
446
368
 
@@ -449,6 +371,7 @@ module Parallel
449
371
  on_finish = options[:finish]
450
372
  options[:mutex].synchronize { on_start.call(item, index) } if on_start
451
373
  result = yield
374
+ result unless options[:preserve_results] == false
452
375
  ensure
453
376
  options[:mutex].synchronize { on_finish.call(item, index, result) } if on_finish
454
377
  end
@@ -0,0 +1,85 @@
1
+ module Parallel
2
+ module ProcessorCount
3
+ # Number of processors seen by the OS and used for process scheduling.
4
+ #
5
+ # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
6
+ # * BSD: /sbin/sysctl
7
+ # * Cygwin: /proc/cpuinfo
8
+ # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
9
+ # * HP-UX: /usr/sbin/ioscan
10
+ # * IRIX: /usr/sbin/sysconf
11
+ # * Linux: /proc/cpuinfo
12
+ # * Minix 3+: /proc/cpuinfo
13
+ # * Solaris: /usr/sbin/psrinfo
14
+ # * Tru64 UNIX: /usr/sbin/psrinfo
15
+ # * UnixWare: /usr/sbin/psrinfo
16
+ #
17
+ def processor_count
18
+ @processor_count ||= begin
19
+ os_name = RbConfig::CONFIG["target_os"]
20
+ if os_name =~ /mingw|mswin/
21
+ require 'win32ole'
22
+ result = WIN32OLE.connect("winmgmts://").ExecQuery(
23
+ "select NumberOfLogicalProcessors from Win32_Processor")
24
+ result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
25
+ elsif File.readable?("/proc/cpuinfo")
26
+ IO.read("/proc/cpuinfo").scan(/^processor/).size
27
+ elsif File.executable?("/usr/bin/hwprefs")
28
+ IO.popen("/usr/bin/hwprefs thread_count").read.to_i
29
+ elsif File.executable?("/usr/sbin/psrinfo")
30
+ IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
31
+ elsif File.executable?("/usr/sbin/ioscan")
32
+ IO.popen("/usr/sbin/ioscan -kC processor") do |out|
33
+ out.read.scan(/^.*processor/).size
34
+ end
35
+ elsif File.executable?("/usr/sbin/pmcycles")
36
+ IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
37
+ elsif File.executable?("/usr/sbin/lsdev")
38
+ IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
39
+ elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
40
+ IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
41
+ elsif File.executable?("/usr/sbin/sysctl")
42
+ IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
43
+ elsif File.executable?("/sbin/sysctl")
44
+ IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
45
+ else
46
+ $stderr.puts "Unknown platform: " + RbConfig::CONFIG["target_os"]
47
+ $stderr.puts "Assuming 1 processor."
48
+ 1
49
+ end
50
+ end
51
+ end
52
+
53
+ # Number of physical processor cores on the current system.
54
+ #
55
+ def physical_processor_count
56
+ @physical_processor_count ||= begin
57
+ ppc = case RbConfig::CONFIG["target_os"]
58
+ when /darwin1/
59
+ IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
60
+ when /linux/
61
+ cores = {} # unique physical ID / core ID combinations
62
+ phy = 0
63
+ IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
64
+ if ln.start_with?("physical")
65
+ phy = ln[/\d+/]
66
+ elsif ln.start_with?("core")
67
+ cid = phy + ":" + ln[/\d+/]
68
+ cores[cid] = true if not cores[cid]
69
+ end
70
+ end
71
+ cores.count
72
+ when /mswin|mingw/
73
+ require 'win32ole'
74
+ result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
75
+ "select NumberOfCores from Win32_Processor")
76
+ result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
77
+ else
78
+ processor_count
79
+ end
80
+ # fall back to logical count if physical info is invalid
81
+ ppc > 0 ? ppc : processor_count
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module Parallel
2
- VERSION = Version = '1.2.3'
2
+ VERSION = Version = '1.2.4'
3
3
  end
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: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -40,6 +40,7 @@ extra_rdoc_files: []
40
40
  files:
41
41
  - MIT-LICENSE.txt
42
42
  - lib/parallel.rb
43
+ - lib/parallel/processor_count.rb
43
44
  - lib/parallel/version.rb
44
45
  homepage: https://github.com/grosser/parallel
45
46
  licenses:
metadata.gz.sig CHANGED
Binary file