2
2
! Terms of use are as specified in LICENSE.txt
3
3
4
4
#include " language-support.F90"
5
+ #include " assert_macros.h"
5
6
6
7
module prif_co_reduce_test_m
7
8
! ! Unit test fort the prif_init program inititation subroutine
8
- use prif, only : prif_co_reduce, prif_num_images, prif_this_image_no_coarray, prif_error_stop
9
+ use assert_m
10
+ use prif, only : prif_co_reduce, prif_num_images, prif_this_image_no_coarray, prif_error_stop, prif_co_max
9
11
use prif_test_m, only : prif_test_t, test_description_substring
10
12
use iso_c_binding, only : c_bool, c_funloc, c_char, c_double, c_int64_t
11
13
use julienne_m, only : test_result_t, test_description_t
@@ -36,15 +38,15 @@ function results() result(test_results)
36
38
37
39
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
38
40
test_descriptions = [ &
39
- test_description_t(" alphabetical reduction of strings with result_image present " , alphabetically_first_string ) &
40
- ,test_description_t(" sums default integer scalars with no optional arguments" , sum_default_integer_scalars ) &
41
- ,test_description_t(" sums integer(c_int64_t) scalars with no optional arguments" , sum_c_int64_t_scalars ) &
42
- ,test_description_t(" multiplies default real scalars with all optional arguments" , multiply_default_real_scalars ) &
43
- ,test_description_t(" multiplies real(c_double) scalars with all optional arguments " , multiply_c_double_scalars ) &
44
- ,test_description_t(" performs a collective .and. operation across logical scalars " , reports_on_consensus ) &
45
- ,test_description_t(" sums default complex scalars with a stat-variable present" , sum_default_complex_scalars ) &
46
- ,test_description_t(" sums complex(c_double) scalars with a stat-variable present " , sum_complex_c_double_scalars ) &
47
- ,test_description_t(" sums default integer elements of a 2D array across images " , sum_integer_array_elements ) &
41
+ test_description_t(" sums default integer scalars with no optional arguments " , sum_default_integer_scalars ) &
42
+ ,test_description_t(" sums integer(c_int64_t) scalars with no optional arguments" , sum_c_int64_t_scalars ) &
43
+ ,test_description_t(" multiplies default real scalars with all optional arguments" , multiply_default_real_scalars ) &
44
+ ,test_description_t(" multiplies real(c_double) scalars with all optional arguments" , multiply_c_double_scalars ) &
45
+ ,test_description_t(" performs a collective .and. operation across logical scalars " , reports_on_consensus ) &
46
+ ,test_description_t(" sums default complex scalars with a stat-variable present " , sum_default_complex_scalars ) &
47
+ ,test_description_t(" sums complex(c_double) scalars with a stat-variable present" , sum_complex_c_double_scalars ) &
48
+ ,test_description_t(" sums default integer elements of a 2D array across images " , sum_integer_array_elements ) &
49
+ ,test_description_t(" alphabetical reduction of strings with result_image present " , alphabetically_first_string ) &
48
50
]
49
51
#else
50
52
procedure (test_function_i), pointer :: &
@@ -59,15 +61,15 @@ function results() result(test_results)
59
61
,sum_integer_array_elements_ptr = > sum_integer_array_elements
60
62
61
63
test_descriptions = [ &
62
- test_description_t(" alphabetical reduction of strings with result_image present" , alphabetically_first_string_ptr) &
63
- ,test_description_t(" sums default integer scalars with no optional arguments" , sum_default_integer_scalars_ptr) &
64
+ test_description_t(" sums default integer scalars with no optional arguments" , sum_default_integer_scalars_ptr) &
64
65
,test_description_t(" sums integer(c_int64_t) scalars with no optional arguments" , sum_c_int64_t_scalars_ptr) &
65
66
,test_description_t(" multiplies default real scalars with all optional arguments" , multiply_default_real_scalars_ptr) &
66
67
,test_description_t(" multiplies real(c_double) scalars with all optional arguments" , multiply_c_double_scalars_ptr) &
67
68
,test_description_t(" performs a collective .and. operation across logical scalars" , reports_on_consensus_ptr) &
68
69
,test_description_t(" sums default complex scalars with a stat-variable present" , sum_default_complex_scalars_ptr) &
69
70
,test_description_t(" sums complex(c_double) scalars with a stat-variable present" , sum_complex_c_double_scalars_ptr) &
70
71
,test_description_t(" sums default integer elements of a 2D array across images" , sum_integer_array_elements_ptr) &
72
+ ,test_description_t(" alphabetical reduction of strings with result_image present" , alphabetically_first_string_ptr) &
71
73
]
72
74
#endif
73
75
@@ -81,30 +83,25 @@ function results() result(test_results)
81
83
function alphabetically_first_string () result(test_passes)
82
84
logical test_passes
83
85
character (len=* , kind= c_char), parameter :: names(* ) = [" larry" ," harry" ," carey" ," betty" ," tommy" ," billy" ]
84
- character (len= :, kind= c_char), allocatable :: my_name(:)
85
- character (len= :), allocatable :: expected_name
86
- integer :: me, num_imgs
86
+ character (len= len (names), kind= c_char) my_name, expected_name
87
+ integer :: me, n
87
88
88
89
call prif_this_image_no_coarray(this_image= me)
89
90
associate(periodic_index = > 1 + mod (me-1 ,size (names)))
90
- my_name = [ names(periodic_index)]
91
+ my_name = names(periodic_index)
91
92
call prif_co_reduce(my_name, c_funloc(alphabetize))
92
93
end associate
93
94
94
- call prif_num_images(num_images= num_imgs )
95
- expected_name = minval (names(1 :min (num_imgs , size (names)))) ! this exposes a flang bug
96
- test_passes = all ( expected_name == my_name)
95
+ call prif_num_images(num_images= n )
96
+ expected_name = minval (names(1 :min (n , size (names)))) ! this exposes a flang bug
97
+ test_passes = expected_name == my_name
97
98
98
99
contains
99
100
100
- function alphabetize (lhs , rhs ) result(first_alphabetically)
101
+ pure function alphabetize (lhs , rhs ) result(first_alphabetically)
101
102
character (len=* ), intent (in ) :: lhs, rhs
102
- character (len= :), allocatable :: first_alphabetically
103
-
104
- if (len (lhs).ne. len (rhs)) then
105
- call prif_error_stop(quiet= .false. _c_bool, &
106
- stop_code_char= " co_reduce_s alphabetize: LHS(" // lhs // " )/RHS(" // rhs // " ) length don't match" )
107
- end if
103
+ character (len= len (lhs)) first_alphabetically
104
+ call_assert(len (lhs) == len (rhs))
108
105
first_alphabetically = min (lhs,rhs)
109
106
end function
110
107
0 commit comments