<FORM TEAM Example Program>
Program form_team_example
Use Iso_Fortran_Env
Implicit None
Integer :: myteamid,i
Type(team_type) team
Integer :: temp[*],answer[*] = 0
If (Num_Images()<4) Error Stop 'Not enough images (need 4)'
myteamid = (This_Image()+1)/2
Form Team(myteamid,team)
Change Team(team)
If (myteamid==1) Then
! Do what team 1 is supposed to do.
temp = This_Image()**2
Sync All ! Just syncs team one.
If (This_Image()==1) answer = temp + temp[2]
Else If (myteamid==2) Then
! Do what team 2 is supposed to do.
temp = This_Image()**3
Sync All ! Just syncs team two.
If (This_Image()==1) answer = temp + temp[2]
Else
answer = 0
End If
End Team
If (This_Image()==1) Then
Do i=2,Num_Images()
answer = answer + answer[i]
End Do
Print *,answer
End If
End Program
■ Execution Results
14