22! Terms of use are as specified in LICENSE.txt
33submodule(collective_subroutines_m) co_reduce_s
44 use iso_c_binding, only : &
5- c_int64_t, c_ptr, c_size_t, c_loc, c_double , c_null_ptr, c_funloc, c_associated, c_f_pointer, c_int, c_f_procpointer
5+ c_ptr, c_size_t, c_loc, c_null_ptr, c_funloc, c_associated, c_f_pointer, c_int, c_f_procpointer
66 use assert_m, only : assert
77 use intrinsic_array_m, only : intrinsic_array_t
88 use utilities_m, only : get_c_ptr, get_c_ptr_character, optional_value
1616 module procedure caf_co_reduce
1717
1818 type (c_ptr) :: stat_ptr = c_null_ptr, errmsg_ptr = c_null_ptr
19+
1920 procedure (c_int32_t_operation), pointer :: int32_op = > null ()
21+ procedure (c_int64_t_operation), pointer :: int64_op = > null ()
2022 procedure (c_float_operation), pointer :: float_op = > null ()
23+ procedure (c_double_operation), pointer :: double_op = > null ()
2124 procedure (c_bool_operation), pointer :: bool_op = > null ()
2225 procedure (c_char_operation), pointer :: char_op = > null ()
2326 procedure (c_float_complex_operation), pointer :: float_complex_op = > null ()
27+ procedure (c_double_complex_operation), pointer :: double_complex_op = > null ()
2428
2529 call assert(c_associated(operation), " caf_co_reduce: c_associated(operation)" )
2630
3135 call c_f_procpointer(operation, int32_op)
3236 call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
3337 int (product (shape (a)), c_size_t), c_funloc(Coll_ReduceSub_c_int32_t), c_null_ptr)
38+ else if (caf_c_same_cfi_type(a, 0_c_int64_t )) then
39+ call c_f_procpointer(operation, int64_op)
40+ call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
41+ int (product (shape (a)), c_size_t), c_funloc(Coll_ReduceSub_c_int64_t), c_null_ptr)
42+ else if (caf_c_same_cfi_type(a, 1._c_double )) then
43+ call c_f_procpointer(operation, double_op)
44+ call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
45+ int (product (shape (a)), c_size_t), c_funloc(Coll_ReduceSub_c_double), c_null_ptr)
3446 else if (caf_c_same_cfi_type(a, 1._c_float )) then
3547 call c_f_procpointer(operation, float_op)
3648 call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
5163 call c_f_procpointer(operation, float_complex_op)
5264 call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
5365 int (product (shape (a)), c_size_t), c_funloc(Coll_ReduceSub_c_float_complex), c_null_ptr)
66+ else if (caf_c_same_cfi_type(a, (0._c_double , 0._c_double ))) then
67+ call c_f_procpointer(operation, double_complex_op)
68+ call caf_c_co_reduce(a, optional_value(result_image), stat_ptr, errmsg_ptr, &
69+ int (product (shape (a)), c_size_t), c_funloc(Coll_ReduceSub_c_double_complex), c_null_ptr)
5470 else
5571 error stop " caf_co_reduce: unsupported type"
5672 end if
@@ -75,6 +91,42 @@ subroutine Coll_ReduceSub_c_int32_t(arg1, arg2_and_out, count, cdata) bind(C)
7591 end do
7692 end subroutine
7793
94+ subroutine Coll_ReduceSub_c_int64_t (arg1 , arg2_and_out , count , cdata ) bind(C)
95+ type (c_ptr), value :: arg1 ! ! "Left" operands
96+ type (c_ptr), value :: arg2_and_out ! ! "Right" operands and result
97+ integer (c_size_t), value :: count ! ! Operand count
98+ type (c_ptr), value :: cdata ! ! Client data
99+ integer (c_int64_t), pointer :: lhs(:)= >null (), rhs_and_result(:)= >null ()
100+ integer (c_size_t) i
101+
102+ call assert(all ([c_associated(arg1), c_associated(arg2_and_out)]), " Coll_ReduceSub_c_int64_t: operands associated" )
103+
104+ call c_f_pointer(arg1, lhs, [count])
105+ call c_f_pointer(arg2_and_out, rhs_and_result, [count])
106+
107+ do concurrent(i= 1 :count)
108+ rhs_and_result(i) = int64_op(lhs(i), rhs_and_result(i))
109+ end do
110+ end subroutine
111+
112+ subroutine Coll_ReduceSub_c_double (arg1 , arg2_and_out , count , cdata ) bind(C)
113+ type (c_ptr), value :: arg1 ! ! "Left" operands
114+ type (c_ptr), value :: arg2_and_out ! ! "Right" operands and result
115+ integer (c_size_t), value :: count ! ! Operand count
116+ type (c_ptr), value :: cdata ! ! Client data
117+ real (c_double), pointer :: lhs(:)= >null (), rhs_and_result(:)= >null ()
118+ integer (c_size_t) i
119+
120+ call assert(all ([c_associated(arg1), c_associated(arg2_and_out)]), " Coll_ReduceSub_c_double: operands associated" )
121+
122+ call c_f_pointer(arg1, lhs, [count])
123+ call c_f_pointer(arg2_and_out, rhs_and_result, [count])
124+
125+ do concurrent(i= 1 :count)
126+ rhs_and_result(i) = double_op(lhs(i), rhs_and_result(i))
127+ end do
128+ end subroutine
129+
78130 subroutine Coll_ReduceSub_c_float (arg1 , arg2_and_out , count , cdata ) bind(C)
79131 type (c_ptr), value :: arg1 ! ! "Left" operands
80132 type (c_ptr), value :: arg2_and_out ! ! "Right" operands and result
@@ -93,6 +145,24 @@ subroutine Coll_ReduceSub_c_float(arg1, arg2_and_out, count, cdata) bind(C)
93145 end do
94146 end subroutine
95147
148+ subroutine Coll_ReduceSub_c_double_complex (arg1 , arg2_and_out , count , cdata ) bind(C)
149+ type (c_ptr), value :: arg1 ! ! "Left" operands
150+ type (c_ptr), value :: arg2_and_out ! ! "Right" operands and result
151+ integer (c_size_t), value :: count ! ! Operand count
152+ type (c_ptr), value :: cdata ! ! Client data
153+ complex (c_double), pointer :: lhs(:)= >null (), rhs_and_result(:)= >null ()
154+ integer (c_size_t) i
155+
156+ call assert(all ([c_associated(arg1), c_associated(arg2_and_out)]), " Coll_ReduceSub_c_dobule_complex: operands associated" )
157+
158+ call c_f_pointer(arg1, lhs, [count])
159+ call c_f_pointer(arg2_and_out, rhs_and_result, [count])
160+
161+ do concurrent(i= 1 :count)
162+ rhs_and_result(i) = double_complex_op(lhs(i), rhs_and_result(i))
163+ end do
164+ end subroutine
165+
96166 subroutine Coll_ReduceSub_c_float_complex (arg1 , arg2_and_out , count , cdata ) bind(C)
97167 type (c_ptr), value :: arg1 ! ! "Left" operands
98168 type (c_ptr), value :: arg2_and_out ! ! "Right" operands and result
0 commit comments