<CRITICAL Example Program>
Module module
Logical :: finished = .False.
Integer :: count[*] = 0
Contains
Subroutine do_some_work
! Just increment the count on image one, safely.
Critical
! We only read or write the value of count[1] inside this
! Critical block, so only one image at a time.
If (count[1]==100) Then
finished = .True.
Else
count[1] = count[1] + 1
End If
End Critical
End Subroutine
End Module
Program critical_example
Use module
! All images will do this.
Do While (.Not.finished)
Call do_some_work
End Do
If (This_Image()==1) Then
Print 1,count
1 Format(1X,'Finished ',I0,' units of work')
End If
End Program
■ Execution Results
Finished 100 units of work