Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

EVENT POST and EVENT WAIT

Statements: The EVENT POST statement allows an image to notify another image that it can proceed to work on tasks that use common resources. The EVENT WAIT statement allows an image to wait on events posted by other images. They take the following forms:

EVENT POST (event-var [, sync-stat-list])

EVENT WAIT (event-var [, wait-spec-list])

event-var

Is a scalar variable of type EVENT_TYPE. For more information, see intrinsic module ISO_FORTRAN_ENV.

It must not depend on the value of stat-var or err-var.

It cannot be a coindexed variable in an EVENT WAIT statement.

sync-stat-list

Is STAT=stat-var

or ERRMSG=err-var

stat-var

Is a scalar integer variable in which the status of the synchronization is stored.

err-var

Is a scalar default character variable in which explanatory text is stored if an error occurs.

wait-spec-list

Is until-spec

or sync-stat-list

until-spec

Is UNTIL_COUNT= scalar-integer-expression.

Each specifier is optional and may appear at most once in a sync-stat-list or in a wait-spec-list.

Description

An EVENT POST statement atomically increments the value of event-var by one. Its value is processor dependent if an error condition occurs during the execution of an EVENT POST statement. The completion of an EVENT POST statement does not in any way depend on execution of a corresponding EVEN WAIT statement.

The following actions occur during the execution of an EVENT WAIT statement:

  • If UNTIL_COUNT is not specified, the threshold value is one; otherwise, it is the maximum value of one and the specified scalar-integer-expression.

  • The image executing the EVENT WAIT statement waits until the value of event-var is equal to or greater than the threshold value; otherwise, an error condition occurs.

  • If no error condition has occurred, event-var is atomically decremented by the threshold value.

The value of event-var is processor dependent if an error condition occurs during the execution of an EVENT WAIT statement.

An EVEN POST statement execution is initially unsatisfied. The successful execution of an EVENT WAIT statement with a threshold value of n satisfies the first n unsatisfied EVENT POST statement executions for the specified event-var. The EVENT WAIT statement delays execution of the segment following the EVENT WAIT statement to execute after the segments which precede the first n EVENT POST statement executions for the specified event-var.

Example

The following example shows the use of EVENT POST and EVENT WAIT statements to synchronize each image with its left and right neighbor. Image 1 and image NUM_IMAGES() treat each other as left and right neighbors, conceptually laying the images out in a circle.

USE, INTRINSIC    :: ISO_FORTRAN_ENV
TYPE(EVENT_TYPE)  :: EVENT[*]
INTEGER           :: LEFT, RIGHT
...
IF ((THIS_IMAGE().NE. 1) .AND. (THIS_IMAGE() .NE. NUM_IMAGES()) THEN
  LEFT  = THIS_IMAGE() – 1
  RIGHT = THIS_IMAGE() + 1
ELSE IF (THIS_IMAGE() == 1) THEN
  LEFT  = NUM_IMAGES()
  RIGHT = 2
ELSE IF (THIS_IMAGE()== NUM_IMAGES()) THEN
  LEFT  = NUM_IMAGES() - 1
  RIGHT = 1
END IF 

EVENT POST (EVENT[LEFT])            ! Signal left neighbor you got here
EVENT POST (EVENT[RIGHT])           ! Signal right neighbor you got here
EVENT WAIT (EVENT, UNTIL_COUNT = 2) ! Wait until your neighbors have both reached this point also