On May 6, 1:22 pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
wrote:
Philipp <djb...@gmail.com> wrote:
public void increment(int x, int y){
// System.out.println("Increm " + x + " " + y);
try{
// locking the 2 x 2 region
for(int i = x; i < x + FRAGMENT_SIZE; i++){
for(int j = y; j < y + FRAGMENT_SIZE; j++){
int indexI = i % LATTICE_X_SIZE; // wrap around
int indexJ = j % LATTICE_Y_SIZE;
Oh, you've got a wraparound here! Caution, Danger ahead!
Namely: danger of dining philosopher's lockup.
You are absolutely right, thanks for spotting that!
I think the lockup can only happen if the number of threads NT >=
LATTICE_X_SIZE / (FRAGMENT_SIZE-1) respectively in the Y direction,
whatever is smaller. If the number of threads is below this, my
proposal should not lock. (ie. there's a philosopher missing at the
dinner table).
You'll have to use two loops, one for those cases where
"x >= LATTICE_X_SIZE - FRAGMENT_SIZE"
that will deal with the wrapped part of the fragment,
and another one for the normal case, clipping rather than
wrapping on overflow.
Yes, that would be the more general solution.
branches, is to make the array a bit bigger than the real size. Add a
changing LATTICE_X_SIZE or LATTICE_Y_SIZE.