首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Python中进行并行编程?

如何在Python中进行并行编程?
EN

Stack Overflow用户
提问于 2013-12-13 00:19:17
回答 4查看 283.8K关注 0票数 167

对于C++,我们可以使用OpenMP进行并行编程;但是,OpenMP不适用于Python.如果我想并行我的python程序的某些部分,我应该怎么做?

代码的结构可以被认为是:

代码语言:javascript
复制
solve1(A)
solve2(B)

其中solve1solve2是两个独立的函数。如何并行运行这类代码,而不是按顺序运行,以减少运行时间?代码是:

代码语言:javascript
复制
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

其中setinnersetouter是两个独立的函数。这就是我想要比较的地方。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20548628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档