Parrallel run using parfor and institute server?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Edric Ellis
le 10 Oct 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!