Matlab多线程与多核运算, 以及GPU加速

来源:互联网 发布:盐城大数据产业园 编辑:程序博客网 时间:2024/05/18 03:36

Matlab支持多线程多核运算,并且可用GPU加速


软件版本: Matlab2015a (windows10+i7-4710hq 16G+GTX860M 4G)

当然,在使用GPU之前,要安装NVIDIA的驱动与CUDA的toolkit。 这些可以去NVIDIA develop下载。


1. Matlab多线程. 

  preference->Computer Vision System Toolbox ->勾选"Use Parallel"

  (某些版本中2007a: File->Preference->General->Multithreading 打开)

2. Matlab多核

matlabpool local 4

setenv('OMP_NUM_THREADS', '8')

getenv 'OMP_NUM_THREADS'

修改 home->parallel-manage cluster profile-> NumWorkers 8

parfor i=1:2000

  ...

end

matlabpool close

其它对global变量解决方法: 

A1 = evalin('base', 'A2'); 将workspace中变量A2赋值给函数中里的变量A

assignin('base', 'R', D/2) 将D/2的值输出到workspace, 生成新的变量R 

3. Matalb GPU加速

G = gpuArray(M) 将数据从内存中的M赋值给GPU内存中的G

A=zeros(10,10,'gpuArray'); %创建GPU内存中的变量A 10x10的零数组

B=gather(A); %将GPU内存中的变量A传回电脑内存中的B

fft, ifft, 三角函数, 相关函数xcorr以及常用的运算符等等都可以进行加速。

其它help gpuArray: gpuArray.ones

classUnderlying

existsOnGPU

isreal

length

ndims

size


Reference:

http://www.360doc.com/content/14/0311/10/13256259_359504252.shtml

http://www.360doc.com/content/14/0430/11/6322459_373434451.shtml


0 0