29
29
! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
program main
31
31
! ! summary: Test get_team function, an OpenCoarrays-specific language extension
32
- use opencoarrays, only : get_team, &
33
- team_number ! ! TODO: remove team_number once gfortran supports it
34
- use iso_c_binding, only : c_int
32
+ use opencoarrays, only : get_team
35
33
36
34
implicit none
37
35
38
- integer (c_int) :: comm
39
- ! ! MPI communicator
40
- comm = get_team()
36
+ call mpi_matches_caf(get_team())
37
+ ! ! verify # ranks = # images and image number = rank + 1
41
38
42
- check_communicator: block
39
+ block
40
+ use iso_fortran_env, only : team_type
41
+ use opencoarrays, only : get_team, team_number ! ! TODO: remove team_number once gfortran supports it
42
+
43
+ type (team_type) :: league
44
+ integer , parameter :: num_teams= 2
45
+ ! ! number of child teams to form from the parent initial team
46
+
47
+ associate(initial_image= >this_image(), initial_num_images= >num_images(), chosen_team= >destination_team(this_image(),num_teams))
48
+
49
+ form team(chosen_team,league)
50
+ ! ! map images to num_teams teams
51
+
52
+ change team(league)
53
+ ! ! join my destination team
54
+
55
+ call mpi_matches_caf(get_team())
56
+ ! ! verify new # ranks = new # images and new image number = new rank + 1
57
+
58
+ associate(my_team= >team_number())
59
+ call assert(my_team== chosen_team," assigned team matches chosen team" )
60
+ associate(new_num_images= >initial_num_images/ num_teams+ merge (1 ,0 ,my_team<= mod (initial_num_images,num_teams)))
61
+ call assert(num_images()==new_num_images," block distribution of images" )
62
+ end associate
63
+ end associate
64
+
65
+ end team
66
+
67
+ call assert( initial_image== this_image()," correctly remapped to original image number" )
68
+ call assert( initial_num_images== num_images()," correctly remapped to original number of images" )
69
+
70
+ end associate
71
+
72
+ end block
73
+
74
+ sync all
75
+ if (this_image()==1 ) print * ," Test passed."
76
+
77
+ contains
78
+
79
+ pure function destination_team (image ,numTeams ) result(team)
80
+ integer , intent (in ) :: image, numTeams
81
+ integer :: team
82
+ team = mod (image+1 ,numTeams)+ 1
83
+ end function
84
+
85
+ subroutine mpi_matches_caf (comm )
86
+ use iso_c_binding, only : c_int
43
87
use mpi, only : MPI_COMM_SIZE, MPI_COMM_RANK
88
+ integer (c_int), intent (in ) :: comm
89
+ ! ! MPI communicator
44
90
integer (c_int) :: isize,ierror,irank
45
91
46
92
call MPI_COMM_SIZE(comm, isize, ierror)
47
93
call assert( ierror== 0 , " successful call MPI_COMM_SIZE" )
94
+ call assert( isize== num_images(), " num MPI ranks = num CAF images " )
48
95
49
96
call MPI_COMM_RANK(comm, irank, ierror)
50
97
call assert( ierror== 0 , " successful call MPI_COMM_RANK" )
51
-
52
- call assert( isize== num_images() , " num MPI ranks = num CAF images " )
53
98
call assert( irank== this_image()- 1 , " correct rank/image-number correspondence" )
54
99
55
- end block check_communicator
56
-
57
- sync all
58
- if (this_image()==1 ) print * ," Test passed."
59
-
60
- contains
100
+ end subroutine
61
101
62
102
elemental subroutine assert (assertion ,description )
63
103
! ! TODO: move this to a common place for all tests to use
@@ -67,7 +107,7 @@ elemental subroutine assert(assertion,description)
67
107
character (len= max_digits) :: image_number
68
108
if (.not. assertion) then
69
109
write (image_number,* ) this_image()
70
- error stop " Assertion " // description // " failed on image " // trim (image_number)
110
+ error stop " Assertion ' " // description // " ' failed on image " // trim (image_number)
71
111
end if
72
112
end subroutine
73
113
0 commit comments