Multi-thread on OptimizeCbModel

91 views
Skip to first unread message

Magdalena R

unread,
May 16, 2017, 11:28:19 AM5/16/17
to COBRA Toolbox
Hello,

I have to analyze a big number of cases with OptimizeCbModel, and to reduce time I was trying to parallel one of the steps. 

I read that the optimization of a linear problem cannot be done in a multi thread, so I was trying with a parallel for (parfor command, MATLAB). However, when running my code I am getting the following error :

Error using solveCobraLP (line 103)
No solver found.  call changeCobraSolver(solverName)
Error in optimizeCbModel (line 159)
solution = solveCobraLP(LPproblem);


I have installed gurobi5 and this problem does not present when running the same code with a normal for. Any idea of why could this be happening? My code is basically this:


range=0:0.1:1;
alpha=1;
ErrorRef=1000;

parfor t=1:length(range)
            beta=range(t);
            maux=NewModel;
            gamma=1-alpha-beta;
            maux=changeObjective(maux,maux.rxns(posBiom),[alpha beta gamma]);

            pesos=zeros((2*5*5),3);
            error=zeros((2*5*5),1);
            u=0;
            for j=0.1:0.1:0.2
                for k=0.1:0.1:0.5
                    for l=0.1:0.1:0.5
                        u=u+1;
                        maux=changeRxnBounds(NewModel,NewModel.rxns(posmATP(1)),j,'b');
                        maux=changeRxnBounds(maux,NewModel.rxns(posmATP(2)),k,'b');
                        maux=changeRxnBounds(maux,NewModel.rxns(posmATP(3)),l,'b');

         
                        pesos(u,:)=[alpha beta gamma];

                        f=optimizeCbModel(maux);
                        error(u)=sum((100*abs(f.x(posBiom))-datos(:,end))./datos(:,end));
                            
                    end
                end
            end
end
        
     
for e=1:length(error)
    if error(e)<ErrorRef
                ErrorRef=error(e);
                alphaOpt=alpha;
                betaOpt=beta;
    end
end

Almut Heinken

unread,
May 16, 2017, 11:34:27 AM5/16/17
to cobra-...@googlegroups.com
Dear Magdalena,
just to make sure: did you run changeCobraSolver to set the solver to gurobi before executing this script?
Best
Almut

--

---
You received this message because you are subscribed to the Google Groups "COBRA Toolbox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-toolbox+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Laurent Heirendt

unread,
May 16, 2017, 11:42:45 AM5/16/17
to COBRA Toolbox
Hi Magdalena,

This is an issue with MATLAB that global variables are not properly set during a parfor loop. You can get around this as described here:


Please let me know if this helps.

Best,

Laurent

Magdalena R

unread,
May 16, 2017, 2:27:04 PM5/16/17
to COBRA Toolbox
Hi Almut,
I set the Solver to gurobi, and then verified it by running the algorithm in a normal for loop, and it seems to be working. 
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-toolbo...@googlegroups.com.

Magdalena R

unread,
May 16, 2017, 2:27:40 PM5/16/17
to COBRA Toolbox
I did what is described in github and now it works, thanks Laurent! 

To unsubscribe from this group and stop receiving emails from it, send an email to cobra-toolbo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages