简体   繁体   English

PuLP CBC多线程不适用于COIN_CMD

[英]PuLP CBC multithreading not working with COIN_CMD

I am using PuLP with Python to do some optimization and because my data is so large, I decided to try multithreading as my problem is quite large, ie choosing 我正在使用PuLP和Python进行一些优化,并且由于我的数据很大,所以我决定尝试多线程,因为我的问题很大,即选择

However, in testing with a small subset of the main problem (10k instead of 1M people), I cannot get multithreading to actually use multiple threads. 但是,在测试主要问题的一小部分(10k而不是1M的人)时,我无法获得多线程来实际使用多个线程。

I followed the instructions to build the solver from source using the ../configure --enable-cbc-parallel flag as described on Coin-OR website ; 我按照说明使用Coin-OR网站上描述../configure --enable-cbc-parallel标志从源代码构建求解器; everything worked great and all the tests passed. 一切正常,所有测试都通过了。 I checked the CBC config log in build/Cbc/config.log and it has the message configure:30105: Cbc multithreading enabled in line 845, so it definitely is enabled to work. 我检查了build/Cbc/config.log的CBC配置日志,它显示了消息configure:30105: Cbc multithreading enabled第845行中configure:30105: Cbc multithreading enabledconfigure:30105: Cbc multithreading enabled ,因此肯定可以工作。

System: 系统:

  • Mac OS X 10.14.3 Mac OS X 10.14.3
  • i7-4870HQ quad-core i7-4870HQ四核
  • Python 3.6.7 w/Anaconda 带有Anaconda的Python 3.6.7
  • problem occurs both in Jupyter and running in Python interpreter from the command line 从命令行在Jupyter和Python解释器中都出现问题

Code, similar to from example here : 代码,类似于此处的示例

start = time.time()
solver = solvers.COIN_CMD(~/Cbc-2.9/build/Cbc/src/cbc',threads=8,msg=1,fracGap = 0.01)
prob.solve(solver)
print('time to solve:',time.time()-start,'seconds')

>> time to solve: 24.815305948257446 seconds

That time was about the same if I specified the multi-threaded solver or if I just used the default solver. 如果我指定了多线程求解器,或者我只是使用默认的求解器,那么那段时间差不多。

In the CBC message at runtime was the line: 运行时在CBC消息中显示以下行:

threads was changed from 0 to 8

and also the lines: 以及以下行:

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
Cbc0001I Search completed - best objective -25507, took 0 iterations and 0 nodes (18.29 seconds)

which means that all the threads were created, but not used? 这意味着所有线程都已创建但未被使用?

One solution that I've thought of but don't know how to solve: maybe my path to the solver is wrong, ie the COIN_CMD solver shouldn't be directed to .../cbc but to something else. 我想到但不知道如何解决的一个解决方案:也许我通往求解器的路径是错误的,即COIN_CMD求解器不应定向到.../cbc而应定向到其他目标。 I haven't found anything on that. 我还没找到任何东西。

So what am I doing wrong? 那我在做什么错? I couldn't find any other documentation on how to use the threads. 我找不到其他有关如何使用线程的文档。 Hopefully this is a stupid question with an easy solution. 希望这是一个愚蠢的问题,并且有一个简单的解决方案。 Thanks for your help. 谢谢你的帮助。

Looks all the work was done during preprocessing. 看起来所有工作都是在预处理过程中完成的。 Parallel threads only kick in during the branch-and-bound phase, after preprocessing. 并行线程仅在预处理之后的分支定界阶段才起作用。 Try a model or dataset where CBC has to do some real branching. 尝试模型或数据集,其中CBC必须做一些实际的分支。 Ie where the number of nodes is significant. 也就是说,节点数很大。 For most larger MIP models, CBC will need to explore a large number of nodes. 对于大多数大型MIP模型,CBC将需要探索大量节点。 In that case parallel threads can make a difference. 在这种情况下,并行线程可能会有所作为。 But in some cases it may also lead to worse performance (see link ). 但是在某些情况下,它也可能导致性能下降(请参阅链接 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM