主要是想在server上实现 matlab 的 并行运算,问了一些人,大概有两个思路。(p.s. server上是 linux 系统)
“有两种方式,一种是bash parallel processing,需要提前计算好程序的动态CPU和内存使用率在分配核心,否则会出现进程假死。另一种是MATLAB的并行,用spmd或parfor,根据具体代码修改。"
最首先是关于 matlab parallel processing 的定义,一些关于 parfor loop 的使用说明,以及 已有的 toolbox,还有一些exercise
http://people.sc.fsu.edu/~jburkardt/m_src/matlab_parallel/matlab_parallel.html
也有matlab自身 的电子书
https://www.mathworks.com/help/pdf_doc/distcomp/distcomp.pdf
下面是一篇blog写的,其中提到用 bash 计算,以及用 parfor loop 的方式进行编程
http://blog.csdn.net/jiandanjinxin/article/details/50697508
下面是一个 关于 使用 parfor loop或者 matlabpool的 cmd 的guide
http://blog.csdn.net/ylf13/article/details/17608399
an example on Youtube
1 type cmd 'matlabpool open num'
the number means how many cores to open
use the cmd matlabpool close to end it
2 parfor loop
use this loop to cover the for loop
the cmd are as below
clear all
close all
clc
% matlabpool open 4
a=
rand
(1e6,1);
b=
rand
(1e6,1);
c=zeros(size(a));
tic
tstart=tic;
for
i=1:length(a)
c(i)=a(i)+b(i);
end
t_normal_for=toc(tstart)
tstart=tic;
parfor i=1:length(a)
c(i)=a(i)+b(i);
end
t_parfor=toc(tstart)
% matlabpool close
3 download the parallel computing toolbox
GPU running
4 can use the batch in matlab
5 use the spmd (single program multiple data)
when use spmd, preferred to use the switch case or if else
for each case, specified as each worker
6 use the gpu code
2 functions: arrayfun pagefun
esp. for single cmd line
gpuArray: to transfer the cpu data to the gpu data
after calculation, should transfer the gpu data to the cpu data