# FAIL IMAGE

Statement: Causes the image that executes it to stop participating in program execution, without initiating termination.

FAIL IMAGE

This statement allows you to simulate image failure and to test and debug image failure recovery in a program, without requiring an actual image failure.

After execution of a FAIL IMAGE statement, no additional statements are executed by the image.

A FAIL IMAGE statement is not an image control statement.

The detection of a failed image may happen at different times in the execution of other images; for more information, see FAILED_IMAGES.

### Note

If you use a FAIL IMAGE statement to make an image fail, you should use a STAT= specifier or a STAT argument in all coarray operations that might encounter that failed image if the statement or operation permits, or you should specify either the assume failed_images or standard-semantics compiler option. If you do not use a STAT= specifier, a STAT argument, or specify one of the compiler options, those operations will not check for failed images. They may then try to coordinate with the failed image, waiting for a response from it. The response would never happen and so the application would hang.

## Examples

The following example demonstrates using the STAT= specifier to prevent an application hang (see Note above):

    SUBROUTINE FAIL_AND_SYNC ( THIS_ONE )
       INTEGER THIS_ONE
       INTEGER MY_STAT
       IF (THIS_IMAGE() .EQ. THIS_ONE) THEN
           FAIL IMAGE
       END IF
       SYNC ALL (STAT=MY_STAT)      ! Would hang without STAT=
    END SUBROUTINE FAIL_AND_SYNC

If an image calls the following procedure at regular time intervals, it has a one in ten thousand chance of failure in each time step:

    SUBROUTINE RANDOM_FAILURE ()
       REAL RANDOM
       CALL RANDOM_NUMBER (RANDOM)
       IF (RANDOM > 0.9999) FAIL IMAGE
       RETURN
    END SUBROUTINE RANDOM_FAILURE

Parent topic: E to F

## See Also

FAILED_IMAGES
IMAGE_STATUS
standard-semantics compiler option
assume [no]failed_images compiler option