Windows8下Anaconda环境MKL线程数受限的技术咨询
I’ve dealt with similar MKL thread capping issues on older Windows versions, so let’s walk through some targeted fixes beyond the steps you’ve already tried:
1. Rule Out Windows 8 Power Plan Throttling
Windows 8’s default power plans often restrict CPU usage to save battery, which can indirectly cap MKL’s thread count. Here’s how to fix it:
- Head to Control Panel > Hardware and Sound > Power Options
- Switch to the High Performance plan (this ensures your CPU runs at full capacity)
- Open Task Manager’s Performance tab to confirm all 4 cores are active and not stuck at low utilization
2. Create a Custom MKL Config File (Anaconda-specific)
Anaconda sometimes overrides MKL settings behind the scenes. A dedicated config file can force it to respect your thread count:
- Navigate to your Anaconda install directory, then go to
Library\etc\mkl - Create a new text file named
mkl.conf(if it doesn’t exist already) - Paste these lines into the file:
MKL_NUM_THREADS=4 MKL_DYNAMIC=FALSE - Save the file, close all your Python/Anaconda sessions, then restart and test with this code:
import mkl mkl.set_num_threads(4) print(mkl.get_max_threads()) # Should now return 4
3. Sync PyTorch Thread Settings with MKL
PyTorch has its own thread management that can clash with MKL. Explicitly set both to match:
import torch import mkl # Force MKL to use 4 threads mkl.set_num_threads(4) # Set PyTorch's intra-operation threads to match MKL torch.set_num_threads(4) # Optional: Disable inter-operation threads if you don't need multi-task parallelism torch.set_num_interop_threads(1) # Verify settings print(f"MKL max threads: {mkl.get_max_threads()}") print(f"PyTorch active threads: {torch.get_num_threads()}")
4. Downgrade MKL for Windows 8 + Python 3.6 Compatibility
Python 3.6 is end-of-life, and newer MKL versions (2020+) have known compatibility quirks with Windows 8. Let’s roll back to a stable version:
- Open your Anaconda Prompt and run:
conda list mkl - If your MKL version is 2020 or newer, downgrade it:
conda install mkl=2019.4 -y - Reinstall a compatible PyTorch version for Python 3.6:
conda install pytorch=1.7.1 torchvision=0.8.2 cpuonly -c pytorch -y
5. Check System-wide Processor Restrictions
Windows 8 might have hidden group policies limiting CPU cores/threads:
- Press
Win + R, typegpedit.mscand hit Enter to open Local Group Policy Editor - Navigate to Computer Configuration > Administrative Templates > System > Processor Scheduling
- Double-click Limit maximum number of processors and set it to Not Configured (or explicitly set it to 4)
- Restart your PC to apply changes
内容的提问来源于stack exchange,提问作者Aviv Rubinstein

