Find max value using parfor loop

6 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2016-11-29
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by