How to use multiple cores

Problems with syntax of GAMS
Post Reply
GAMSisGREAT
User
User
Posts: 11
Joined: 6 years ago

How to use multiple cores

Post by GAMSisGREAT »

I have an MCP maximization problem that I need to solve for several thousand different levels of a parameter. I do this via writing a loop over this parameter and having the MCP problem solved within the loop. Running this takes something like 15 hours, and because I need to do this for many scenarios I would like to significantly cut the time.
My question is whether it is possible to make use of the multiple cores (I have 12) in my computer by breaking up the problem into several sub-problems and then sending these to different cores. The article "Grid-Enabled Optimization with GAMS" by Bussieck et al. gives me the impression that this is possible, but it does not give me enough information to actually do this. I have also looked at e.g. https://www.gams.com/latest/docs/UG_GridComputing.html and
https://www.gams.com/latest/docs/S_GUSS.html, but this did not answer my question. In a blog post on http://yetanothermathprogrammingconsult ... -jobs.html, Erwin Kalvelangen seems to introduce a way in which one can send a model to different cores, but this seems to require knowledge of batch files in windows and the explanation is not exhaustive enough (for me) to actually implement it.

Could anyone maybe point me towards further literature or some worked examples?
More precisely, what I want to do is the following. Assume I solve the MCP problem over a parameter that can take any integer number between 1 to 10 000. Call this parameter x. Then what I do now is
loop(x,
*solve the MCP problem
*put the result in a file
);
What I want to do is: make core 1 solve the loop over x in (1,833), make core 2 solve the loop over x in (834,1666), etc.
If you can point me towards some worked examples along these lines I'd be very grateful!
Thanks so much.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: How to use multiple cores

Post by Renger »

Hi
Why don't you just follow the example in the documentation and adjust it a little bit?
Here some pseudo code doing that. You don't want to assign yourself the separate jobs to a specific core, as this is not efficient: Suppose you send the first 500 to the first core and they are all difficult to solve, then you still have to wait a long time. Let Gams do the job.


Parameter h(i) 'model handles';
minvar.solveLink = 3;
loop(i,
...
solve mymodel using mcp;
h(i) = mymodel.handle;
);

* Collect the results

loop(i$handleCollect(h(i)),
myresults(i,s) = P.L(s);
);

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
GAMSisGREAT
User
User
Posts: 11
Joined: 6 years ago

Re: How to use multiple cores

Post by GAMSisGREAT »

Thanks for the quick reply. The problem is that I have sub-loops in a loop which GAMS only calculates if a previous condition holds true. Something like this:
loop(i,
* solve mcp model
* Solution collected in parameter p
If(p>0,
loop(k,
*solve another model
);
);
Thus, I don't know how GAMS splits the work up when I use submission and collection loops. I for example don't want GAMS to calculate the IF loop unnecessarily (as this takes a lot of time).
That was the reason for which I simply wanted to choose the subsets of i which I would designate to different cores.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: How to use multiple cores

Post by Renger »

OK, but then you define your handle over the complete loop: it will start at i=1 and 2 if you have two cores. If it finishes one of them, it will assign the next one to this core.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
GAMSisGREAT
User
User
Posts: 11
Joined: 6 years ago

Re: How to use multiple cores

Post by GAMSisGREAT »

So just to be sure I should do this:

Parameter h(i) 'model handles';
minvar.solveLink = 3;
loop(i,
* solve mymodel using mcp;
* save solution as parameter x
If(x>0,
loop(j,
* solve mymodel_2 using mcp;
);
h(i) = mymodel.handle;
);

* Collect the results
loop(i$handleCollect(h(i)),
myresults(i,s) = P.L(s);
);

Like this GAMS should evaluate the loop over i, do the loop over j if necessary, and it continues the loop over i even if the loop j is not yet done?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: How to use multiple cores

Post by Renger »

exactly.
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply