# How can multiple processes write to a tensor at the same time?

**URL:** <https://discuss.pytorch.org/t/how-can-multiple-processes-write-to-a-tensor-at-the-same-time/181394>\
**Category:** Uncategorized\
**Created:** [June 4, 2023, 3:32pm UTC](https://discuss.pytorch.org/t/how-can-multiple-processes-write-to-a-tensor-at-the-same-time/181394 "2023-06-04T15:32:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Lerman](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sam_lerman/32/37165_2.png) [@Sam\_Lerman](https://discuss.pytorch.org/u/Sam_Lerman)\
**Post date:** [June 4, 2023, 3:32pm UTC](https://discuss.pytorch.org/t/how-can-multiple-processes-write-to-a-tensor-at-the-same-time/181394/1 "2023-06-04T15:32:00Z")

</div>

Can I use \_share\_memory() and just write to different indices:

`tensor = torch.randn([5,5])._share_memory()`

And then from multiple processes:

`tensor[process_id] = process_id`

Is there a better way involving all\_reduce or something? I want non-blocking writes, as in just hogwild writes from multiple processes in parallel.
