author | wenzelm |
Wed, 14 Feb 2024 14:41:18 +0100 | |
changeset 79604 | 0e8ac7db1f4d |
parent 79603 | 9f002cdb6b8d |
child 79605 | 83627a092fbf |
permissions | -rw-r--r-- |
79603 | 1 |
/* Title: Pure/Concurrent/multithreading.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Multithreading in Isabelle/Scala. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Multithreading { |
|
79604
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
11 |
/* physical processors */ |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
12 |
|
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
13 |
def num_processors(ssh: SSH.System = SSH.Local): Int = |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
14 |
if (ssh.isabelle_platform.is_macos) { |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
15 |
val result = ssh.execute("sysctl -n hw.physicalcpu").check |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
16 |
Library.trim_line(result.out) match { |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
17 |
case Value.Int(n) => n |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
18 |
case _ => 1 |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
19 |
} |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
20 |
} |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
21 |
else { |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
22 |
val Core_Id = """^\s*core id\s*:\s*(\d+)\s*$""".r |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
23 |
val cpuinfo = ssh.read(Path.explode("/proc/cpuinfo")) |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
24 |
(for (case Core_Id(Value.Int(i)) <- Library.trim_split_lines(cpuinfo)) yield i).toSet.size |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
25 |
} |
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
26 |
|
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
27 |
|
79603 | 28 |
/* max_threads */ |
29 |
||
30 |
def max_threads(): Int = { |
|
31 |
val m = Value.Int.unapply(System.getProperty("isabelle.threads", "0")) getOrElse 0 |
|
79604
0e8ac7db1f4d
clarified num_processors: follow Poly/ML (with its inaccuracies);
wenzelm
parents:
79603
diff
changeset
|
32 |
if (m > 0) m else (num_processors() max 1) min 8 |
79603 | 33 |
} |
34 |
} |