zoukankan      html  css  js  c++  java
  • 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.x A(...)
    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

    你问我生命中还有什么可追寻?

  • 相关阅读:
    小程序中的箭头函数
    总结:小程序常见问题(2)
    总结:小程序常见问题(1)
    实战:云开发-实现奶茶店小程序(二)
    实战:云开发-实现奶茶店小程序(一)
    实战:云开发-实现在线充值小程序
    ORACLE表名与列名小写转成大写
    MSSQL所有表名、列名转大写的SQL语句
    ORACLE 之 标识符无效 问题总结及解决方案
    SQL语句获取数据库中的表主键,自增列,所有列
  • 原文地址:https://www.cnblogs.com/avril/p/2703752.html
Copyright © 2011-2022 走看看