forked from taiki45/mecab-ext
-
Notifications
You must be signed in to change notification settings - Fork 2
/
parallel_make.rb
39 lines (37 loc) · 1.42 KB
/
parallel_make.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# from: https://github.com/grosser/parallel/blob/master/lib/parallel.rb
def processor_count
os_name = RbConfig::CONFIG["target_os"]
if os_name =~ /mingw|mswin/
require 'win32ole'
result = WIN32OLE.connect("winmgmts://").
ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
elsif File.readable?("/proc/cpuinfo")
IO.read("/proc/cpuinfo").scan(/^processor/).size
elsif File.executable?("/usr/bin/hwprefs")
IO.popen("/usr/bin/hwprefs thread_count").read.to_i
elsif File.executable?("/usr/sbin/psrinfo")
IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
elsif File.executable?("/usr/sbin/ioscan")
IO.popen("/usr/sbin/ioscan -kC processor") do |out|
out.read.scan(/^.*processor/).size
end
elsif File.executable?("/usr/sbin/pmcycles")
IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
elsif File.executable?("/usr/sbin/lsdev")
IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
elsif File.executable?("/usr/sbin/sysctl")
IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
elsif File.executable?("/sbin/sysctl")
IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
else
1
end
end
class MiniPortile
def make_cmd
"make -j#{processor_count+1}"
end
end