我刚刚遇到了一个关于凸优化的cvxopt package的问题,我在documentation中没有提到这个问题。我不知道有没有人知道是什么原因造成的,以及如何最好地解决它。在
问题是,当您在使用^{import cvxopt
时,这些进程不能再并行运行。它们似乎自动同步。请注意,无论程序是否实际使用了cvxopt
函数,都会发生这种情况。简单地导入包就会产生这种效果。在
示例:
# import cvxopt
from multiprocessing import Queue, Process
def compute(queue):
"""
Pick integers from a queue and perform some useless
calculations on them just to keep the CPU busy.
"""
total = 0
while True:
item = queue.get()
if item is None:
break
for i in range(item):
total += i
if __name__ == '__main__':
queue = Queue()
procs = []
for i in range(4):
proc = Process(target = compute,
args = (queue,))
proc.start()
procs.append(proc)
for i in range(100000):
queue.put(i)
for proc in procs:
queue.put(None)
for proc in procs:
proc.join()
上面的脚本启动与主程序并行运行的四个进程。在一台有四个核心的机器上,我有四个进程,每个进程占用100%的CPU。在
但是,当在开始时取消对import cvxopt
语句的注释时,每个进程最终只占用25%的CPU,就像它与其他进程同步一样。在
我对解释和解决办法都感兴趣。如果文档中有我忽略的明显解释,我很抱歉。在
有关如何重现问题的详细信息
我运行它的环境是Linux3.5.0(Ubuntu12.10发行版)和Python3.2.3。我是这样安装cvxopt的:
安装matplotlib 1.2.1(我这样做是因为它包含pylab,pylab在许多cvxopt示例脚本中都使用。我不确定这是否是实际要求)。我用了this tar.gz package安装了它。
已安装BLAS和ATLAS
^{pr2}$以上可能是非常必要的,但我会惊讶,如果这造成任何问题。
已安装cvxopt 1.1.6,使用焦油gz包from here和sudo python3 ./setup.py install
。
也许是因为pythongil没有发布?在
参见:http://comments.gmane.org/gmane.comp.python.scientific.user/15678
相关问题 更多 >
编程相关推荐