Parfor loop problem during response surface creation

Hello,
I'm having problems when trying to run a parfor loop to reduce runtime for my response surface creation. Inside the parfor loop i have to create a vector of 13 parameters between an upper (ub) and lower bound(lb). Then, this vector goes inside a function called response_surface_AVL. The problem is that, inside this function, the variables doesn't seem to be declared, but when I try only with the RS_input, pars is correctly created. I've iterated through many different options, but none of them seem to work.
Thank you for the help!!
Gonzalo
parfor counter =1:n_points
pars= zeros(1,13);% If i take this out, classification error appears
for ii =1:13
x= rand;
if (ii== 5) || (ii== 6) || (ii== 7) || (ii== 8)
pars(ii) = round(lb(ii)+x*(ub(ii)-lb(ii)));
else
pars(ii) = lb(ii)+x*(ub(ii)-lb(ii));
end
end
RS_input(counter,:) = pars;
%Here I've tried inputting both pars, RS_input and other auxiliary variables, but every time the
% I get an error, as if the pars/RS_input input for the response_surface_AVL function didn't
initialise = response_surface_AVL(RS_input(counter,:),dir,flight_con{1,1},filename);
RS_CL0(counter) = initialise.CL0;
end
% Here is where the variables aren't declared, maybe due to how they are declared
function initialise = response_surface_AVL(pars,dir,flight_con,filename)
%...
geo.Ct_w = pars(1);
geo.b_w= pars(2);
geo.sweep1_w = pars(3);%(deg)
geo.aoar_w = pars(4);%(deg)
geo.airfoilroot_w = strcat(num2str(pars(6)),'4',num2str(pars(5),'%02d'));
geo.airfoiltip_w = strcat(num2str(pars(8)),'4',num2str(pars(7),'%02d'));
%canard
geo.b_c = pars(9);%(m)
geo.sweep1_c = pars(10);%(deg)
geo.aoar_c = pars(11);%(deg)
%Manouevre longitudinal
geo.zle_c = pars(12);%(m)MANOUEVRE6
%Manouevre lateral
geo.b_f= pars(13);%(m)
%...

댓글 수: 1

It's not clear from the code you've shown what the problem is. Your for loop to initialise pars looks fine. I would try the following:
  1. Try and simplify the code to come up with a minimal self-contained example that demonstrates the problem. If you can do that, post it here and we'll have a better chance of helping
  2. Try running the parfor loop with no parallel pool open. This will enable you to set breakpoints inside response_surface_AVL. You can do this either by changing your parallel preferences so that a parallel pool is not automatically created, or by changing your parfor line to read parfor (counter = 1:n_points, 0) .
  3. Sometimes it can be helpful to add disp statements inside your parfor loop to trace values (I would recommend running with a pool of size 1 to make the output easier to understand).

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2020년 5월 10일

댓글:

2020년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by