Skip to content

Commit

Permalink
Fix normalize_num_threads for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
vovaf709 committed Nov 22, 2024
1 parent ffad7ac commit 4d5c22e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion imops/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
from contextlib import contextmanager
from itertools import permutations
from typing import Callable, Optional, Sequence, Tuple, Union
Expand Down Expand Up @@ -53,7 +54,7 @@ def normalize_num_threads(num_threads: int, backend: Backend, warn_stacklevel: i
env_num_threads = os.environ.get(env_num_threads_var_name, '').strip()
env_num_threads = int(env_num_threads) if env_num_threads else None
# TODO: maybe let user set the absolute maximum number of threads?
num_available_cpus = len(os.sched_getaffinity(0))
num_available_cpus = os.cpu_count() if platform.system() == 'Darwin' else len(os.sched_getaffinity(0))

max_num_threads = min(filter(bool, [IMOPS_NUM_THREADS, env_num_threads, num_available_cpus]))

Expand Down

0 comments on commit 4d5c22e

Please sign in to comment.