MATLAB中的并行计算

  1. 在图像处理任务中经常会对很多图片进行特征提取,每幅图片的特征提取的过程都是可以并行的。

http://www.mathworks.cn/cn/help/distcomp/parfor.html

http://www.mathworks.cn/cn/help/distcomp/matlabpool.html

Examples

Perform three large eigenvalue computations using three computers or cores:

matlabpool(3)
parfor i=1:3, c(:,i) = eig(rand(1000)); end

 

  1. 关于Sliced variables:

 

A sliced variable is one whose value can be broken up into segments, or slices, which are then operated on separately by workers and by the MATLAB client. Each iteration of the loop works on a different slice of the array. Using sliced variables is important because this type of variable can reduce communication between the client and workers. Only those slices needed by a worker are sent to it, and only when it starts working on a particular range of indices.

In the next example, a slice of A consists of a single element of that array:

parfor i = 1:length(A)
   B(i) = f(A(i));
end

Characteristics of a Sliced Variable.  A variable in a parfor-loop is sliced if it has all of the following characteristics. A description of each characteristic follows the list:

  • Type of First-Level Indexing — The first level of indexing is either parentheses, (), or braces, {}.

  • Fixed Index Listing — Within the first-level parenthesis or braces, the list of indices is the same for all occurrences of a given variable.

  • Form of Indexing — Within the list of indices for the variable, exactly one index involves the loop variable.

  • Shape of Array — In assigning to a sliced variable, the right-hand side of the assignment is not [] or '' (these operators indicate deletion of elements).

Type of First-Level Indexing. For a sliced variable, the first level of indexing is enclosed in either parentheses, (), or braces, {}.

This table lists the forms for the first level of indexing for arrays sliced and not sliced.

Reference for Variable Not SlicedReference for Sliced Variable
A.xA(...)
A.(...)A{...}

 

 

  1. When any of the following are true, MATLAB does not execute the loop in parallel:
  • There are no workers in a MATLAB pool

  • You set M to zero

  • You do not have Parallel Computing Toolbox

If you have Parallel Computing Toolbox, you can read more about parfor and matlabpool by typing

doc distcomp/parfor
doc distcomp/matlabpool

转载于:https://www.cnblogs.com/avril/archive/2012/09/26/2703752.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值