PuLP CBC 多线程不适用于 COIN_CMD

PuLP CBC multithreading not working with COIN_CMD

我正在使用 PuLP 和 Python 来做一些优化,因为我的数据太大了,我决定尝试多线程,因为我的问题非常大,即选择

但是,在测试主要问题的一小部分(10k 而不是 1M 人)时,我无法让多线程实际使用多个线程。

我关注了the instructions to build the solver from source using the ../configure --enable-cbc-parallel flag as described on Coin-OR website;一切都很好,所有测试都通过了。我检查了 build/Cbc/config.log 中的 CBC 配置日志,它在第 845 行中有消息 configure:30105: Cbc multithreading enabled,所以它肯定可以工作。

系统:

代码,类似于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

如果我指定多线程求解器或者如果我只使用默认求解器,那时间是差不多的。

在运行时的 CBC 消息中有一行:

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

这意味着所有线程都已创建,但未使用?

我想到但不知道如何解决的一个解决方案:也许我的求解器路径是错误的,即 COIN_CMD 求解器不应该指向 .../cbc但对别的东西。我还没有找到任何相关信息。

那我做错了什么?我找不到关于如何使用线程的任何其他文档。希望这是一个简单的解决方案的愚蠢问题。感谢您的帮助。

看起来所有工作都已在预处理期间完成。并行线程仅在预处理后的分支定界阶段启动。尝试一个模型或数据集,其中 CBC 必须做一些真正的分支。 IE。其中节点数很重要。对于大多数较大的 MIP 模型,CBC 将需要探索大量节点。在那种情况下,并行线程会有所作为。但在某些情况下,它也可能导致性能下降(参见 link)。