
4.8. EXAMPLE: TRANSFORMING AN ADJACENCY MATRIX 99
We then call rollmean() on this thread’s chunk, and write the results into
this thread’s section of mas:
mas [ 1 , m y f i r s t : mylast ] <−
rollmean ( x [ m y f i r s t : ( mylast+k −1)] , k )
When all the threads are done executing the above line, we will be ready
to combine the results. But how will we know when they’re done? That’s
where the barrier comes in. We call barr() to make sure everyone is done,
and then designate one thread to then combine the results found by the
threads:
barr ( ) # make s u r e a l l t h r e a d s have w r i t t e n to mas
i f ( myinfo$ i d == 1) {
r s l t s [ 1 , 1 ]