int MPE_Counter_nxtval(MPI_Win counterWin, int counterNum, int *value) { const int one = 1; int lrank, flag, size, *attrval; MPI_Aint lidx; /* Compute the location of the counter */ MPI_Win_get_attr(counterWin, MPE_COUNTER_KEYVAL, &attrval, &flag); if (!flag) return -1; /* Error: counterWin not correctly setup */ size = (MPI_Aint)attrval; /* We stored the integer as a pointer */ lrank = counterNum % size; lidx = counterNum / size; /* Update and return the counter */ MPI_Win_lock(MPI_LOCK_SHARED, 0, lrank, counterWin); MPI_Fetch_and_op(&one, value, MPI_INT, lrank, lidx, MPI_SUM, counterWin); MPI_Win_unlock(lrank, counterWin); return 0; }