I was discussing yesterday with @milancurcic about event post
and event_query
in a parallel Fortran 2018 application. I have made good progress today although a little problem still remains.
I have pushed a new gtk-fortran example demonstrating how it can be used with parallel computing features of f2008 & f2018:
https://github.com/vmagnin/gtk-fortran-extra/tree/main/parallel_app
Each Fortran image is computing a Buddhabrot and they are regularly summed with co_sum()
before being displayed in the GTK window. The parallel computing is running fine with ifort 2021.6.0 and GFortran 11.2.0 + OpenCoarrays 2.10.0 under Ubuntu 22.04.
The problem occurs when I close the GTK window which is managed by image 1. The callback function destroy_signal()
(at the top of GUI_and_computation.f90
) sends a message to other images:
if (num_images() >= 2) then
do i = 2, num_images()
event post(stop_notification[i], STAT=status)
print '(A, I3, A, I3)', "Image 1 sending event post stop_notification to", i, " status=", status
end do
end if
Toward the bottom of the same file, each image looks if there is a stop message and exits the computation if there is one:
call event_query(stop_notification, counter)
print '(A, I3, A, I3)', "I am image", this_image(), " ; event counter", counter
if (counter /=0) exit computation
It seems to work as this is the end of main.f90
:
print '(A, I3, A)', "I am image", this_image(), " at end program"
sync all
print '(A, I3, A)', "I am image", this_image(), " and I am after sync all"
end program Parallel_Buddhabrot
and I have those messages printed for 4 images:
Image 1 sending event post stop_notification to 2 status= 0
I am image 2 ; event counter 1
I am image 2 at end program
Image 1 sending event post stop_notification to 3 status= 0
Image 1 sending event post stop_notification to 4 status= 0
I am image 1 at end program
I am image 1 and I am after sync all
I am image 2 and I am after sync all
sync all: 4
sync all: 3
I am image 4 ; event counter 1
I am image 4 at end program
I am image 3 ; event counter 1
I am image 3 at end program
I am image 3 and I am after sync all
I am image 4 and I am after sync all
The problem is that the images are still running, and even burning the CPU… I have tried many things, but the problem remains. I don’t know if it is a Fortran problem or maybe a linking problem with GTK. Anyway it is strange it burns the CPU as the scientific computation is finished and we are at end program
.