MATLAB Answers

YALMIP is not working with parfor loop

조회 수: 52(최근 30일)
Adriana Kiszka
Adriana Kiszka 3 Mar 2021
댓글: Adriana Kiszka 9 Mar 2021
I have the problem with decision variables and solving multiple problems using parfor loop.
I define some decision variables before parfor loop and when I run parfor loop I got the error: "Matrix dimensions must agree", because my decision variables are now empty vectors/matrices.
Here I attach a piece of my code for which I already get the error.
rep = 100;
P_min=[0.0800; 0.0800];
P_max=[0.2; 0.2];
Pd = [1.0800 1.0800 1.0800 1.0800;
0.9700 0.9700 0.9700 0.9700];
Qd = [0.2200 0.2200 0.2200 0.2200;
0.2000 0.2000 0.2000 0.2000];
lambda_l = sdpvar(m,1);
lambda_u = sdpvar(m,1);
lambda = sdpvar(n,1);
h_bas = 0;
h_bas = h_bas + sum(lambda_l.*P_min.*(~isinf(P_min))-lambda_u.*P_max.*(~isinf(P_max)));
cons_bas = [];
cons_bas = [cons_bas, lambda_l>=0,lambda_u>=0];
for t=1:T
parfor k=1:rep
h = h_bas + sum(lambda.*Pd(:,t));
cons = [cons_bas];
options = sdpsettings('solver','mosek','verbose',0);
Could you please help me to fix this problem?
  댓글 수: 1
Raymond Norris
Raymond Norris 3 Mar 2021
I would suggest posting some sample code.

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


Walter Roberson
Walter Roberson 3 Mar 2021
YALMIP permits you to define variables using calls such as
P = sdvpar(1)
and it expects that variable to be distinguished from
Q = sdvpar(1)
That can only happen if YALMIP is retaining state about which variables have been created and what their properties are.
In MATLAB, the methods of recording state like this are:
  • in graphics objects (not likely at all to be the case here)
  • in the base workspace
  • in persistent variables
  • in global variables
  • in handle objects
  • in class variables
However, graphics objects, base workspace, persistent variables, and global variables are not copied to parallel workers.
Objects (that are plainly referenced) are copied to parallel workers, but through a method equivalent of "save" and "load" --- a process that copies only serializable data, and loses dynamic properties, and effectively disconnects the copied clones from the original objects.
I suspect that the code was not designed with parallel use in mind.
  댓글 수: 7
Adriana Kiszka
Adriana Kiszka 9 Mar 2021
As I wrote, I got the above error that "Matrix dimensions must agree" and it was using the MATLAB version 2020b. Unfortunately this problem appeared after some runs, when I increased the number of repetitions. That's why it is difficult for me to find what's wrong.
Have you run exactly the same code I attached or maybe you modified it to one-dimensional version?

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

Johan Löfberg
Johan Löfberg 9 Mar 2021
편집: Johan Löfberg 9 Mar 2021
EDIT: Works now in newer MATLAB version!
YALMIP does not work with parfor, and it cannot be fixed or circumvented.
For YALMIP specific questions, you are much better off posting quetions on the YALMIP google groups forum.
  댓글 수: 3
Adriana Kiszka
Adriana Kiszka 9 Mar 2021
Thank you Johan for your suggestion, I will try to use optimizer.

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


Community Treasure Hunt

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

Start Hunting!

Translated by