I don't think this is possible without additional synchronization ... unless you don't mind if you lose some updates.
The barrier inside the while loop could be a problem. Assume the counter has a value of MAX_SUM-2, core A increments it to MAX_SUM-1 and reenters the barrier, just before the increment of core B. Core B would then continue with the code following the loop.
Also, I would suggest to initialize the counter right after allocation, for example:
if (ID == 0) *ptr = 0; RCCE_barrier(&RCCE_COMM_WORLD);
I agree with Andreas; you need to initialize
ptrbefore using it.
Then, you compare
*ptr(an integer) with
NULL, hence you simply compare the value of the pointer with 0. Is this what you wanted to do?
Moreover, as Andreas mentioned, since you use the barrier combined with conditional on the
ID, your cores will not synchronize as intended.
Finally, I suggest your use a barrier after the shmem allocation and initialization, or else the second initialization may erase some work from the other core.