对于C++,我们可以使用OpenMP进行并行编程;但是,OpenMP不适用于Python.如果我想并行我的python程序的某些部分,我应该怎么做?
代码的结构可以被认为是:
solve1(A)
solve2(B)
其中solve1
和solve2
是两个独立的函数。如何并行运行这类代码,而不是按顺序运行,以减少运行时间?代码是:
def solve(Q, G, n):
i = 0
tol = 10 ** -4
while i < 1000:
inneropt, partition, x = setinner(Q, G, n)
outeropt = setouter(Q, G, n)
if (outeropt - inneropt) / (1 + abs(outeropt) + abs(inneropt)) < tol:
break
node1 = partition[0]
node2 = partition[1]
G = updateGraph(G, node1, node2)
if i == 999:
print "Maximum iteration reaches"
print inneropt
其中setinner
和setouter
是两个独立的函数。这就是我想要比较的地方。
https://stackoverflow.com/questions/20548628
复制相似问题