Skip to content

Commit 62795e5

Browse files
seba-1511chsasank
authored andcommitted
Improved passage on immediates and their undefined behaviour. (pytorch#152)
* Added distributed tutorial. * Updated undefined behaviour when using immediates
1 parent 8ce8107 commit 62795e5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

intermediate_source/dist_tuto.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ return a ``DistributedRequest`` object upon which we can choose to
138138
# Receive tensor from process 0
139139
req = dist.irecv(tensor=tensor, src=0)
140140
print('Rank 1 started receiving')
141-
print('Rank 1 has data ', tensor[0])
142141
req.wait()
143142
print('Rank ', rank, ' has data ', tensor[0])
144143
145-
Running the above function might result in process 1 still having 0.0
146-
while having already started receiving. However, after ``req.wait()``
144+
When using immediates we have to be careful about with our usage of the sent and received tensors.
145+
Since we do not know when the data will be communicated to the other process,
146+
we should not modify the sent tensor nor access the received tensor before ``req.wait()`` has completed.
147+
In other words,
148+
149+
- writing to ``tensor`` after ``dist.isend()`` will result in undefined behaviour.
150+
- reading from ``tensor`` after ``dist.irecv()`` will result in undefined behaviour.
151+
152+
However, after ``req.wait()``
147153
has been executed we are guaranteed that the communication took place,
148154
and that the value stored in ``tensor[0]`` is 1.0.
149155

0 commit comments

Comments
 (0)