我有两个职能。功能2取决于功能1。我想先并行运行function1,然后将function1中的值转换为function2,以并行运行function2。
import multiprocessing as mp
global x
def f1(x):
print(x*x)
def f2(y):
print(y*x)
def main():
pool = mp.Pool(mp.cpu_count()) #number of cores in computer
pool.map(f1, [1,2])
pool.map(f2, [3,4])
if __name__ == "__main__":
main()
预期结果:
1
4
3
8