[Cbc] CbcEventHandler in multithreading
John Forrest
john.forrest at fastercoin.com
Sun Sep 18 11:00:32 EDT 2016
Alexis,
On 15/09/16 01:21, Alexis wrote:
>
> Hi,
>
> With the help of Tobias, I managed to compile CBC standalone in
> VS2015. Inspection of the CPU usage on my machine indicates that
> multithreading seems to work.
>
> I have a few more questions:
>
> 1 - Does the parameter with -threads indicates the number of extra
> threads? 0 would mean that there is only the master thread,
> essentially no multithreading?
>
Yes.
>
> 2 - I am not sure I understand at this point the parameter
> threadMode_, but I am going to look more into it.
>
Mostly of secondary importance. The deterministic option switch on by
-threads 1nn is important.
> 3 - More importantly, I am trying to use multithreading with my
> application. Compilation is ok. I am mostly wondering about the
> behavior of the handlers in the multithreading settings.
>
> My code is essentially an extended version of driver6.cpp/driver4.cpp
> so I used to have
>
> // Pass to Cbc initialize defaults
> CbcModel modelA(solver1);
> CbcModel * model = &modelA;
> CbcMain0(modelA);
> // Event handler
> MyEventHandler3 eventHandler;
> model->passInEventHandler(&eventHandler);
> /* Now go into code for standalone solver
> Could copy arguments and add -quit at end to be safe
> but this will do
> */
> const char * argv2[]={"driver4","-solve","-quit"};
> CbcMain1(3,argv2,modelA);
>
> Now, I have
>
> * const char * argv2[]={"driver4","-threads, "X", "-solve","-quit"};*
> * CbcMain1(5,argv2,modelA);*
>
> - Is eventHandler shared between all the threads? Or is there one
> handler (copy) per thread?
I may get this wrong, but ... Normally shared - just one copy - so
CbcModel pointer is to master. There is option to copy - then points to
thread CbcModel.
> - In the first case, is eventHandler thread safe?
Threadsafe for locals. I would try having copies so each can get local
CbcModel and global one. I would use three globals (global model, best
objective and stopflag) + mutex. Then if event handler wants to do
something it grabs mutex, looks at flag - if set releases mutex and
returns. If not set then sets it, releases mutex and returns saying do
something. If you just want to save a good solution then similar. I
have probably got that all wrong.
> - What would be the best way to get the best solution in the tree?
> Currently, I just have to call
>
> CbcEventHandler::CbcAction
> MyEventHandler3::event(CbcEvent whichEvent)
> {
> // If in sub tree carry on
> if (!model_->parentModel()) {
> if (whichEvent==solution||whichEvent==heuristicSolution) {
> printf("value of solution is %g\n",model_->getObjValue());
> } else {
> return noAction; // carry on
> }
> }
see above
>
> Thanks!
>
> Alexis
>
> --
> Alexis Guigue, E.I.T., B.Eng., M.A.Sc., Ph.D.
> Software Engineer/Research Engineer
> 604-519-6222, ext. 107
>
> Softree Technical Systems Inc.
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.softree.com&d=CwMDaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=js2M0T-3OIMIVDvokcKjokJbk0F8QOCd0mT4FsVFE88&m=JW7jxzBRiPgrJcasWuWrK0kZrU1D4udLWpqagPpVbJc&s=WbbXokSFCnOnYzXBZhD9h4E2A01vgNt2NwPQvBErT8k&e=>
>
> Engineering an Easier Way
>
>
>
> _______________________________________________
> Cbc mailing list
> Cbc at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__list.coin-2Dor.org_mailman_listinfo_cbc&d=CwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=js2M0T-3OIMIVDvokcKjokJbk0F8QOCd0mT4FsVFE88&m=JW7jxzBRiPgrJcasWuWrK0kZrU1D4udLWpqagPpVbJc&s=HlOBrUOpfS4_ECFITp9Dm3uUNJz94iQ1OPfrqtmiv2o&e=
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20160918/b8aadd30/attachment.html>
More information about the Cbc
mailing list