# Program Termination

Program termination may involve flushing I/O buffers, closing open I/O files, writing of a STOP code or an ERROR STOP code, or reporting an error status on one or more images. There are two types of image termination, normal termination and error termination.

Normal termination occurs when an image executes a STOP statement or an END [PROGRAM] statement. If there are multiple images running, execution of STOP or END [PROGRAM] statement effects only the image that executes the statement; it has no effect on other images. When an image initiates normal termination, its image status becomes STOPPED, and it waits until all other active images initiate normal termination at which time all images terminate execution. While an image has the status STOPPED, its coarrays are still accessible for reference or definition by other active images.

Error termination of one image causes termination of all other images. Error termination is not initiated if an error condition occurs during the execution of an I/O statement which specifies either an IOSTAT= or ERR= specifier, during the execution of an image control statement that specifies a STAT= specifier, or during a reference to an intrinsic function with a present STAT argument. Otherwise, if an error condition occurs, error termination is initiated.

A program terminates execution when all images that have not failed terminate execution.

Parent topic: Execution Control