MATLAB:多线程和多核之间的区别 [英] MATLAB: difference between Multithreading and Multicore
问题描述
我有一个i7-M620处理器,该处理器具有2个物理核心和每个核心2个线程(多线程CPU)(总共4个线程).当我使用MATLAB并行计算工具箱时,我只能打开2个池,而不能打开4个.这是代码:
I have an i7-M620 processor that have 2 physical cores and 2 threads (multi-threaded CPU) per core (a total of 4 threads). When I use the MATLAB Parallel Computing Toolbox, I can only open 2 pools and not 4. Here is the code:
matlabpool(2)
parfor i = 1:20
Test(i) = i^2;
end
matlabpool close
- 有人可以解释为什么吗?
- 我在这里执行多线程或多核计算吗?
- 是否可以同时使用MATLAB?
- 转到
Parallel->Manage Cluster Profiles
- 根据您的Matlab版本,您需要先
Validate
local
配置文件,然后再进行任何更改. - 单击
edit
并更改NumWorkers
变量以适合您的需求. - Go to
Parallel->Manage Cluster Profiles
- Depending on you Matlab version, you'll need to
Validate
thelocal
profile before changing anything. - Click
edit
and change theNumWorkers
variable to suit your needs.
推荐答案
我通过编辑并行计算内容的本地"配置来解决这个问题(我的i5带有2个核心和4个线程):
I got around this (with my core i5 with 2 cores and 4 threads) by editing the "local" configuration for the parallel computing stuff:
然后您可以像这样启动matlabpool
:
Then you can start matlabpool
like this:
matlabpool local
请注意,我从未使用parfor
获得加速. Matlab的开销始终超过了收益.我的意思是:首先对您的代码进行基准测试,然后确定parfor
(或其他并行的东西)是否对您有用.
Note I have never gotten a speedup using parfor
. Matlab's overhead has always outweighed the benefits. What I'm saying is: benchmark your code first, then decide if parfor
(or other parallel stuff) works for you or not.
这篇关于MATLAB:多线程和多核之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!