I want to put the elements in a list to shared memory. The code (main.py) is as follows.
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_()
The problem is that, when I run “python main.py” from command line, it outputs the following error
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
However, no error appears when I run the same code in PyCharm. I have checked that PyCharm is using the same python interpreter and same pytorch.
If I change “list_len=10000” to “list_len=100”, the command line “python main.py” also works.
So I am wondering where there is somewhere I can set the shared memory size (i.e. the number of shared variables). Many thanks to any hints to solve this!
P.S. I am using anaconda python 3.6 and pytorch 0.4.0