Skip to content

Commit 8e094fb

Browse files
committed
add sys.cpu_count
1 parent 16648de commit 8e094fb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

+stdlib/+sys/cpu_count.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function N = cpu_count
2+
%CPU_COUNT how many CPUs
3+
N = maxNumCompThreads;
4+
if N < 2 % happens on some HPC
5+
N = feature('NumCores');
6+
end
7+
8+
% logical CPUs
9+
% N=java.lang.Runtime.getRuntime().availableProcessors();
10+
end

test/TestSys.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ function test_ram(tc)
5353

5454
end
5555

56-
function test_cpu(tc)
56+
function test_cpu_count(tc)
57+
58+
tc.verifyGreaterThan(stdlib.sys.cpu_count(), 0)
59+
60+
end
61+
62+
function test_cpu_load(tc)
5763

5864
tc.verifyGreaterThanOrEqual(stdlib.sys.cpu_load(), 0)
5965

0 commit comments

Comments
 (0)