Multithreading with CBC

4,457 views
Skip to first unread message

Syed Taha Munir

unread,
Mar 25, 2015, 1:06:24 PM3/25/15
to pulp-or...@googlegroups.com
When i run the solver with this statement.
 
prob.solve(PULP_CBC_CMD(fracGap=0.01,threads=2,msg=1)) it always gives me that output on screen.
 
Coin0008I MODEL read with 0 errors
No match for threads - ? for list of commands
No match for 2 - ? for list of commands
ratioGap was changed from 0 to 0.01
 
Should i use the updated version of CBC ?
 
I want to use more threads for solving my problem.

Stuart Mitchell

unread,
Mar 25, 2015, 5:03:17 PM3/25/15
to pulp-or...@googlegroups.com
CBC has to be compiled specially to support multi-threading.

If you want to use this option I suggest you compile cbc yourself and use the COIN_CMD solver.

Stu

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Stuart Mitchell

unread,
Mar 25, 2015, 5:04:29 PM3/25/15
to pulp-or...@googlegroups.com
Also if you just want a speed up, try downloading the development version from github. I should be releasing this this week after I test on windows.

Stu

Syed Taha Munir

unread,
Mar 26, 2015, 3:57:46 AM3/26/15
to pulp-or...@googlegroups.com
Hi stu
Thanks for reply
Have you used new version of CBC in the development version?
How can i compile COIN_CMD solver my self and use it with pulp, I am sure you must have answered this to someone already in the group :) , if you could just point out the discussion , it will be a favor
 
 kind regards
Taha

Stuart Mitchell

unread,
Mar 26, 2015, 5:10:11 PM3/26/15
to pulp-or...@googlegroups.com
Are you on Windows or OSX/ Linux?

Linux is fairly straight forward, with Windows it is complicated.

Look at the CBC webpage on coin-or.org for a discussion on how to compile. Once you have done that add it to the path and COIN_CMD will just work.

Development on github uses uptodate (single threaded) cbc.

Stu

Syed Taha Munir

unread,
Mar 27, 2015, 4:57:12 AM3/27/15
to pulp-or...@googlegroups.com
Hi Stu
 
Unluckily I am using Windows :( .

Syed Taha Munir

unread,
Mar 31, 2015, 8:35:39 AM3/31/15
to pulp-or...@googlegroups.com
Hi Stu
i just wanted to know when are you releasing new  version of Pulp?
 
kind regards
Taha

Stuart Mitchell

unread,
Mar 31, 2015, 5:53:48 PM3/31/15
to pulp-or...@googlegroups.com
Done it is on PyPI now :-)

Please test.

Neil Wang

unread,
Jun 8, 2018, 7:34:18 PM6/8/18
to pulp-or-discuss
Hi Stuart,

I am currently using CBC-2.9.9 and I would like to use multi-threading feature of in on Linux. I have recompiled with --enable-parallel argument passed in. In cbc command line, I can specify 4 threads, and it shows "change threads from 0 to 4", but when I ran the model, the system only showed 1 core working.

Could you show me a way to solve this problem, please? Thank you so much

Stuart Mitchell

unread,
Jun 10, 2018, 5:51:25 PM6/10/18
to pulp-or...@googlegroups.com
I would email this to the cbc list if I were you.

Stu

Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.

J. Friedman

unread,
Jan 8, 2019, 9:53:44 PM1/8/19
to pulp-or-discuss
Like this

m.solve(solvers.COIN_CMD(maxSeconds=400,threads=4,msg=1,fracGap = 0.0))

Matthew Pearlson

unread,
Jan 28, 2019, 12:36:16 PM1/28/19
to pulp-or-discuss
I'm glad there is some more discussion on multi-threading. I am working on a project that I think would benefit from multiprocessing.

Russell Romney

unread,
Feb 17, 2019, 6:32:19 PM2/17/19
to pulp-or-discuss
Thanks for your answers. I am trying to do a similar thing: I have compiled from source, used the path to the solver, and specified that threads should be used, but when I run it like above the threads are created but not used. 

This looks like:

threads was changed from 0 to 8

Cbc0012I Integer solution of -25507 found by DiveCoefficient after 0 iterations and 0 nodes (18.04 seconds)
Cbc0030I Thread 0 used 0 times,  waiting to start 0.291008, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 1 used 0 times,  waiting to start 0.24997687, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 2 used 0 times,  waiting to start 0.21034408, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 3 used 0 times,  waiting to start 0.17122722, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 4 used 0 times,  waiting to start 0.13530493, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 5 used 0 times,  waiting to start 0.098966837, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 6 used 0 times,  waiting to start 0.062871933, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Thread 7 used 0 times,  waiting to start 0.028151035, 0 cpu time, 0 locks, 0 locked, 0 waiting for locks
Cbc0030I Main thread 0 waiting for threads,  1 locks, 0.00077700615 locked, 9.5367432e-07 waiting for locks

Also, the build/Cbc/config.log includes a line about multithreading being enabled, and I'm using a 4-core MBP so it's not a CPU issue. Any ideas about how to solve this? @J or @stu

Stuart Mitchell

unread,
Feb 17, 2019, 6:33:56 PM2/17/19
to pulp-or...@googlegroups.com
Try a larger problem, this example looks like it was solved by the presolve so no other threads were needed.

Stu
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---

David

unread,
Feb 19, 2019, 5:52:20 PM2/19/19
to pulp-or-discuss
Hi Stuart,

Building CBC threaded as discussed above appears to thread CBC so an instance of an optimisation can be parallelised across multiple threads.

Can I parallelise at the pulp level? By this I mean instantiate multiple instances of an optimisation within a process with perhaps different coefficient values for one or more decision variables. I'll confess that while I've done a lot of work with parallelising C++ programs across multiple cores/CPUs I haven't parallelised a python application so that part is new to me. Also new to me would be parallelising pulp if that's supported.

Thanks

David

Stuart Mitchell

unread,
Feb 19, 2019, 5:53:47 PM2/19/19
to pulp-or...@googlegroups.com
If you have a long build time there are probably ways to speed that up.

Unfortunately it is difficult to multi thread model build.

Stu
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

David

unread,
Feb 19, 2019, 6:34:31 PM2/19/19
to pulp-or-discuss
Hi Stuart,

Apologies for not being more clear. I wasn't referring to parallelising the model build specifically but rather having multiple instances of pulp optimisations running simultaneously. I think this could be done a job parallelisation by instantiating separate Python environments for each pulp optimisation but this is expensive in terms of repeated code and memory. What would be great is parallelising Pulp/CBC as per what you get using OpenMP with C++ on Linux boxes.

If CBC can be built thread-safe then this can be shared amongst multiple optimisations. Python as I understand it has a serial bottleneck at the interpreter. I noticed a multiprocessing Python capability that adds some possibly relevant  capability to Python but I need to spend some more time on that. What would be very handy is to parallelise at the pulp model level with threadsafe data and code. I've used the Intel HPC profiling and analysis toolkit quite a bit on C++ code. I think Intel are supporting Python to some extent now but I'm not sure if their thread analysis tools work on Python code.

Bye for now

David

Stuart Mitchell

unread,
Feb 19, 2019, 6:49:15 PM2/19/19
to pulp-or...@googlegroups.com
Multiprocessing is what you want then.

Just remember that if you use multiprocessing from your script make sure to add an


#place function defs here
if __name__ == "__main__":
      #place script code here

structure to your code

Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

David

unread,
Feb 19, 2019, 8:35:47 PM2/19/19
to pulp-or-discuss
Thanks, Stuart.

Has anyone had a crack at running multiple pulp sessions with the Python multiprocessing facility? Be very interested in any lessons learnt

David

Franco Peschiera

unread,
Mar 27, 2019, 6:28:10 PM3/27/19
to pulp-or-discuss
Ok, so even though I'm 4 years late to this thread...

In case windows users don't want to struggle with the horrible task of compiling things, the ampl site has 64-bit binaries for CBC. I've tried to use the windows one with the pulp option of threads=4 and it worked.
Also, Linux binaries are available.
The CBC version is 2.9.7 so not the newest.

regards,

Franco


El jueves, 26 de marzo de 2015, 14:10:11 (UTC-7), Stuart Mitchell escribió:
Are you on Windows or OSX/ Linux?

Linux is fairly straight forward, with Windows it is complicated.

Look at the CBC webpage on coin-or.org for a discussion on how to compile. Once you have done that add it to the path and COIN_CMD will just work.

Development on github uses uptodate (single threaded) cbc.

Stu
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.

To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.

Matthew Pearlson

unread,
May 31, 2019, 9:52:35 AM5/31/19
to pulp-or-discuss
Thanks Franco. I downloaded the binaries, but no joy with multithreading.

We are calling the CBC solver from a module that imported to our main python script.

Can anyone explain how to handle the if __name__ = "__main__"  in this case?

I saw a forum posts on "Singleton Command", but it wasn't clear what the syntax was.
Thanks! Matthew

Franco Peschiera

unread,
Jun 10, 2019, 8:25:11 AM6/10/19
to pulp-or...@googlegroups.com

Hey Matthew,

I’m sorry. I thought I had it working at some point but upon other tests I was not able to replicate. I haven’t retried.

As long as you pass pulp the explicit, complete path to the good CBC executable when initializing the solver, it doesn’t care how you call pulp or from where. If you use COIN_CMD you require to give it the explicit path to CBC. In PULP_CBC_CMD, pulp uses the CBC that comes inside pulp.

F.

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
You received this message because you are subscribed to a topic in the Google Groups "pulp-or-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pulp-or-discuss/IKE--kT6c5U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pulp-or-discu...@googlegroups.com.

To post to this group, send email to pulp-or...@googlegroups.com.

daG ee

unread,
Jun 16, 2019, 6:30:10 PM6/16/19
to pulp-or-discuss
Wow, thank you for that link! It somehow worked (with the command line in the same folder, where the exe is). The output says, that "threads was changed from 0 to 5"..
Now I've got a problem, that IF I change the threads within a script, then sometimes the run stops/does not finish.. but thats another topic I guess.

But that link was great, Franco!
Reply all
Reply to author
Forward
0 new messages