
104 CHAPTER 4. SHARED MEMORY: R
all the threads will be making use of the cumulative sums, and we need to
be sure those sums are ready first. These are typical examples of barrier
use.
Now that our thread knows where in lnks to write its results, it can go
ahead:
mystart <− i f (me == 1 ) 1 else c o unts [ 1 , me−1] + 1
myend <− mystart + nmyedges − 1
l n k s [ mystart : myend , ] <− tmp
4.8.2 Overallocation of Memory
A problem above is having to allocate the lnks matrix to handle the worst
case, thus wasting space and execution time. The problem is that we don’t
know in advance the size of our “output,” in this case the argument lnks.
In our little example ...