parallel: CPU detection code for AIX thanks to Christian Netrwal.

This commit is contained in:
Ole Tange 2011-04-18 11:37:34 +02:00
parent bc0f875e86
commit 3ab1fc535c
5 changed files with 32 additions and 17 deletions

View file

@ -165,6 +165,8 @@ New in this release:
? Part of Debian? ? Part of Debian?
? Part of Ubuntu? ? Part of Ubuntu?
* CPU detection code for AIX thanks to Christian Netrwal.
* Thanks to Ævar Arnfjörð Bjarmason for reading my code. * Thanks to Ævar Arnfjörð Bjarmason for reading my code.
* GNU Parallel was presented at: * GNU Parallel was presented at:

View file

@ -2207,6 +2207,7 @@ sub no_of_cores {
sub no_of_cpus_gnu_linux { sub no_of_cpus_gnu_linux {
# Returns: # Returns:
# Number of physical CPUs on GNU/Linux # Number of physical CPUs on GNU/Linux
# undef if not GNU/Linux
my $no_of_cpus; my $no_of_cpus;
if(-e "/proc/cpuinfo") { if(-e "/proc/cpuinfo") {
$no_of_cpus = 0; $no_of_cpus = 0;
@ -2225,6 +2226,7 @@ sub no_of_cpus_gnu_linux {
sub no_of_cores_gnu_linux { sub no_of_cores_gnu_linux {
# Returns: # Returns:
# Number of CPU cores on GNU/Linux # Number of CPU cores on GNU/Linux
# undef if not GNU/Linux
my $no_of_cores; my $no_of_cores;
if(-e "/proc/cpuinfo") { if(-e "/proc/cpuinfo") {
$no_of_cores = 0; $no_of_cores = 0;
@ -2240,6 +2242,7 @@ sub no_of_cores_gnu_linux {
sub no_of_cpus_darwin { sub no_of_cpus_darwin {
# Returns: # Returns:
# Number of physical CPUs on Mac Darwin # Number of physical CPUs on Mac Darwin
# undef if not Mac Darwin
my $no_of_cpus = `sysctl -a hw 2>/dev/null | grep -w physicalcpu | awk '{ print \$2 }'`; my $no_of_cpus = `sysctl -a hw 2>/dev/null | grep -w physicalcpu | awk '{ print \$2 }'`;
return $no_of_cpus; return $no_of_cpus;
} }
@ -2247,6 +2250,7 @@ sub no_of_cpus_darwin {
sub no_of_cores_darwin { sub no_of_cores_darwin {
# Returns: # Returns:
# Number of CPU cores on Mac Darwin # Number of CPU cores on Mac Darwin
# undef if not Mac Darwin
my $no_of_cores = `sysctl -a hw 2>/dev/null | grep -w logicalcpu | awk '{ print \$2 }'`; my $no_of_cores = `sysctl -a hw 2>/dev/null | grep -w logicalcpu | awk '{ print \$2 }'`;
return $no_of_cores; return $no_of_cores;
} }
@ -2254,6 +2258,7 @@ sub no_of_cores_darwin {
sub no_of_cpus_freebsd { sub no_of_cpus_freebsd {
# Returns: # Returns:
# Number of physical CPUs on FreeBSD # Number of physical CPUs on FreeBSD
# undef if not FreeBSD
my $no_of_cpus = my $no_of_cpus =
(`sysctl -a dev.cpu | grep \%parent | awk '{ print \$2 }' | uniq | wc -l | awk '{ print \$1 }'` (`sysctl -a dev.cpu | grep \%parent | awk '{ print \$2 }' | uniq | wc -l | awk '{ print \$1 }'`
or or
@ -2265,6 +2270,7 @@ sub no_of_cpus_freebsd {
sub no_of_cores_freebsd { sub no_of_cores_freebsd {
# Returns: # Returns:
# Number of CPU cores on FreeBSD # Number of CPU cores on FreeBSD
# undef if not FreeBSD
my $no_of_cores = my $no_of_cores =
(`sysctl hw.ncpu 2>/dev/null | awk '{ print \$2 }'` (`sysctl hw.ncpu 2>/dev/null | awk '{ print \$2 }'`
or or
@ -2276,6 +2282,7 @@ sub no_of_cores_freebsd {
sub no_of_cpus_solaris { sub no_of_cpus_solaris {
# Returns: # Returns:
# Number of physical CPUs on Solaris # Number of physical CPUs on Solaris
# undef if not Solaris
if(-x "/usr/sbin/psrinfo") { if(-x "/usr/sbin/psrinfo") {
my @psrinfo = `/usr/sbin/psrinfo`; my @psrinfo = `/usr/sbin/psrinfo`;
if($#psrinfo >= 0) { if($#psrinfo >= 0) {
@ -2294,6 +2301,7 @@ sub no_of_cpus_solaris {
sub no_of_cores_solaris { sub no_of_cores_solaris {
# Returns: # Returns:
# Number of CPU cores on Solaris # Number of CPU cores on Solaris
# undef if not Solaris
if(-x "/usr/sbin/psrinfo") { if(-x "/usr/sbin/psrinfo") {
my @psrinfo = `/usr/sbin/psrinfo`; my @psrinfo = `/usr/sbin/psrinfo`;
if($#psrinfo >= 0) { if($#psrinfo >= 0) {
@ -2312,26 +2320,29 @@ sub no_of_cores_solaris {
sub no_of_cpus_aix { sub no_of_cpus_aix {
# Returns: # Returns:
# Number of physical CPUs on AIX # Number of physical CPUs on AIX
my $no_of_cpus; # undef if not AIX
$no_of_cpus = 0; my $no_of_cpus = 0;
my %seen; if(-x "/usr/sbin/lscfg") {
open(IN,"lscfg -vs|grep proc | wc -l|tr -d ' ' |") || return undef; open(IN,"/usr/sbin/lscfg -vs |grep proc | wc -l|tr -d ' ' |") || return undef;
$no_of_cpus = <IN>; $no_of_cpus = <IN>;
chomp ($no_of_cpus); chomp ($no_of_cpus);
close IN; close IN;
}
return $no_of_cpus; return $no_of_cpus;
} }
sub no_of_cores_aix { sub no_of_cores_aix {
# Returns: # Returns:
# Number of CPU cores on AIX # Number of CPU cores on AIX
# undef if not AIX
my $no_of_cores; my $no_of_cores;
$no_of_cores = 0; if(-x "/usr/bin/vmstat") {
open(IN,"vmstat 1 1|") || return undef; open(IN,"/usr/bin/vmstat 1 1|") || return undef;
while(<IN>) { while(<IN>) {
/.*lcpu=([0-9]*) .*/ and $no_of_cores = $1 ; /lcpu=([0-9]*) / and $no_of_cores = $1;
} }
close IN; close IN;
}
return $no_of_cores; return $no_of_cores;
} }

View file

@ -1,4 +1,4 @@
testsuite: ../src/parallel tests-to-run/* wanted-results/* testsuite: ../src/parallel tests-to-run/* wanted-results/* startdb
echo | mop || (echo mop is required for testsuite; /bin/false) echo | mop || (echo mop is required for testsuite; /bin/false)
seq 1 2 | mop || (echo seq is required for testsuite; /bin/false) seq 1 2 | mop || (echo seq is required for testsuite; /bin/false)
stdout echo || (echo stdout is required for testsuite; /bin/false) stdout echo || (echo stdout is required for testsuite; /bin/false)
@ -16,6 +16,9 @@ testsuite: ../src/parallel tests-to-run/* wanted-results/*
time sh Start.sh time sh Start.sh
date date
startdb:
sudo parallel /etc/init.d/{} start ::: postgresql mysql oracle-xe
clean: clean:
rm -rf input-files/random_dirs_no_newline rm -rf input-files/random_dirs_no_newline
rm -rf input-files/random_dirs_with_newline rm -rf input-files/random_dirs_with_newline

View file

@ -7,8 +7,8 @@ echo '### Test --number-of-cores'
parallel --number-of-cores parallel --number-of-cores
echo '### Test --use-cpus-instead-of-cores' echo '### Test --use-cpus-instead-of-cores'
(seq 1 4 | parallel --use-cpus-instead-of-cores -j100% sleep) && echo CPUs done & (seq 1 4 | stdout parallel --use-cpus-instead-of-cores -j100% sleep) && echo CPUs done &
(seq 1 4 | parallel -j100% sleep) && echo cores done & (seq 1 4 | stdout parallel -j100% sleep) && echo cores done &
echo 'Cores should complete first on machines with less than 4 physical CPUs' echo 'Cores should complete first on machines with less than 4 physical CPUs'
wait wait

View file

@ -137,7 +137,6 @@ d
3>45 3>45
4>6 4>6
5>
### Test --rrs -N1 --recend single ### Test --rrs -N1 --recend single
1>12a34 1>12a34
2>45a6 2>45a6