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 的数十万次调用,我原以为所有内核的使用率都会很高,但仪表板却显示了这一点:

enter image description here

为什么会这样?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)