spmd
Execute code in parallel on workers of parallel pool
Syntax
spmd语句
end
描述
SPMD,
defines an语句
, endspmd
单行上的语句。MATLAB®executes thespmd
body denoted by语句
同时在几个Matlab工人身上。每个工人都可以在不同的数据集或分布式数据的不同部分进行操作,并可以在执行并行计算时与其他参与的工人进行通信。这spmd
statement can be used only if you have Parallel Computing Toolbox™. To execute the statements in parallel, you must first create a pool of MATLAB workers usingparpool
或者have your parallel preferences allow the automatic start of a pool.
Inside the body of thespmd
statement, each MATLAB worker has a unique value oflabindex
, whilenumlabs
denotes the total number of workers executing the block in parallel. Within the body of thespmd
statement, communication functions for communicating jobs (such aslabSend
和labReceive
)可以在工人之间传输数据。
Values returning from the body of anspmd
statement are converted toComposite
MATLAB客户端上的对象。复合对象包含对存储在远程MATLAB工人上的值的引用,可以使用单元格索引检索这些值。工人的实际数据仍在工人身上可用spmd
执行,只要该复合材料存在于客户端上并且平行池保持打开状态。
默认情况下,MATLAB使用池中的所有工人。如果没有池活动,MATLAB将创建一个池并使用该池中的所有工人。如果您的偏好不允许自动创建自动池,则MATLAB在本地执行块主体,并根据需要创建复合对象。你不能执行spmd
block if any worker is busy executing aparfeval
请求,除非您使用SPMD(0)
。
For more information aboutspmd
和Composite objects, see分发阵列并运行SPMD。
Note
利用parfevalOnAll
instead ofparfor
或者spmd
if you want to use清除
。This preserves workspace transparency. SeeEnsure Transparency in parfor-Loops or spmd Statements。
SPMD(
用途n
),语句
, endn
to specify the exact number of MATLAB workers to evaluate语句
, provided thatn
工人可以从平行池中获得。如果没有足够的工人可用,则会出现错误。如果n
is zero, MATLAB executes the block body locally and creates Composite objects, the same as if there is no pool available.
SPMD(
用途a minimum ofm
,n
), statements, endm
和a maximum ofn
工人评估语句
。如果没有足够的工人可用,则会出现错误。m
can be zero, which allows the block to run locally if no workers are available.
例子
限制
这
spmd
statement supports thread-based environments, however worker communication functions, such aslabSend
和labReceive
,在基于线程的环境中金宝app不支持。有关更多信息,请参阅Run MATLAB Functions in Thread-Based Environment。
提示
An
spmd
块运行on the workers of the existing parallel pool. If no pool exists,spmd
除非在您的并行首选项中禁用池的自动启动,否则将启动一个新的并行池。如果没有平行池,并且spmd
无法启动一个,代码在客户端会话中串行运行。如果是
AutoAttachFiles
平行池的集群配置文件中的属性设置为真的
,Matlab对spmd
block to determine what code files are necessary for its execution, then automatically attaches those files to the parallel pool job so that the code is available to the workers.For information about restrictions and limitations when using
spmd
, seeRun Single Programs on Multiple Data Sets。有关性能的信息
spmd
和other parallel programming constructs, see在SPMD,PARFOR和PARFEVAL之间进行选择。