Skip to content

Commit 6aff6d3

Browse files
committed
Merge branch 'co_broadcast-derived-type' of github.com:sourceryinstitute/OpenCoarrays
2 parents d13375d + 9fd352a commit 6aff6d3

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ if(opencoarrays_aware_compiler)
797797

798798
add_caf_test(co_sum 4 co_sum_test)
799799
add_caf_test(co_broadcast 4 co_broadcast_test)
800+
add_caf_test(co_broadcast_derived_type 4 co_broadcast_derived_type_test)
800801
add_caf_test(co_min 4 co_min_test)
801802
add_caf_test(co_max 4 co_max_test)
802803
add_caf_test(syncall 8 syncall)

src/mpi/mpi_caf.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7253,9 +7253,10 @@ get_MPI_datatype(gfc_descriptor_t *desc, int char_len)
72537253
return string;
72547254
}
72557255

7256-
caf_runtime_error("Unsupported data type in collective: %zd\n",
7257-
GFC_DTYPE_TYPE_SIZE(desc));
7258-
return 0;
7256+
return MPI_BYTE;
7257+
/* caf_runtime_error("Unsupported data type in collective: %zd\n", */
7258+
/* GFC_DTYPE_TYPE_SIZE(desc)); */
7259+
/* return 0; */
72597260
}
72607261

72617262

@@ -7379,9 +7380,17 @@ PREFIX(co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat,
73797380
size *= dimextent;
73807381
}
73817382

7383+
printf("DTYPE Size: %d\n",GFC_DESCRIPTOR_SIZE(a));
7384+
73827385
if (rank == 0)
73837386
{
7384-
if (datatype != MPI_CHARACTER)
7387+
if( datatype == MPI_BYTE)
7388+
{
7389+
ierr = MPI_Bcast(a->base_addr, size*GFC_DESCRIPTOR_SIZE(a),
7390+
datatype, source_image - 1,
7391+
CAF_COMM_WORLD); chk_err(ierr);
7392+
}
7393+
else if (datatype != MPI_CHARACTER)
73857394
{
73867395
ierr = MPI_Bcast(a->base_addr, size, datatype, source_image - 1,
73877396
CAF_COMM_WORLD); chk_err(ierr);

src/tests/unit/collectives/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
caf_compile_executable(co_sum_test co_sum.F90)
22
caf_compile_executable(co_broadcast_test co_broadcast.F90)
3+
caf_compile_executable(co_broadcast_derived_type_test co_broadcast_derived_type.f90)
34
caf_compile_executable(co_min_test co_min.F90)
45
caf_compile_executable(co_max_test co_max.F90)
56
caf_compile_executable(co_reduce_test co_reduce.F90)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
module object_interface
2+
implicit none
3+
private
4+
public :: object
5+
6+
type object
7+
private
8+
integer :: foo=0
9+
logical :: bar=.false.
10+
contains
11+
procedure :: initialize
12+
procedure :: co_broadcast_me
13+
procedure :: not_equal
14+
procedure :: copy
15+
generic :: operator(/=)=>not_equal
16+
generic :: assignment(=)=>copy
17+
end type
18+
19+
interface
20+
elemental impure module subroutine initialize(this,foo_,bar_)
21+
implicit none
22+
class(object), intent(out) :: this
23+
integer, intent(in) :: foo_
24+
logical, intent(in) :: bar_
25+
end subroutine
26+
27+
elemental impure module subroutine co_broadcast_me(this,source_image)
28+
implicit none
29+
class(object), intent(inout) :: this
30+
integer, intent(in) :: source_image
31+
end subroutine
32+
33+
elemental module function not_equal(lhs,rhs) result(lhs_ne_rhs)
34+
implicit none
35+
class(object), intent(in) :: lhs,rhs
36+
logical lhs_ne_rhs
37+
end function
38+
39+
elemental impure module subroutine copy(lhs,rhs)
40+
implicit none
41+
class(object), intent(inout) :: lhs
42+
class(object), intent(in) :: rhs
43+
end subroutine
44+
end interface
45+
46+
end module
47+
48+
submodule(object_interface) object_implementation
49+
implicit none
50+
contains
51+
module procedure co_broadcast_me
52+
call co_broadcast(this%foo,source_image)
53+
call co_broadcast(this%bar,source_image)
54+
end procedure
55+
56+
module procedure initialize
57+
this%foo = foo_
58+
this%bar = bar_
59+
end procedure
60+
61+
module procedure not_equal
62+
lhs_ne_rhs = (lhs%foo /= rhs%foo) .or. (lhs%bar .neqv. rhs%bar)
63+
end procedure
64+
65+
module procedure copy
66+
lhs%foo = rhs%foo
67+
lhs%bar = rhs%bar
68+
end procedure
69+
end submodule
70+
71+
program main
72+
use object_interface, only : object
73+
implicit none
74+
type(object) message
75+
76+
call message%initialize(foo_=1,bar_=.true.)
77+
78+
emulate_co_broadcast: block
79+
type(object) foobar
80+
if (this_image()==1) foobar = message
81+
call foobar%co_broadcast_me(source_image=1)
82+
if ( foobar /= message ) error stop "Test failed."
83+
end block emulate_co_broadcast
84+
85+
desired_co_broadcast: block
86+
type(object) barfoo
87+
if (this_image()==1) barfoo = message
88+
call co_broadcast(barfoo,source_image=1) ! OpenCoarrays terminates here with the message "Unsupported data type"
89+
if ( barfoo /= message ) error stop "Test failed."
90+
end block desired_co_broadcast
91+
92+
sync all ! Wait for each image to pass the test
93+
if (this_image()==1) print *,"Test passed."
94+
95+
end program main

0 commit comments

Comments
 (0)