MATLAB:多线程和多核之间的区别 [英] MATLAB: difference between Multithreading and Multicore

查看:729
本文介绍了MATLAB:多线程和多核之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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?
  • 推荐答案

    我通过编辑并行计算内容的本地"配置来解决这个问题(我的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:

    1. 转到Parallel->Manage Cluster Profiles
    2. 根据您的Matlab版本,您需要先Validate local配置文件,然后再进行任何更改.
    3. 单击edit并更改NumWorkers变量以适合您的需求.
    1. Go to Parallel->Manage Cluster Profiles
    2. Depending on you Matlab version, you'll need to Validate the local profile before changing anything.
    3. Click edit and change the NumWorkers variable to suit your needs.

    然后您可以像这样启动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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆