--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
is not serializable
> In parallel.internal.pool.serialize (line 21)
In distcomp.remoteparfor (line 77)
In parallel_function>iMakeRemoteParfor (line 1060)
In parallel_function (line 444)
In parallel (line 8)
Error using AMPLBase/solve (line 297)
Struct contents reference from a non-struct array object.
Error in parallel (line 8)
parfor i = 1:1:10
Warning: AMPLAPI version 1.0.0AMPL Version 20151130 (Linux x86_64)Licensed to --(redacted)--Maintenance expires with version 20161130.Using license file "/usr/local/bin/amplapi/matlab/../../ampl.lic".
is not serializable > In parallel.internal.pool.serialize (line 21) In distcomp.remoteparfor (line 77) In parallel_function>iMakeRemoteParfor (line 1060) In parallel_function (line 444) In parallel (line 8)
Error using AMPLBase/solve (line 297)Struct contents reference from a non-struct array object.
Error in parallel (line 8)parfor i = 1:1:10
evalc('run /usr/local/bin/amplapi/matlab/setUp.m');
% Works with a "for" loop but not with a "parfor" loop
parfor i = 1:1:10 ampl = AMPL; ampl.read('model.mod'); ampl.setOption('solver', 'cplex'); ampl.solve;end
Error using AMPL (line 21)Undefined variable "com" or class "com.ampl.AMPL".
Error in parallel2 (line 5)
parfor i = 1:1:10
Visit this group at https://groups.google.com/group/ampl.
clear all;
addpath('/usr/local/bin/amplapi/matlab/');
parfor i = 1:1:10
setUp
ampl = AMPL;
ampl.read('model.mod');
ampl.setOption('solver', 'cplex');
ampl.solve;
end
Error using setUp (line 2)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
Error in parallel2 (line 5)
parfor i = 1:1:10
for i = 1:1:NCores
ampl(i) = AMPL;
ampl(i).read('model.mod');
end
parfor i = 1:1:BigNumber
[change some aspects of ampl(currentcore)]
ampl(currentcore).solve
end
clear all;
addpath('/usr/local/amplapi/matlab/');
parfor i = 1:1:10 setUp; ampl = AMPL; ampl.read('model.mod'); ampl.setOption('solver', 'cplex'); ampl.solve;
ampl = 0;end
Cannot find AMPL API in
C:\Users\ADMINI~1\AppData\Local\Temp\2\tp07e8c5a6_d161_4860_bd9f_60bfb0bc4d8crp10428\a\tpaaab5098_c17b_4756_b08d_734579b78d0f\..\lib\ampl-1.2.2.jar
Error in cont1stage (line 17)
parfor t = 1:et
Error in TestSubproblemDecomp (line 158)
[KK1, KK2, KK3, W, tEnd2] = cont1stage(K, GENS, LINES,
BUSES,...
--
I am using AMPL on MATLAB through the AMPL API. In one of my applications I intend to call AMPL in a “parfor” (parallelizing calling AMPL). So I start by setting up AMPL on each worker (core) as follows:
“myCluster = parcluster('local');
poolsize=myCluster.NumWorkers;
parfor i=1:poolsize
setUp;
end
“
And then I run “parfor” (parallel “for” on MATLAB) as follows
“
basef = fileparts(which('example'));
u=-1:0.1:2;
parfor i=1:length(u)
ampl{i}= AMPL;
ampl{i}.read([basef '/' 'example.mod']);
ampl{i}.getParameter('u').setValues(u(i));
ampl{i}.setOption('solver' ,'gurobi');
ampl{i}.solve();
p(i)=ampl{i}.getValue('Objective');
ampl{i}.close;
% i
end
“
This works perfectly and it is much faster than a regular “for”. Notice that in this case there is only one parameter (‘u’) but in other instances where there are other fixed parameters on top of the ones that are changing inside "parfor", I find myself having to use dataframes to setup these fixed parameters inside the parfor. This however slows the performance significantly as the ampl structure for each subproblems is created every time from inside the for loop (at each core). Is there a way to use the AMPL API more efficiently with parfor? Like for instance forming the AMPL structures beforehand as in a regular for loop? As far as i know "parfor" does not allow being passed an array of ampl structures. Is there a way around this issue?
Thanks a lot.
Dear AMPL support services,
Thank you for your prompt reply. Here’s an example where I use dataframes to form the AMPL objects inside the parfor.
Example 1:
“
myCluster = parcluster('local');
poolsize=myCluster.NumWorkers;
parfor i=1:poolsize
setUp;
end
for k=1:maxiter;
parfor l=1:nlines
amplline=AMPL;
amplline.read([basef '/' 'Line.mod']);
amplline.getParameter('rho').setValues(rho(k));
amplline.getSet('lines').setValues(l);
dfline=DataFrame(1,'terminals','lambdap');
dfline.setColumn('terminals',num2cell(T_line(l,:)'));
dfline.setColumn('lambdap',lp(k));
amplline.setData(dfline,'terminals');
dfline=DataFrame(1,'lines_fr','Gf','Bf','Gsf','Bsf','thetad','Smax','Vminf','Vmaxf');
dfline.setColumn('lines_fr',[l,T_line(l,:)]);
dfline.setColumn('Gf',Gf(l));
dfline.setColumn('Bf',Bf(l));
dfline.setColumn('Gsf',Gsf(l));
dfline.setColumn('Bsf',Bsf(l));
dfline.setColumn('thetad',Anglediff(l));
dfline.setColumn('Smax',Smaxt(l));
dfline.setColumn('Vminf',Vminf(l));
dfline.setColumn('Vmaxf',Vmaxf(l));
amplline.setData(dfline,'lines_fr');
amplline.setOption('solver' ,'knitro');
amplline.solve();
objectiveline=amplline.getValue('subproblem');
exitflag=amplline.getObjective('subproblem').exitcode;
amplline.close;
end
end
“
This approach works but, as you can see, the AMPL objects “amplline” are created each time parfor called. And I reality these AMPL objects can be larger than this (and more dataframes are used to form them) which results in an large overhead for creating them (and this leads to a performance decline). Notice that the only parameter that is changing from one parfor call to another is “'lambdap',lp(k)”. However, if I can form these AMPL objects beforehand and then pass them to each worker through the parfor, the overhead for forming them would not carry over to each call of parfor. This can be easily done with a regular “for” (on one worker) where the AMPL objects “amplline” can be created beforehand as follows.
“
for l=1:nlines;
amplline(l)=AMPL;
amplline(l).read([basef '/' 'Line.mod']);
amplline(l).getParameter('rho').setValues(rho);
amplline(l).getSet('lines').setValues(l);
dfline(l)=DataFrame(1,'terminals' 'lambdap');
dfline(l).setColumn('terminals',num2cell(T_line(l,:)'));
dfline(l).setColumn('lambdap',lp(k));
amplline(l).setData(dfline(l),'terminals');
dfline(l)=DataFrame(1,'lines_fr','Gf','Bf','Gsf','Bsf','thetad','Smax','Vminf','Vmaxf');
dfline(l).setColumn('lines_fr',[l,T_line(l,:)]);
dfline(l).setColumn('Gf',Gf(l));
dfline(l).setColumn('Bf',Bf(l));
dfline(l).setColumn('Gsf',Gsf(l));
dfline(l).setColumn('Bsf',Bsf(l));
dfline(l).setColumn('thetad',Anglediff(l));
dfline(l).setColumn('Smax',Smaxt(l));
dfline(l).setColumn('Vminf',Vminf(l));
dfline(l).setColumn('Vmaxf',Vmaxf(l));
amplline(l).setData(dfline(l),'lines_fr');
end
for k=1:maxiter;
for l=1:nlines
amplline(l).getParameter('lambdap').setValues(T_line(l,:)',lp(k));
amplline(l).setOption('solver' ,'knitro');
amplline(l).solve();
Objectiveline=amplline(l).getValue('subproblem');
end
end
“
To summarize, what I desire to be able to do is the following:
Example 2:
“
myCluster = parcluster('local');
poolsize=myCluster.NumWorkers;
parfor i=1:poolsize
setUp;
end
for l=1:nlines;
amplline(l)=AMPL;
amplline(l).read([basef '/' 'Line.mod']);
amplline(l).getParameter('rho').setValues(rho);
amplline(l).getSet('lines').setValues(l);
dfline(l)=DataFrame(1,'terminals' 'lambdap');
dfline(l).setColumn('terminals',num2cell(T_line(l,:)'));
dfline(l).setColumn('lambdap',lp(k));
amplline(l).setData(dfline(l),'terminals');
dfline(l)=DataFrame(1,'lines_fr','Gf','Bf','Gsf','Bsf','thetad','Smax','Vminf','Vmaxf');
dfline(l).setColumn('lines_fr',[l,T_line(l,:)]);
dfline(l).setColumn('Gf',Gf(l));
dfline(l).setColumn('Bf',Bf(l));
dfline(l).setColumn('Gsf',Gsf(l));
dfline(l).setColumn('Bsf',Bsf(l));
dfline(l).setColumn('thetad',Anglediff(l));
dfline(l).setColumn('Smax',Smaxt(l));
dfline(l).setColumn('Vminf',Vminf(l));
dfline(l).setColumn('Vmaxf',Vmaxf(l));
amplline(l).setData(dfline(l),'lines_fr');
end
for k=1:maxiter;
parfor l=1:nlines
amplline(l).getParameter('lambdap').setValues(T_line(l,:)',lp(k));
amplline(l).setOption('solver' ,'knitro');
amplline(l).solve();
Objectiveline=amplline(l).getValue('subproblem');
end
end
“
However, doing so results in the following error:
“
AMPL Version 20160803 (Intel icl EMT64 10.1.029, 64-bit; expires midnight 20170131 GMT)
License 57b64d6d-1 for ELEC4712 Honours Thesis, Gregor Verbic, University of Sydney
is not serializable
> In parallel.internal.pool.serialize (line 21)
In distcomp.remoteparfor/addInterval (line 103)
In parallel_function>distributed_execution (line 780)
In parallel_function (line 587)
In ADMMtest (line 306)
Error using AMPL/getValue (line 82)
Struct contents reference from a non-struct array object.
Error in example1 (line 306)
parfor l=1:n
”
Your support is greatly appreciated.
Sincerely,
Sleiman
Hello.
It worked for me. I implemented a
Benders decomposition scheme for a hydrothermal scheduling
problem; the Benders sub-problems were solved in parallel.
Just don't have my laptop with me right now, but will gladly share the files by evening.
Regards,
Carlos J. López
--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/PtfBRMRdzkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to am...@googlegroups.com.
Carlos,
That would be awesome, thank you so much. I am running the old API (ampl-1.4.0.0.jar), do I need to update to 2.0.0-3 (C++ version)?
Another random question, do you run both the AMPL instances and the linear/non-linear solver on the same local machine? I was hoping this would allow me to write the problem locally with API and the send all of the problem instances to Gurobi Cloud. Please let me know If I am misunderstanding what capabilities the AMPL + MATLAB API parfor combination.
Thanks Again,
Malcolm
On Wed, Apr 24, 2019 at 4:49 PM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hello.
It worked for me. I implemented a Benders decomposition scheme for a hydrothermal scheduling problem; the Benders sub-problems were solved in parallel.
Just don't have my laptop with me right now, but will gladly share the files by evening.
Regards,
Carlos J. López
On Wed, Apr 24, 2019 at 4:04 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Hi Malcolm,
The MATLAB API now works on top of our C++ API with a thin layer of Java in the middle (instead of a complete Java API in the middle), this should have reduced the overhead of having to create multiple objects but still does not allow direct use with with parfor.
--
Filipe Brandão
am...@googlegroups.com
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
The code is in a rather primitive
state and I'm sure it can be improved. Any suggestion or
recommendation would be appreciated. It was intended to work in a 28-core machine, but today
I tested in a 2-core i5 processor and it worked.
I too am still using ampl-1.4.0.0.jar, but I believe it should behave the same with the newest version. And for the second question, that is right, I run both the AMPL instance and the solver on the same machine.
Carlos J.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.