11module data_partition_test
2- ! ! author: Damian Rouson
3- ! !
4- ! ! summary: verify data partitioning across images and data gathering
5- use vegetables, only: &
6- result_t, example_t, input_t, integer_input_t, test_item_t, & ! types
7- describe, it, assert_equals, assert_that ! functions
8- use data_partition_m, only : data_partition_t
9- use iso_fortran_env, only : real64
10- implicit none
11-
12- private
13- public :: test_data_partition
2+ ! ! verify data partitioning across images and data gathering
3+ use data_partition_m, only : data_partition_t
4+ use test_m, only : test_t, test_result_t
5+ use iso_fortran_env, only : real64
6+ implicit none
147
15- type (data_partition_t) partition
16- integer , parameter :: num_particles= 31 , gatherer= 1 , num_steps= 9 , dummy= 0
8+ private
9+ public :: data_partition_test_t
10+
11+ type, extends(test_t) :: data_partition_test_t
12+ contains
13+ procedure , nopass :: subject
14+ procedure , nopass :: results
15+ end type
16+
17+ type (data_partition_t) partition
18+ integer , parameter :: num_particles= 31 , gatherer= 1 , num_steps= 9 , dummy= 0
1719
1820contains
1921
20- function test_data_partition () result(tests)
21- type (test_item_t) tests
22+ pure function subject () result(specimen)
23+ character (len= :), allocatable :: specimen
24+ specimen = " The data_partition_t type"
25+ end function
26+
27+ function results () result(test_results)
28+ type (test_result_t), allocatable :: test_results(:)
2229
23- call partition% define_partitions( cardinality= num_particles)
30+ call partition% define_partitions(cardinality= num_particles)
2431
2532 associate( me= >this_image() )
2633 associate( my_first= >partition% first(me), my_last= >partition% last(me) )
27- tests = describe( &
28- " data_partition class" , &
29- [it( &
30- " partitions data in nearly even blocks" , &
31- verify_block_partitioning), &
32- it( &
33- " all data partitioned across all images without data loss" , &
34- verify_all_particles_partitioned), &
35- it( &
36- " 1D real array gathered on all images" , &
37- [example_t(integer_input_t(dummy)), example_t(integer_input_t(dummy))], &
38- verify_all_gather_1D_real_array), &
39- it( &
40- " dimension 1 of 2D real array gathered on all images witout dim argument" , &
41- [example_t(integer_input_t(dummy)), example_t(integer_input_t(dummy))], &
42- verify_all_gather_2D_real_array), &
43- it( &
44- " dimension 1 of 2D real array gathered on all images with dim argument" , &
45- [example_t(integer_input_t(dummy)), example_t(integer_input_t(dummy))], &
46- verify_all_gather_2D_real_array_dim1), &
47- it( &
48- " dimension 1 of 2D real array gathered onto result_image with dim argument" , &
49- [example_t(integer_input_t(dummy)), example_t(integer_input_t(dummy))], &
50- verify_gather_2D_real_array_dim1)])
51-
34+ test_results = [ &
35+ test_result_t(" partitioning data in nearly even blocks" , verify_block_partitioning()), &
36+ test_result_t(" partitioning all data across all images without data loss" , verify_all_particles_partitioned()), &
37+ test_result_t(" gathering a 1D real array onto all images" , verify_all_gather_1D_real_array()), &
38+ test_result_t(" gathering dimension 1 of 2D real array onto all images witout dim argument" , &
39+ verify_all_gather_2D_real_array()), &
40+ test_result_t(" gathering dimension 1 of 2D real array onton all images with dim argument" , &
41+ verify_all_gather_2D_real_array_dim1()), &
42+ test_result_t(" gathering dimension 1 of 2D real array onto result_image with dim argument" , &
43+ verify_gather_2D_real_array_dim1()) &
44+ ]
5245 end associate
5346 end associate
5447 end function
5548
56- function verify_block_partitioning () result(result_ )
49+ function verify_block_partitioning () result(test_passes )
5750 ! ! Verify that the data is partitioned across images evenly to
5851 ! ! within a difference of one datum between any two images.
5952 type (data_partition_t) partition
60- type (result_t) result_
53+ logical test_passes
6154 integer my_particles
6255
6356 associate( me= >this_image() )
6457 associate( my_first= >partition% first(me), my_last= >partition% last(me) )
6558 my_particles = my_last - my_first + 1
6659 associate( ni= >num_images() )
6760 associate( quotient= >num_particles/ ni, remainder= >mod (num_particles,ni) )
68- result_ = assert_equals( quotient + merge (1 , 0 , me<= remainder), my_particles, " block distribution " )
61+ test_passes = quotient + merge (1 , 0 , me<= remainder) == my_particles
6962 end associate
7063 end associate
7164 end associate
7265 end associate
7366 end function
7467
75- function verify_all_particles_partitioned () result(result_ )
68+ function verify_all_particles_partitioned () result(test_passes )
7669 ! ! Verify that the number of particles on each image sums to the
7770 ! ! total number of particles distributed.
7871 type (data_partition_t) partition
79- type (result_t) result_
72+ logical test_passes
8073 integer particles
8174
8275 associate(me = > this_image())
8376 associate( my_first= >partition% first(me), my_last= >partition% last(me) )
8477 particles = my_last - my_first + 1
8578 call co_sum(particles)
86- result_ = assert_equals( num_particles, particles, " all particles distributed " )
79+ test_passes = num_particles == particles
8780 end associate
8881 end associate
8982 end function
9083
91- function verify_all_gather_1D_real_array (unused ) result(result_ )
84+ function verify_all_gather_1D_real_array () result(test_passes )
9285 type (data_partition_t) partition
93- class(input_t), intent (in ) :: unused
94- type (result_t) result_
86+ logical test_passes
9587 real (real64) :: particle_scalar(num_particles)
9688 real (real64), parameter :: junk=- 12345._real64 , expected= 1._real64
9789
98- associate( no_op = > unused) ! eliminate unused-variable warning
99- end associate
100-
10190 associate(me = > this_image())
10291 associate( first= >partition% first(me), last= >partition% last(me) )
103-
10492 particle_scalar(first:last) = expected ! ! values to be gathered
10593 particle_scalar(1 :first-1 ) = junk ! ! values to be overwritten by the gather
10694 particle_scalar(last+1 :) = junk ! ! values to be overwritten by the gather
107-
10895 call partition% gather(particle_scalar)
109-
110- result_ = assert_that( all (particle_scalar== expected), " real 1D array all-gathered" )
111-
96+ test_passes = all (particle_scalar== expected)
11297 end associate
11398 end associate
11499 end function
115100
116- function verify_all_gather_2D_real_array (unused ) result(result_)
117- class(input_t), intent (in ) :: unused
101+ function verify_all_gather_2D_real_array () result(test_passes)
118102 type (data_partition_t) partition
119- type (result_t) result_
103+ logical test_passes
120104 integer , parameter :: vec_space_dim= 3
121105 real (real64) particle_vector(vec_space_dim, num_particles)
122106 real (real64), parameter :: junk=- 12345._real64 , expected= 1._real64
123107
124- associate( no_op = > unused) ! eliminate unused-variable warning
125- end associate
126-
127108 associate(me = > this_image())
128109 associate( first= >partition% first(me), last= >partition% last(me) )
129110
130111 particle_vector(:, first:last) = expected ! ! values to be gathered
131112 particle_vector(:, 1 :first-1 ) = junk ! ! values to be overwritten by the gather
132113 particle_vector(:, last+1 :) = junk ! ! values to be overwritten by the gather
133-
134114 call partition% gather(particle_vector)
135-
136- result_ = assert_that(all (particle_vector== expected), " real 2D array all-gathered implicitly along dimension 1" )
137-
115+ test_passes = all (particle_vector== expected)
138116 end associate
139117 end associate
140118 end function
141119
142- function verify_all_gather_2D_real_array_dim1 (unused ) result(result_)
143- class(input_t), intent (in ) :: unused
120+ function verify_all_gather_2D_real_array_dim1 () result(test_passes)
144121 type (data_partition_t) partition
145- type (result_t) result_
122+ logical test_passes
146123 integer , parameter :: vec_space_dim= 3
147124 real (real64) :: vector_transpose(num_particles, vec_space_dim)
148125 real (real64), parameter :: junk=- 12345._real64 , expected= 1._real64
149126
150- associate( no_op = > unused) ! eliminate unused-variable warning
151- end associate
152-
153127 associate(me = > this_image())
154128 associate( first= >partition% first(me), last= >partition% last(me) )
155129
@@ -159,23 +133,19 @@ function verify_all_gather_2D_real_array_dim1(unused) result(result_)
159133
160134 call partition% gather( vector_transpose, dim= 1 )
161135
162- result_ = assert_that( all (vector_transpose== expected), " vector_transpose gathered explicitly along dimension 1 " )
136+ test_passes = all (vector_transpose== expected)
163137
164138 end associate
165139 end associate
166140 end function
167141
168- function verify_gather_2D_real_array_dim1 (unused ) result(result_)
169- class(input_t), intent (in ) :: unused
142+ function verify_gather_2D_real_array_dim1 () result(test_passes)
170143 type (data_partition_t) partition
171- type (result_t) result_
144+ logical test_passes
172145 integer , parameter :: vec_space_dim= 3
173146 real (real64) :: vector_transpose(num_particles, vec_space_dim)
174147 real (real64), parameter :: junk=- 12345._real64 , expected= 1._real64
175148
176- associate( no_op = > unused) ! eliminate unused-variable warning
177- end associate
178-
179149 associate(me = > this_image())
180150 associate( first= >partition% first(me), last= >partition% last(me) )
181151
@@ -186,12 +156,12 @@ function verify_gather_2D_real_array_dim1(unused) result(result_)
186156 call partition% gather( vector_transpose, result_image= gatherer, dim= 1 )
187157
188158 if (me== gatherer) then
189- result_ = assert_that( all (vector_transpose== expected), " all( particle_vector==expected) " )
159+ test_passes = all (vector_transpose== expected)
190160 else
191- result_ = &
192- assert_that( all (vector_transpose(1 :first-1 ,:)==junk), " lower transpose data unchanged) " ) .and. &
193- assert_that( all (vector_transpose(first:last,:)==expected), " expected transpose data gathered " ) .and. &
194- assert_that( all (vector_transpose(last+1 :,:)==junk), " upper transpose data unchanged) " )
161+ test_passes = &
162+ all (vector_transpose(1 :first-1 ,:)==junk) .and. &
163+ all (vector_transpose(first:last,:)==expected) .and. &
164+ all (vector_transpose(last+1 :,:)==junk)
195165 end if
196166
197167 end associate
0 commit comments