parpool
在集群上创建并行池
Syntax
Description
parpool
starts a parallel pool of workers using the default cluster profile. With default preferences, MATLAB®starts a pool on the local machine with one worker per physical CPU core, up to the preferred number of workers. For more information on parallel preferences, see指定您的平行首选项。
In general, the pool size is specified by your parallel preferences and the default profile.parpool
creates a pool on the default cluster with itsNumWorkers
在范围内[1, preferredNumWorkers]
for running parallel language features.preferredNumWorkers
是the value defined in your parallel preferences. For all factors that can affect your pool size, seePool Size and Cluster Selection。
parpool
enables the full functionality of the parallel language features in MATLAB by creating a special job on a pool of workers, and connecting the MATLAB client to the parallel pool. Parallel language features includeparfor
,parfeval
,parfevalOnAll
,spmd
, 和分散式
。If possible, the working folder on the workers is set to match that of the MATLAB client session.
Parpool(
creates and returns a pool with the specified number of workers.poolsize
)poolsize
can be a positive integer or a range specified as a 2-element vector of integers. Ifpoolsize
是一个范围,在所需的范围内,生成的池的大小尽可能大。
Specifying thepoolsize
覆盖偏好或配置文件中指定的工人人数,并启动精确的工人数量,即使必须等待他们可用。大多数集群都有最多可以启动的工人数量。如果配置文件指定MATLAB作业调度程序群集,则parpool
从已经运行并在该MATLAB作业调度程序下可用的人员中保留其工人。如果配置文件指定本地或第三方调度程序,parpool
instructs the scheduler to start the workers for the pool.
Parpool(___,
applies the specified values for certain properties when starting the pool.Name,Value
)
返回一个poolobj
= parpool(___)Parallel.Pool
对象代表群集上池的客户端工作区。您可以使用池对象来编程删除池或访问其属性。采用删除(pool)
关闭平行池。
Examples
Input Arguments
Output Arguments
Tips
桌面左下角的池状态指示器显示了客户端会话连接到池和池状态。单击图标以获取支持的池操作菜单。万博1manbetx
With a pool running:With no pool running:
If you set your parallel preferences to automatically create a parallel pool when necessary, you do not need to explicitly call the
parpool
command. You might explicitly create a pool to control when you incur the overhead time of setting it up, so the pool is ready for subsequent parallel language constructs.删除(poolobj)
shuts down the parallel pool. Without a parallel pool,spmd
和parfor
run as a single thread in the client, unless your parallel preferences are set to automatically start a parallel pool for them.When you use the MATLAB editor to update files on the client that are attached to a parallel pool, those updates automatically propagate to the workers in the pool. (This automatic updating does not apply to Simulink®模型文件。要向工人传播更新的模型文件,请使用
updateAttachedFiles
function.)If possible, the working folder on the workers is initially set to match that of the MATLAB client session. Subsequently, the following commands entered in the client Command Window also execute on all the workers in the pool:
This behavior allows you to set the working folder and the command search path on all the workers, so that subsequent pool activities such as
parfor
-loops execute in the proper context.When changing folders or adding a path with
cd
或者addpath
on clients with Windows®operating systems, the value sent to the workers is the UNC path for the folder if possible. For clients with Linux®operating systems, it is the absolute folder location.If any of these commands does not work on the client, it is not executed on the workers either. For example, if
addpath
指定客户端无法访问的文件夹addpath
command is not executed on the workers. However, if the working folder can be set on the client, but cannot be set as specified on any of the workers, you do not get an error message returned to the client Command Window.Be careful of this slight difference in behavior in a mixed-platform environment where the client is not the same platform as the workers, where folders local to or mapped from the client are not available in the same way to the workers, or where folders are in a nonshared file system. For example, if you have a MATLAB client running on a Microsoft®Windows操作系统在MATLAB工人都在Linux操作系统上运行时,相同的参数
addpath
不能同时工作。在这种情况下,您可以使用该功能pctRunOnAll
to assure that a command runs on all the workers.客户和工人之间的另一个区别是
addpath
arguments that are part of theMatlabroot
folder are not set on the workers. The assumption is that the MATLAB install base is already included in the workers’ paths. The rules foraddpath
regarding workers in the pool are:Subfolders of the
Matlabroot
folder are not sent to the workers.第一次出现之前出现的任何文件夹
Matlabroot
folder are added to the top of the path on the workers.Any folders that appear after the first occurrence of a
Matlabroot
folder are added after theMatlabroot
group of folders on the workers’ paths.
For example, suppose that
Matlabroot
on the client isC:\ applications \ matlab \
。With an open parallel pool, execute the following to set the path on the client and all workers:addpath('P1','P2','C:\Applications\matlab\T3','C:\Applications\matlab\T4','P5','C:\Applications\matlab\T6','P7','P8');
Because
T3
,T4
, 和T6
are subfolders ofMatlabroot
, they are not set on the workers’ paths. So on the workers, the pertinent part of the path resulting from this command is:P1 P2
P5 P7 P8 If you are usingMacintosh或Linux,并在大型平行池创建期间看到问题,请参阅Macintosh和Linux的推荐系统限制。