Previous | Next --- Slide 43 of 48
Back to Lecture Thumbnails
Aarow

Are these tradeoffs most of the reason why there isn't a compiler to convert generic complex programs into parallel programs? Or are there another more fundamental reasons?

gryffolyon

why have a used an array of 3 elements? Why cant an array with 2 elements work? I feel we can still do a %2 instead of a %3 and still achieve what we are currently doing here.

andymochi

@gryffolyon Pretty sure the choice was arbitrary here.

I think some number > 2 is generally chosen in parallel work examples because it models more scenarios you encounter with unspecified execution order. But you're right, in this particular case, that doesn't really apply.

andymochi

@gryffolyon I was wrong, with this code the choice isn't arbitrary. As he mentioned in lecture today - one thread could pre-empt and overwrite diff[(index+1)%2] before another thread has a chance to check it.

But he did say that there might be an implementation with a 2 element array.

***Edit: probably could -> might

kayvonf

@andymochi. Don't quote me on "probably". ;-) I only claimed I didn't come up with one in the time I worked on it. Given this code structure I believe you need three variables since the code needs to be able to read diff[index] from the (current) iteration A, accumulate into diff[index+1] for iteration B, and also be clearing diff[] for iteration C. But one might be able to restructure the code so this isn't necessary.

andymochi

@kayvonf Haha... I was struggling with words when I wrote this. Oopsy.