parallel-processing matplotlib标题位置 - 如何在Python中进行并行编程

plt.annotate用法 plt.title用法 (5)

``````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是两个独立的函数，这就是我想要平行的地方......

``````import ray

ray.init()

# Define the functions.

@ray.remote
def solve1(a):
return 1

@ray.remote
def solve2(b):
return 2

# Start two tasks in the background.
x_id = solve1.remote(0)
y_id = solve2.remote(1)

# Block until the tasks are done and get the results.
x, y = ray.get([x_id, y_id])
``````

1. 相同的代码将运行在多核机器以及一组机器上。
2. 进程通过共享内存和零拷贝序列化高效地共享数据。
3. 错误消息传播良好。
4. 这些函数调用可以组合在一起，例如，

``````@ray.remote
def f(x):
return x + 1

x_id = f.remote(1)
y_id = f.remote(x_id)
z_id = f.remote(y_id)
ray.get(z_id)  # returns 4
``````
5. 除了远程调用函数之外，类还可以作为actors远程实例化。

``````from multiprocessing import Pool
pool = Pool()
result1 = pool.apply_async(solve1, [A])    # evaluate "solve1(A)" asynchronously
result2 = pool.apply_async(solve2, [B])    # evaluate "solve2(B)" asynchronously
``````

``````args = [A, B]
results = pool.map(solve1, args)
``````

CPython使用全局解释器锁，这使得并行编程比C ++更有趣

``````import datetime
date_time = str(datetime.datetime.now())
date = date_time.split()[0]
time = date_time.split()[1]
``````