Find max value using parfor loop
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lukasz Wieczorek
le 29 Nov 2016
Modifié(e) : Lukasz Wieczorek
le 29 Nov 2016
I have very complex, time-consuming computation function depends on three parameters. I decided to use parfor loop and I have the following situation
best_result = methodcall(init1, init2, init3);
for x1=1:init1
for x2=1:init2
parfor x3=1:init3
a = methodcall(x1,x2,x3);
if (a > best_result)
best_result = a;
end
end
end
end
And of course -
The temporary variable 'best_result' uses a value set outside the PARFOR.
I cannot define an 3d array (init1, init2, init3) because there are very big numbers. What I have to do, to solve it?
0 commentaires
Réponse acceptée
Walter Roberson
le 29 Nov 2016
best_result = methodcall(init1, init2, init3);
for x1=1:init1
for x2=1:init2
a = zeros(init3, 1);
parfor x3=1:init3
a(x3) = methodcall(x1,x2,x3);
end
best_result = max(best_result, max(a));
end
end
Note: your heading talks about finding the max value, but your proposed code would find the min value. I have coded here for max value; change the two max() to min() if you want min.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!