Skip to content

Commit 6d1671d

Browse files
author
Damian Rouson
committed
Refactor/improve co_broadcast
1 parent 9fd352a commit 6d1671d

File tree

2 files changed

+106
-97
lines changed

2 files changed

+106
-97
lines changed

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,23 +794,26 @@ if(opencoarrays_aware_compiler)
794794
add_caf_test(strided_sendget 3 strided_sendget)
795795
add_caf_test(get_with_vector_index 4 get_with_vector_index)
796796

797-
797+
# Collective subroutine tests
798798
add_caf_test(co_sum 4 co_sum_test)
799799
add_caf_test(co_broadcast 4 co_broadcast_test)
800800
add_caf_test(co_broadcast_derived_type 4 co_broadcast_derived_type_test)
801801
add_caf_test(co_min 4 co_min_test)
802802
add_caf_test(co_max 4 co_max_test)
803-
add_caf_test(syncall 8 syncall)
804-
add_caf_test(syncimages 8 syncimages)
805-
add_caf_test(syncimages2 8 syncimages2)
806-
add_caf_test(duplicate_syncimages 8 duplicate_syncimages)
807803
add_caf_test(co_reduce 4 co_reduce_test)
808804
add_caf_test(co_reduce_res_im 4 co_reduce_res_im)
809805
add_caf_test(co_reduce_string 4 co_reduce_string)
810806
add_caf_test(syncimages_status 8 syncimages_status)
811807
add_caf_test(sync_ring_abort_np3 3 sync_image_ring_abort_on_stopped_image)
812808
add_caf_test(sync_ring_abort_np7 7 sync_image_ring_abort_on_stopped_image)
813809
add_caf_test(simpleatomics 8 atomics)
810+
811+
# Synchronization tests
812+
add_caf_test(syncall 8 syncall)
813+
add_caf_test(syncimages 8 syncimages)
814+
add_caf_test(syncimages2 8 syncimages2)
815+
add_caf_test(duplicate_syncimages 8 duplicate_syncimages)
816+
814817
# possible logic error in the following test
815818
# add_caf_test(increment_my_neighbor 32 increment_my_neighbor)
816819

@@ -820,7 +823,6 @@ if(opencoarrays_aware_compiler)
820823
add_caf_test(co_heat 2 co_heat)
821824
add_caf_test(asynchronous_hello_world 3 asynchronous_hello_world)
822825

823-
824826
# Regression tests based on reported issues
825827
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
826828
if( CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0 )
Lines changed: 98 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,102 @@
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-
711
program main
72-
use object_interface, only : object
2+
!! author: Damian Rouson
3+
!!
4+
!! Test co_broadcast with derived-type actual arguments
735
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."
6+
7+
integer, parameter :: sender=1 !! co_broadcast source_image
8+
character(len=*), parameter :: text="text" !! character message data
9+
10+
associate(me=>this_image())
11+
12+
test_non_allocatable: block
13+
type parent
14+
integer :: heritable=0
15+
end type
16+
17+
type component
18+
integer :: subcomponent=0
19+
end type
20+
21+
type, extends(parent) :: child
22+
type(component) a
23+
character(len=len(text)) :: c="", z(0)
24+
complex :: i=(0.,0.), j(1)=(0.,0.)
25+
integer :: k=0, l(2,3)=0
26+
real :: r=0., s(3,2,1)=0.
27+
logical :: t=.false., u(1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3)=.false.
28+
end type
29+
30+
type(child) message
31+
type(child) :: content = child( &
32+
parent=parent(heritable=-2), a=component(-1), c=text, z=[character(len=len(text))::], &
33+
i=(0.,1.), j=(2.,3.), k=4, l=5, r=7., s=8., t=.true., u=.true. &
34+
)
35+
if (me==sender) message = content
36+
37+
call co_broadcast(message,source_image=sender)
38+
39+
associate( failures => [ &
40+
message%parent%heritable /= content%parent%heritable, &
41+
message%a%subcomponent /= content%a%subcomponent, &
42+
message%c /= content%c, &
43+
message%z /= content%z, &
44+
message%i /= content%i, &
45+
message%j /= content%j, &
46+
message%k /= content%k, &
47+
message%l /= content%l, &
48+
message%r /= content%r, &
49+
message%s /= content%s, &
50+
message%t .neqv. content%t, &
51+
any( message%u .neqv. content%u ) &
52+
] )
53+
54+
if ( any(failures) ) error stop "Test failed in non-allocatable block."
55+
56+
end associate
57+
58+
end block test_non_allocatable
59+
60+
test_allocatable: block
61+
type dynamic
62+
character(len=:), allocatable :: string
63+
complex, allocatable :: scalar
64+
integer, allocatable :: vector(:)
65+
logical, allocatable :: matrix(:,:)
66+
real, allocatable :: superstring(:,:,:, :,:,:, :,:,:, :,:,:, :,:,: )
67+
end type
68+
69+
type(dynamic) alloc_message, alloc_content
70+
71+
alloc_content = dynamic( &
72+
string=text, &
73+
scalar=(0.,1.), &
74+
vector=reshape( [integer::], [0]), &
75+
matrix=reshape( [.true.], [1,1]), &
76+
superstring=reshape([1,2,3,4], [2,1,2, 1,1,1, 1,1,1, 1,1,1, 1,1,1 ]) &
77+
)
78+
79+
if (me==sender) alloc_message = alloc_content
80+
81+
call co_broadcast(alloc_message,source_image=sender)
82+
83+
associate( failures => [ &
84+
alloc_message%string /= alloc_content%string, &
85+
alloc_message%scalar /= alloc_content%scalar, &
86+
alloc_message%vector /= alloc_content%vector, &
87+
alloc_message%matrix .neqv. alloc_content%matrix, &
88+
alloc_message%superstring /= alloc_content%superstring &
89+
] )
90+
91+
if ( any(failures) ) error stop "Test failed in allocatable block."
92+
93+
end associate
94+
95+
end block test_allocatable
96+
97+
sync all ! Wait for each image to pass the test
98+
if (me==sender) print *,"Test passed."
99+
100+
end associate
94101

95102
end program main

0 commit comments

Comments
 (0)