我想将元素列表放入共享内存中。代码(main.py
)如下。
import torch
if __name__=='__main__':
mylist = []
list_len = 10000
for i in range(list_len):
element = torch.randn(10)
mylist.append(element)
for element in mylist:
element.share_memory_()
问题是,当我从命令行运行“ python main.py
”时,它会输出以下错误
Traceback (most recent call last):
File "main.py", line 9, in <module>
File "/home/rozyang/anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 217, in share_memory_
File "/home/rozyang/anaconda3/lib/python3.6/site-packages/torch/storage.py", line 104, in share_memory_
RuntimeError: unable to open shared memory object </torch_1543_4219316339> in read-write mode at /opt/conda/conda-bld/pytorch_1524590031827/work/aten/src/TH/THAllocator.c:342
但是,当我在PyCharm中运行相同的代码时,没有错误出现。我检查了PyCharm是否使用了相同的python解释器和相同的PyTorch。
如果我将“ list_len=10000
”更改为“ list_len=100
”,则命令行“ python main.py
”也将起作用。
所以我想知道是否可以设置共享内存大小(即共享变量的数量)。非常感谢解决此问题的任何提示!
P.S。我正在使用蟒蛇python 3.6和pytorch 0.4.0