parallel 1.22.0 → 1.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parallel/version.rb +1 -1
- data/lib/parallel.rb +43 -3
- metadata +9 -10
- data/lib/parallel/processor_count.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b8bb887652e89a339de17f31e8482aec8664426b2b12eb11566779f53153a56
|
4
|
+
data.tar.gz: e5fa1401f5748de7216a6d973d1ca1a2af514caeaec1dacafb153d2a5538334d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 481a4b04da349a2eb88cdcab724dc3c47efe757dcb61889a3105d0097fb3255ff6283470f6c2bc636c1bd053e274516fddfa33f8d362e8208f6f57638864ca48
|
7
|
+
data.tar.gz: 9093769c22e258cb921c1ab6ead1c7083fcc1d315b7bc268dff807c0fe1c4468b4316171e5f837283d7387ecdb01284f55763b60912c4bce7548aa9c869cc57b
|
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
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: michael@grosser.it
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -18,17 +18,16 @@ 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.23.0/Readme.md
|
28
|
+
source_code_uri: https://github.com/grosser/parallel/tree/v1.23.0
|
30
29
|
wiki_uri: https://github.com/grosser/parallel/wiki
|
31
|
-
post_install_message:
|
30
|
+
post_install_message:
|
32
31
|
rdoc_options: []
|
33
32
|
require_paths:
|
34
33
|
- lib
|
@@ -43,8 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: '0'
|
45
44
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
45
|
+
rubygems_version: 3.1.6
|
46
|
+
signing_key:
|
48
47
|
specification_version: 4
|
49
48
|
summary: Run any kind of code in parallel processes
|
50
49
|
test_files: []
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'etc'
|
3
|
-
|
4
|
-
module Parallel
|
5
|
-
# TODO: inline this method into parallel.rb and kill physical_processor_count in next major release
|
6
|
-
module ProcessorCount
|
7
|
-
# Number of processors seen by the OS, used for process scheduling
|
8
|
-
def processor_count
|
9
|
-
@processor_count ||= Integer(ENV['PARALLEL_PROCESSOR_COUNT'] || Etc.nprocessors)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Number of physical processor cores on the current system.
|
13
|
-
def physical_processor_count
|
14
|
-
@physical_processor_count ||= begin
|
15
|
-
ppc =
|
16
|
-
case RbConfig::CONFIG["target_os"]
|
17
|
-
when /darwin[12]/
|
18
|
-
IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
|
19
|
-
when /linux/
|
20
|
-
cores = {} # unique physical ID / core ID combinations
|
21
|
-
phy = 0
|
22
|
-
File.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
|
23
|
-
if ln.start_with?("physical")
|
24
|
-
phy = ln[/\d+/]
|
25
|
-
elsif ln.start_with?("core")
|
26
|
-
cid = "#{phy}:#{ln[/\d+/]}"
|
27
|
-
cores[cid] = true unless cores[cid]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
cores.count
|
31
|
-
when /mswin|mingw/
|
32
|
-
require 'win32ole'
|
33
|
-
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
34
|
-
"select NumberOfCores from Win32_Processor"
|
35
|
-
)
|
36
|
-
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
37
|
-
else
|
38
|
-
processor_count
|
39
|
-
end
|
40
|
-
# fall back to logical count if physical info is invalid
|
41
|
-
ppc > 0 ? ppc : processor_count
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|