如果您可以访问多个GPU,则可以使用并行池在多个GPU上执行计算。
To determine the number of GPUs that are available for use in MATLAB, use thegpudeviceCount
功能。
与可用的GPU一样多的工人开始平行池。为了获得最佳性能,MATLAB默认情况下,MATLAB为每个工人分配了不同的GPU。
使用“本地”配置文件开始并行池(PARPOOL)...连接到并行池(工人数:3)。
To identify which GPU each worker is using, callgpudevice
inside anSPMD
堵塞。这SPMD
block runsgpudevice
on every worker.
使用平行语言功能,例如parfor
or帕菲瓦尔
,将您的计算分发给平行池中的工人。如果您使用gpuarray
在您的计算中启用了功能,这些功能在工人的GPU上运行。有关更多信息,请参阅在GPU上运行MATLAB功能。例如,请参阅在多个GPU上运行MATLAB功能。
完成计算后,关闭并行池。您可以使用GCP
功能以获得当前的平行池。
If you want to use a different choice of GPUs, then you can usegpudevice
to select a particular GPU on each worker, using the GPU device index. You can obtain the index of each GPU device in your system using thegpudeviceCount
功能。
Suppose you have three GPUs available in your system, but you want to use only two for a computation. Obtain the indices of the devices.
Define the indices of the devices you want to use.
启动您的平行池。使用SPMD
块和gpudevice
to associate each worker with one of the GPUs you want to use, using the device index. TheLabindex
功能标识每个工人的索引。
使用“本地”配置文件开始并行池(PARPOOL)...连接到并行池(工人数:2)。
As a best practice, and for best performance, assign a different GPU to each worker.
完成计算后,关闭并行池。