1
1
module caf_teams_test
2
- use iso_c_binding, only: c_size_t, c_ptr, c_null_funptr, c_int64_t
3
- use prif, only: &
4
- prif_coarray_handle, &
5
- prif_allocate_coarray, &
6
- prif_deallocate_coarray, &
7
- prif_this_image_no_coarray, &
8
- prif_num_images, &
9
- prif_team_type, &
10
- prif_form_team, &
11
- prif_change_team, &
12
- prif_end_team
13
- use veggies, only: result_t, test_item_t, assert_equals, describe, it, succeed
2
+ use iso_c_binding, only: c_size_t, c_ptr, c_null_funptr, c_int64_t, c_int
3
+ use prif
4
+ use veggies, only: result_t, test_item_t, assert_equals, assert_that, describe, it, succeed
14
5
15
6
implicit none
16
7
private
@@ -29,16 +20,62 @@ function check_teams() result(result_)
29
20
type (result_t) :: result_
30
21
31
22
! TODO: use final_func to observe automatic deallocation of coarrays
32
- integer :: dummy_element, initial_num_imgs, num_imgs, me, i
23
+ integer :: dummy_element, i
24
+ integer (c_int) :: initial_num_imgs, num_imgs, me, me_child, x
33
25
integer (c_size_t) :: element_size
34
- integer (c_int64_t) :: which_team
26
+ integer (c_int64_t) :: which_team, n
35
27
integer , parameter :: num_coarrays = 4
36
28
type (prif_coarray_handle) :: coarrays(num_coarrays)
37
29
type (c_ptr) :: allocated_memory
38
- type (prif_team_type) :: team
30
+ type (prif_team_type) :: team, initial_team, t
39
31
40
- call prif_this_image_no_coarray(this_image= me)
41
32
call prif_num_images(num_images= initial_num_imgs)
33
+ result_ = result_ .and. &
34
+ assert_that(initial_num_imgs > 0 , " prif_num_images is valid" )
35
+
36
+ call prif_this_image_no_coarray(this_image= me)
37
+ result_ = result_ .and. &
38
+ assert_that(me >= 1 .and. me <= initial_num_imgs, " prif_this_image is valid" )
39
+
40
+ n = 0 ! clear outputs
41
+ call prif_team_number(team_number= n)
42
+ result_ = result_ .and. &
43
+ assert_equals(int (n), - 1 , " Initial team number is -1" )
44
+
45
+ n = 0 ! clear outputs
46
+ call prif_get_team(team= initial_team)
47
+ call prif_team_number(team= initial_team, team_number= n)
48
+ result_ = result_ .and. &
49
+ assert_equals(int (n), - 1 , " prif_get_team retrieves current initial team" )
50
+
51
+ x = 0 ! clear outputs
52
+ call prif_num_images_with_team(team= initial_team, num_images= x)
53
+ result_ = result_ .and. &
54
+ assert_equals(x, initial_num_imgs, " prif_num_images works with initial team" )
55
+
56
+ x = 0 ! clear outputs
57
+ call prif_this_image_no_coarray(team= initial_team, this_image= x)
58
+ result_ = result_ .and. &
59
+ assert_equals(x, me, " prif_this_image_no_coarray works with initial team" )
60
+
61
+ t = prif_team_type() ; n = 0 ! clear outputs
62
+ call prif_get_team(level= PRIF_INITIAL_TEAM, team= t)
63
+ call prif_team_number(team= t, team_number= n)
64
+ result_ = result_ .and. &
65
+ assert_equals(int (n), - 1 , " prif_get_team(PRIF_INITIAL_TEAM) retrieves initial team" )
66
+
67
+ t = prif_team_type() ; n = 0 ! clear outputs
68
+ call prif_get_team(level= PRIF_CURRENT_TEAM, team= t)
69
+ call prif_team_number(team= t, team_number= n)
70
+ result_ = result_ .and. &
71
+ assert_equals(int (n), - 1 , " prif_get_team(PRIF_CURRENT_TEAM) retrieves initial team" )
72
+
73
+ t = prif_team_type() ; n = 0 ! clear outputs
74
+ call prif_get_team(level= PRIF_PARENT_TEAM, team= t)
75
+ call prif_team_number(team= t, team_number= n)
76
+ result_ = result_ .and. &
77
+ assert_equals(int (n), - 1 , " prif_get_team(PRIF_PARENT_TEAM) retrieves initial team" )
78
+
42
79
which_team = merge (1_c_int64_t , 2_c_int64_t , mod (me, 2 ) == 0 )
43
80
element_size = int (storage_size(dummy_element)/ 8 , c_size_t)
44
81
call prif_form_team(team_number = which_team, team = team)
@@ -48,6 +85,66 @@ function check_teams() result(result_)
48
85
initial_num_imgs/ 2 + mod (initial_num_imgs,2 )* (int (which_team)- 1 ), &
49
86
num_imgs, &
50
87
" Team has correct number of images" )
88
+
89
+ x = 0 ! clear outputs
90
+ call prif_num_images_with_team(team= team, num_images= x)
91
+ result_ = result_ .and. &
92
+ assert_equals(x, num_imgs, " prif_num_images works with team" )
93
+
94
+ call prif_this_image_no_coarray(this_image= me_child)
95
+ result_ = result_ .and. &
96
+ assert_equals(me_child, (me - 1 )/ 2 + 1 , " prif_this_image is valid" )
97
+
98
+ x = 0 ! clear outputs
99
+ call prif_this_image_no_coarray(team= team, this_image= x)
100
+ result_ = result_ .and. &
101
+ assert_equals(x, me_child, " prif_this_image is valid" )
102
+
103
+ n = 0 ! clear outputs
104
+ call prif_team_number(team_number= n)
105
+ result_ = result_ .and. &
106
+ assert_equals(int (n), int (which_team), " Correct current team number" )
107
+
108
+ n = 0 ! clear outputs
109
+ call prif_team_number(team= team, team_number= n)
110
+ result_ = result_ .and. &
111
+ assert_equals(int (n), int (which_team), " Correct current team number" )
112
+
113
+ t = prif_team_type() ; n = 0 ! clear outputs
114
+ call prif_get_team(team= t)
115
+ call prif_team_number(team= t, team_number= n)
116
+ result_ = result_ .and. &
117
+ assert_equals(int (n), int (which_team), " prif_get_team retrieves current team" )
118
+
119
+ t = prif_team_type() ; n = 0 ! clear outputs
120
+ call prif_get_team(level= PRIF_INITIAL_TEAM, team= t)
121
+ call prif_team_number(team= t, team_number= n)
122
+ result_ = result_ .and. &
123
+ assert_equals(int (n), - 1 , " prif_get_team(PRIF_INITIAL_TEAM) retrieves initial team" )
124
+
125
+ t = prif_team_type() ; n = 0 ! clear outputs
126
+ call prif_get_team(level= PRIF_CURRENT_TEAM, team= t)
127
+ call prif_team_number(team= t, team_number= n)
128
+ result_ = result_ .and. &
129
+ assert_equals(int (n), int (which_team), " prif_get_team(PRIF_CURRENT_TEAM) retrieves current team" )
130
+
131
+ t = prif_team_type() ; n = 0 ! clear outputs
132
+ call prif_get_team(level= PRIF_PARENT_TEAM, team= t)
133
+ call prif_team_number(team= t, team_number= n)
134
+ result_ = result_ .and. &
135
+ assert_equals(int (n), - 1 , " prif_get_team(PRIF_PARENT_TEAM) retrieves initial team" )
136
+
137
+ x = 0 ! clear outputs
138
+ call prif_num_images_with_team(team= initial_team, num_images= x)
139
+ result_ = result_ .and. &
140
+ assert_equals(x, initial_num_imgs, " prif_num_images works with initial team" )
141
+
142
+ x = 0 ! clear outputs
143
+ call prif_this_image_no_coarray(team= initial_team, this_image= x)
144
+ result_ = result_ .and. &
145
+ assert_equals(x, me, " prif_this_image_no_coarray works with initial team" )
146
+
147
+
51
148
do i = 1 , num_coarrays
52
149
call prif_allocate_coarray( &
53
150
lcobounds = [1_c_int64_t ], &
@@ -59,7 +156,15 @@ function check_teams() result(result_)
59
156
end do
60
157
call prif_deallocate_coarray(coarrays(4 :4 ))
61
158
call prif_deallocate_coarray(coarrays(2 :2 ))
159
+
62
160
call prif_end_team()
161
+
162
+ t = prif_team_type() ; n = 0 ! clear outputs
163
+ call prif_get_team(team= t)
164
+ call prif_team_number(team= t, team_number= n)
165
+ result_ = result_ .and. &
166
+ assert_equals(int (n), - 1 , " prif_end_team restores initial team" )
167
+
63
168
result_ = result_.and. succeed(" Seems to have worked" )
64
169
end function
65
170
end module
0 commit comments