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

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

  • 相关阅读:
    python的os模块命令
    python的os模块
    albert1017 Linux下压缩某个文件夹(文件夹打包)
    装饰器加不加()
    json和jsonp解决跨域传输数据等
    wsgi
    flask建立数据模型数据类型
    爬虫中
    javaweb学习总结(四)——Http协议
    JavaWeb学习总结(三)——Tomcat服务器学习和使用(二)
  • 原文地址:https://www.cnblogs.com/avril/p/2703752.html
Copyright © 2011-2022 走看看