[英]multiprocessing and python code
the execution of my python code is too slow, I have 7 processors and python uses only one, I just discovered the multiprocessing option but I have no idea how to use it, so could you modify my following code using this option? 我的python代码执行速度太慢,我有7个处理器,而python只使用一个,我刚刚发现了multiprocessing选项,但是我不知道如何使用它,所以您可以使用此选项修改以下代码吗?
from itertools import combinations
def New5(A,C5):
d=True
for a in A:
if(d==True):
d=(a not in C5)
return d
def refcomb10(h):
T=[]
C5={0}
b=0
C10=combinations(range(h),10)
for S in C10:
A=combinations(S,5)
if(New5(A,C5)):
A=combinations(S,5)
for a in A:
C5.update({a})
T.append(S)
b+=1
print(b,S)
return([T,C5])
U=refcomb10(60)
Excuse my english 打扰一下我的英语
You probably don't need to multithread to fix your performance problem. 您可能不需要多线程来解决性能问题。 These improvements may be more helpful:
这些改进可能会更有用:
print(b,S)
print(b,S)
A=combinations(S,5)
, if possible A=combinations(S,5)
删除第二个A=combinations(S,5)
replace 更换
for a in A: C5.append(a)
with 与
C5.extend(A)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.