Parfor篇
The MATLAB client (where the parfor is issued) coordinates with MATLAB workers comprising a parallel pool, so that the loop iterations can be executed in parallel on the pool. The necessary data on which parfor operates is sent from the client to workers, where most of the computation happens, and the results are sent back to the client and pieced together.
Each execution of the body of a parfor-loop is an iteration.
如果循环内有一个迭代是依赖于另一个迭代的,那么这个循环不可以用parfor来实现。也因此,parfor不可以处理global变量,因为这个变量的值可能会在运行过程中被其他的迭代修改,造成不同的迭代之间的数据依赖,让程序出现意想不到的结果。
在parfor环境下,有四种变量:
1. accumulate variable:
2. temporary variable: 它可能在不同的parfor迭代(index)下有不同的值,例如,任何仅仅依赖于index并且不属于accumulate变量的变量。在运行完parfor所有迭代后,它的值无法确定,因此不保存。However, suppose you use a nonindexed variable inside the loop, or a variable whose indexing does not depend on the loop variable i.
2.
Matlab Distribute