concept event wait in category fortran

appears as: event wait
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

You can read this diagram in any order. An alert event is an instance of event_type. Image 1 triggers the alert on image 2 by issuing event post(alert[2]). This statement is nonblocking, which means that image 1 can immediately move on with whatever code follows. All instances of event_type keep count of posted events internally. This count is incremented on every event post statement, from any image. Image 2 issues event wait(alert). This is a blocking statement, which means that image 2 will wait until the alert is posted. When it finally happens, event wait decrements the internal event count. Alternatively, image 2 can also poll the number of alerts in a nonblocking fashion with the built-in subroutine event_query.

In a nutshell, event wait blocks the image that executes it until some other image posts an event to it. If until_count is provided and greater than 1, the image will wait until that many events have been posted. On successful execution of event wait, the internal event count is decremented by until_count, if provided, and by 1 otherwise. For example, this statement:

event wait(notification, until_count=100)

blocks the executing image until 100 events have been posted to the notification variable from any other image. Once executed, the internal event count is decremented by exactly 100. Note that this doesn’t mean that the event count is always reduced to zero, because remote event posts can keep incrementing the event count before event wait has time to return.

Using event wait together with the until_count parameter allows you to not block on every posted event, but only on some number of events. However, it also illustrates a restriction to event wait: it’s impossible for the image that listens for events to know how many have been posted without explicitly blocking execution with event wait. This is indeed rather limiting. To poll events without blocking the current image, Fortran provides a built-in subroutine event_query, which we’ll explore in the next subsection.