()
| 336 | print(f"{color}{func.__name__:<25} {round(factor, 1):>4}x {direction}{reset_color}") |
| 337 | |
| 338 | def determine_num_threads_and_affinity(): |
| 339 | if sys.platform != "linux": |
| 340 | return [None] * os.cpu_count() |
| 341 | |
| 342 | # Try to use `lscpu -p` on Linux |
| 343 | import subprocess |
| 344 | try: |
| 345 | output = subprocess.check_output(["lscpu", "-p=cpu,node,core,MAXMHZ"], |
| 346 | text=True, env={"LC_NUMERIC": "C"}) |
| 347 | except (FileNotFoundError, subprocess.CalledProcessError): |
| 348 | return [None] * os.cpu_count() |
| 349 | |
| 350 | table = [] |
| 351 | for line in output.splitlines(): |
| 352 | if line.startswith("#"): |
| 353 | continue |
| 354 | cpu, node, core, maxhz = line.split(",") |
| 355 | if maxhz == "": |
| 356 | maxhz = "0" |
| 357 | table.append((int(cpu), int(node), int(core), float(maxhz))) |
| 358 | |
| 359 | cpus = [] |
| 360 | cores = set() |
| 361 | max_mhz_all = max(row[3] for row in table) |
| 362 | for cpu, node, core, maxmhz in table: |
| 363 | # Choose only CPUs on the same node, unique cores, and try to avoid |
| 364 | # "efficiency" cores. |
| 365 | if node == 0 and core not in cores and maxmhz == max_mhz_all: |
| 366 | cpus.append(cpu) |
| 367 | cores.add(core) |
| 368 | return cpus |
| 369 | |
| 370 | |
| 371 | def thread_run(cpu, in_queue, out_queue): |
no test coverage detected
searching dependent graphs…