Skip to content

Commit f0f1c67

Browse files
author
Damian Rouson
committed
Improve get_team test
1 parent 17d7103 commit f0f1c67

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

src/tests/unit/teams/get-team.f90

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,75 @@
2929
! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
program main
3131
!! 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
3533

3634
implicit none
3735

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
4138

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
4387
use mpi, only : MPI_COMM_SIZE, MPI_COMM_RANK
88+
integer(c_int), intent(in) :: comm
89+
!! MPI communicator
4490
integer(c_int) :: isize,ierror,irank
4591

4692
call MPI_COMM_SIZE(comm, isize, ierror)
4793
call assert( ierror==0 , "successful call MPI_COMM_SIZE" )
94+
call assert( isize==num_images(), "num MPI ranks = num CAF images " )
4895

4996
call MPI_COMM_RANK(comm, irank, ierror)
5097
call assert( ierror==0 , "successful call MPI_COMM_RANK" )
51-
52-
call assert( isize==num_images() , "num MPI ranks = num CAF images " )
5398
call assert( irank==this_image()-1 , "correct rank/image-number correspondence" )
5499

55-
end block check_communicator
56-
57-
sync all
58-
if (this_image()==1) print *,"Test passed."
59-
60-
contains
100+
end subroutine
61101

62102
elemental subroutine assert(assertion,description)
63103
!! TODO: move this to a common place for all tests to use
@@ -67,7 +107,7 @@ elemental subroutine assert(assertion,description)
67107
character(len=max_digits) :: image_number
68108
if (.not.assertion) then
69109
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)
71111
end if
72112
end subroutine
73113

0 commit comments

Comments
 (0)