如何解决Ray 只使用两个线程?
我写的
@ray.remote
def check(word,words):
valid_ciphertexts = []
for key in range(26):
ciphertext = shift(word,key)
if ciphertext in words:
valid_ciphertexts.append(ciphertext)
else:
valid_ciphertexts.append(None)
return valid_ciphertexts
if __name__ == '__main__':
words = set()
with open(sys.argv[1],'r') as lexicon:
for word in lexicon:
words.add(word.strip())
ray.init()
results = ray.get([check.remote(word,words) for word in words])
with open(sys.argv[2],'w',newline='') as f:
writer = csv.writer(f)
writer.writerow([key for key in range(26)])
writer.writerows(results)
由于并行处理了对 check
的数十万次调用,我原以为所有内核的使用率都会很高,但仪表板却显示了这一点:
为什么会这样?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。