parrallel for matlab,How to parallel 4 works with PARFOR with a Core i3

QEUSTION:

I have Matlab R2012b for Ubuntu 64 bits. I have a Intel Core i3 CPU

M 330 @ 2.13GHz × 4.

I want to use parfor to

parallelize 4 loops at same time. Because Intel Core i3 has 2 Cores

and 4 Threads I use this code:

ifmatlabpool('size')==0%checking to seeifmypoolisalready open

matlabpool(4)elsematlabpool close

matlabpool(4)end

And I obtain the following error:

Error:

You requested a minimum of 4 workers, but the cluster "local" has

the NumWorkers property set to allow a maximum of 2 workers. To run

a communicating job on more workers than this (up to a maximum of

12 for the Local cluster), increase the value of the NumWorkers

property for the cluster. The default value of NumWorkers for a

Local cluster is the number of cores on the local machine.

Why? The default value of NumWorkers in my machine is 2 but if I

can do 4 loops at the same time, how do I get it?

ANSWER:

1、To increase the default NumWorkers,

open the Cluster Profile Manager (Parallel->Manage

Cluster Profiles). Pick the localprofile,

click edit, and increase NumWorkers to

the maximum possible value (in your case 4). Now it is possible to

create a matlabpool with

more workers than physical cores on your machine.

However, note that using more workers than cores might lead to

decreased performance as compared to having the same number of

workers as cores.

2、I

got around this (with my core i5 with 2 cores and 4 threads) by

editing the "local" configuration for the parallel computing

stuff:

Go to Parallel->Manage

Cluster Profiles

Depending on you Matlab version, you'll need

to Validate the local profile

before changing anything.

Click edit and

change the NumWorkers variable

to suit your needs.

Then you can start matlabpool like

this:

matlabpoollocal

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.

3、For a parallel configuration, this is the error thrown when

requesting more workers than the default:

The default value of NumWorkers for

a local cluster is the number of cores on the local machine. To run

a communicating job on more workers than this , increase the value

of the NumWorkers property for the cluster.

You can remedy that by modifying the 'local' profile

cluster properties, that effectively control the default number.

From

myCluster=parcluster('local');myCluster.NumWorkers=4;%'Modified'propertynow TRUE

saveProfile(myCluster);%'local'profile now updated,%'Modified'propertynow FALSE

Then matlabpool

open will give you the (default) num. of

workers, while matlabpool(n) will

give you n workers,

up to the above set maximum/default (n<=4).

You can check the number of currently open workers by:

matlabpool('size')

or from the indicator icon

at the lower-right corner of your desktop,

e.g. a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值