Find max value using parfor loop
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lukasz Wieczorek
il 29 Nov 2016
Modificato: Lukasz Wieczorek
il 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 Commenti
Risposta accettata
Walter Roberson
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!