Parrallel run using parfor and institute server?
4 ビュー (過去 30 日間)
古いコメントを表示
I need to speed up my matlab code, for this How can I use parfor nested loop? Here, I am able to use iner parfor loop but it takes time almost equal to normal nested for loop. And outer parfor loop give error. I am trying to run the for loop code as.
function output=f
t=[0.2 0.5];
na=(0:10:20).*10.^11 ;
output=zeros(length(t),length(na));
for i=1:length(t)
for j=1:length(na)
KFa=sqrt(pi.*na(j));
mu=log(exp(1./t(i))-1);
output(i,j)=KFa.*.*t(i)./mu
end
end
end
Along with this, I also want to run this code using a server facility which contain multiple CPU (as worker) and cores. How would I run it using the server.
0 件のコメント
回答 (1 件)
Edric Ellis
2022 年 10 月 10 日
The problem with converting the outer loop to parfor is described in the error message that you get when you try:
Error: When indexing the sliced variable 'output', the range of the for-loop variable 'j' must be a row vector of positive constant numbers or variables.
The fix is to calculate the length of na outside the parfor loop. (I know this seems unncessary, but parfor is very fussy about this sort of thing)
t=[0.2 0.5];
na=(0:10:20).*10.^11;
na_len = length(na);
output=zeros(length(t),na_len);
for i=1:length(t)
for j=1:na_len
KFa=sqrt(pi.*na(j));
mu=log(exp(1./t(i))-1);
output(i,j)=KFa.*t(i)./mu
end
end
The speed-up you get here may well be only small using local workers.
To use more resources, you need to get MATLAB Parallel Server set up on your server facility. Once that is available, you can run your parfor loop across multiple machines.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!