Problems with coarrays

This is your problem. You’re having each image update every value, with no synchronization and not atomically. Thus, some values may not be correctly updated.

Also, since there is no barrier between this loop and the previous print statement, some images may be updating the value before other images have a chance to print it.

The suggestions from others should give some clues as to how to fix these problems.