I have been experimenting with coarrays in the context of the Euler conjecture tutorial (see Euler Sum of Powers Conjecture: Tutorial). One thing that is part of the sample programs is that the program stops after a certain number of solutions has been found (or else continues until all candidates have been examined). This is easy enough when using a sequential program and I have a working version that does so with coarrays. However, I have so far been forced to check the condition to stop using image 1:
outer: do i = imax1, imax2
!
! Check if we need to continue
!
if ( nfound[1] >= findmax ) then
write(*,*) 'Enough solutions found ', this_image()
exit outer
endif
... search for solutions ...
The outer loop is run by all images and the bounds imax1 and imax2 differ per image. The drawback: a lot of communication between image 1 and the others and the rtimings are very erratic, but in general it is not faster than the sequential version.
I have tried setting the nfound variable in all images when a solution is found, so that the combination is very limited. But that does not seem to work. I alos tried with atomic variables and subroutines, but that is the same story.
My question is therefore condensely formulated as this:
I have a program that examines a lot of independent cases and stops once a certain number of solutions have been found. What is the best way to implement this using coarrays?