parallel 1.22.1 → 1.24.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 +4 -4
- data/lib/parallel/version.rb +1 -1
- data/lib/parallel.rb +68 -4
- metadata +4 -5
- data/lib/parallel/processor_count.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b4a5662ef68724c75c2d655d9bd09ad109edc02d3199a0744093544608f74b
|
4
|
+
data.tar.gz: 247f7f3745c42cdafeb5d403fff250e99b99a56d4dc4948050dcf20ecb60d183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f62ea9fefb30bda9b89f0189074da99572c5c17fb93ba28e553b0eb9f6d7a61bd70ba423004b138b05c3c86f8e04fd32fce81da40a68c0bdca39e263b8b892
|
7
|
+
data.tar.gz: dca61c9e3cab22de0ad064c96c55afc88177214108d6bdbfb8e9a93343f23d6ee321c83aa6c4cfa9ee33da79d01802d7b952f3dd0360f9cca26e5da78a4117fa
|
data/lib/parallel/version.rb
CHANGED
data/lib/parallel.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'rbconfig'
|
3
3
|
require 'parallel/version'
|
4
|
-
require 'parallel/processor_count'
|
5
4
|
|
6
5
|
module Parallel
|
7
|
-
extend ProcessorCount
|
8
|
-
|
9
6
|
Stop = Object.new.freeze
|
10
7
|
|
11
8
|
class DeadWorker < StandardError
|
@@ -307,6 +304,49 @@ module Parallel
|
|
307
304
|
map(*args, &block).flatten(1)
|
308
305
|
end
|
309
306
|
|
307
|
+
def filter_map(*args, &block)
|
308
|
+
map(*args, &block).compact
|
309
|
+
end
|
310
|
+
|
311
|
+
# Number of physical processor cores on the current system.
|
312
|
+
def physical_processor_count
|
313
|
+
@physical_processor_count ||= begin
|
314
|
+
ppc =
|
315
|
+
case RbConfig::CONFIG["target_os"]
|
316
|
+
when /darwin[12]/
|
317
|
+
IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
|
318
|
+
when /linux/
|
319
|
+
cores = {} # unique physical ID / core ID combinations
|
320
|
+
phy = 0
|
321
|
+
File.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
|
322
|
+
if ln.start_with?("physical")
|
323
|
+
phy = ln[/\d+/]
|
324
|
+
elsif ln.start_with?("core")
|
325
|
+
cid = "#{phy}:#{ln[/\d+/]}"
|
326
|
+
cores[cid] = true unless cores[cid]
|
327
|
+
end
|
328
|
+
end
|
329
|
+
cores.count
|
330
|
+
when /mswin|mingw/
|
331
|
+
require 'win32ole'
|
332
|
+
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
333
|
+
"select NumberOfCores from Win32_Processor"
|
334
|
+
)
|
335
|
+
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
336
|
+
else
|
337
|
+
processor_count
|
338
|
+
end
|
339
|
+
# fall back to logical count if physical info is invalid
|
340
|
+
ppc > 0 ? ppc : processor_count
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
# Number of processors seen by the OS, used for process scheduling
|
345
|
+
def processor_count
|
346
|
+
require 'etc'
|
347
|
+
@processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
|
348
|
+
end
|
349
|
+
|
310
350
|
def worker_number
|
311
351
|
Thread.current[:parallel_worker_number]
|
312
352
|
end
|
@@ -600,10 +640,34 @@ module Parallel
|
|
600
640
|
end
|
601
641
|
|
602
642
|
def instrument_finish(item, index, result, options)
|
603
|
-
return unless on_finish = options[:finish]
|
643
|
+
return unless (on_finish = options[:finish])
|
644
|
+
return instrument_finish_in_order(item, index, result, options) if options[:finish_in_order]
|
604
645
|
options[:mutex].synchronize { on_finish.call(item, index, result) }
|
605
646
|
end
|
606
647
|
|
648
|
+
# yield results in the order of the input items
|
649
|
+
# needs to use `options` to store state between executions
|
650
|
+
# needs to use `done` index since a nil result would also be valid
|
651
|
+
def instrument_finish_in_order(item, index, result, options)
|
652
|
+
options[:mutex].synchronize do
|
653
|
+
# initialize our state
|
654
|
+
options[:finish_done] ||= []
|
655
|
+
options[:finish_expecting] ||= 0 # we wait for item at index 0
|
656
|
+
|
657
|
+
# store current result
|
658
|
+
options[:finish_done][index] = [item, result]
|
659
|
+
|
660
|
+
# yield all results that are now in order
|
661
|
+
break unless index == options[:finish_expecting]
|
662
|
+
index.upto(options[:finish_done].size).each do |i|
|
663
|
+
break unless (done = options[:finish_done][i])
|
664
|
+
options[:finish_done][i] = nil # allow GC to free this item and result
|
665
|
+
options[:finish].call(done[0], i, done[1])
|
666
|
+
options[:finish_expecting] += 1
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
607
671
|
def instrument_start(item, index, options)
|
608
672
|
return unless on_start = options[:start]
|
609
673
|
options[:mutex].synchronize { on_start.call(item, index) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -18,15 +18,14 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- MIT-LICENSE.txt
|
20
20
|
- lib/parallel.rb
|
21
|
-
- lib/parallel/processor_count.rb
|
22
21
|
- lib/parallel/version.rb
|
23
22
|
homepage: https://github.com/grosser/parallel
|
24
23
|
licenses:
|
25
24
|
- MIT
|
26
25
|
metadata:
|
27
26
|
bug_tracker_uri: https://github.com/grosser/parallel/issues
|
28
|
-
documentation_uri: https://github.com/grosser/parallel/blob/v1.
|
29
|
-
source_code_uri: https://github.com/grosser/parallel/tree/v1.
|
27
|
+
documentation_uri: https://github.com/grosser/parallel/blob/v1.24.0/Readme.md
|
28
|
+
source_code_uri: https://github.com/grosser/parallel/tree/v1.24.0
|
30
29
|
wiki_uri: https://github.com/grosser/parallel/wiki
|
31
30
|
post_install_message:
|
32
31
|
rdoc_options: []
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Parallel
|
3
|
-
# TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
|
4
|
-
module ProcessorCount
|
5
|
-
# Number of processors seen by the OS, used for process scheduling
|
6
|
-
def processor_count
|
7
|
-
require 'etc'
|
8
|
-
@processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Number of physical processor cores on the current system.
|
12
|
-
def physical_processor_count
|
13
|
-
@physical_processor_count ||= begin
|
14
|
-
ppc =
|
15
|
-
case RbConfig::CONFIG["target_os"]
|
16
|
-
when /darwin[12]/
|
17
|
-
IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
|
18
|
-
when /linux/
|
19
|
-
cores = {} # unique physical ID / core ID combinations
|
20
|
-
phy = 0
|
21
|
-
File.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
|
22
|
-
if ln.start_with?("physical")
|
23
|
-
phy = ln[/\d+/]
|
24
|
-
elsif ln.start_with?("core")
|
25
|
-
cid = "#{phy}:#{ln[/\d+/]}"
|
26
|
-
cores[cid] = true unless cores[cid]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
cores.count
|
30
|
-
when /mswin|mingw/
|
31
|
-
require 'win32ole'
|
32
|
-
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
33
|
-
"select NumberOfCores from Win32_Processor"
|
34
|
-
)
|
35
|
-
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
36
|
-
else
|
37
|
-
processor_count
|
38
|
-
end
|
39
|
-
# fall back to logical count if physical info is invalid
|
40
|
-
ppc > 0 ? ppc : processor_count
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|