我有一个脚本,它解决了for循环中许多参数的微分方程组。 (迭代是完全独立的,但是在每次迭代结束时,根据计算结果修改大矩阵(mat))。下面是代码:(B是含有参数的矩阵) mat=zeros(20000,1);
for n=1:20000
prop=B(n,:); % B is a (20000 * 2) matrix that contains U and V p
我在Matlab中有下面的代码(当然简化了,但是这显示了问题的根源),它以前使用for;我想改变它使用parfor代替: isForeground = ones(1, size(In, 1));
% this used to be a simple for
parfor i=1:X
data = output_of_some_expensive_function();
我需要并行执行两个Matlab函数。问题是从他们那里获得结果比执行慢得多。 第一种方法: spmd;
if labindex==1,
K=MatricaK(NP, NE, r, Kxx, N, h, 1); %K is 1000x1000 matrix
end;
if labindex==2,
F=Apkrovos(NP, NE, N, r, Ta, h, 1); %F