Skip to content

Commit 9900f82

Browse files
author
Damian Rouson
authored
Merge pull request #684 from sourceryinstitute/co_broadcast-derived-type
Expand co_broadcast test coverage for derived type arguments; remove temporary diagnostic output
2 parents 2dc92d1 + 0c55821 commit 9900f82

File tree

5 files changed

+166
-94
lines changed

5 files changed

+166
-94
lines changed

CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,23 +802,29 @@ if(opencoarrays_aware_compiler)
802802
add_caf_test(strided_sendget 3 strided_sendget)
803803
add_caf_test(get_with_vector_index 4 get_with_vector_index)
804804

805-
805+
# Collective subroutine tests
806806
add_caf_test(co_sum 4 co_sum_test)
807807
add_caf_test(co_broadcast 4 co_broadcast_test)
808808
add_caf_test(co_broadcast_derived_type 4 co_broadcast_derived_type_test)
809+
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
810+
add_caf_test(co_broadcast_allocatable_components 4 co_broadcast_allocatable_components_test)
811+
endif()
809812
add_caf_test(co_min 4 co_min_test)
810813
add_caf_test(co_max 4 co_max_test)
811-
add_caf_test(syncall 8 syncall)
812-
add_caf_test(syncimages 8 syncimages)
813-
add_caf_test(syncimages2 8 syncimages2)
814-
add_caf_test(duplicate_syncimages 8 duplicate_syncimages)
815814
add_caf_test(co_reduce 4 co_reduce_test)
816815
add_caf_test(co_reduce_res_im 4 co_reduce_res_im)
817816
add_caf_test(co_reduce_string 4 co_reduce_string)
818817
add_caf_test(syncimages_status 8 syncimages_status)
819818
add_caf_test(sync_ring_abort_np3 3 sync_image_ring_abort_on_stopped_image)
820819
add_caf_test(sync_ring_abort_np7 7 sync_image_ring_abort_on_stopped_image)
821820
add_caf_test(simpleatomics 8 atomics)
821+
822+
# Synchronization tests
823+
add_caf_test(syncall 8 syncall)
824+
add_caf_test(syncimages 8 syncimages)
825+
add_caf_test(syncimages2 8 syncimages2)
826+
add_caf_test(duplicate_syncimages 8 duplicate_syncimages)
827+
822828
# possible logic error in the following test
823829
# add_caf_test(increment_my_neighbor 32 increment_my_neighbor)
824830

@@ -828,7 +834,6 @@ if(opencoarrays_aware_compiler)
828834
add_caf_test(co_heat 2 co_heat)
829835
add_caf_test(asynchronous_hello_world 3 asynchronous_hello_world)
830836

831-
832837
# Regression tests based on reported issues
833838
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
834839
if( CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0 )

src/mpi/mpi_caf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7380,8 +7380,6 @@ PREFIX(co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat,
73807380
size *= dimextent;
73817381
}
73827382

7383-
printf("DTYPE Size: %zd\n",GFC_DESCRIPTOR_SIZE(a));
7384-
73857383
if (rank == 0)
73867384
{
73877385
if( datatype == MPI_BYTE)

src/tests/unit/collectives/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
caf_compile_executable(co_sum_test co_sum.F90)
22
caf_compile_executable(co_broadcast_test co_broadcast.F90)
33
caf_compile_executable(co_broadcast_derived_type_test co_broadcast_derived_type.f90)
4+
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
5+
caf_compile_executable(co_broadcast_allocatable_components_test co_broadcast_allocatable_components.f90)
6+
endif()
47
caf_compile_executable(co_min_test co_min.F90)
58
caf_compile_executable(co_max_test co_max.F90)
69
caf_compile_executable(co_reduce_test co_reduce.F90)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
program main
2+
!! author: Damian Rouson
3+
!!
4+
!! Test co_broadcast with derived-type actual arguments
5+
implicit none
6+
7+
integer, parameter :: sender=1 !! co_broadcast source_image
8+
character(len=*), parameter :: text="text" !! character message data
9+
10+
type dynamic
11+
character(len=:), allocatable :: string
12+
character(len=len(text)), allocatable :: string_array(:)
13+
complex, allocatable :: scalar
14+
integer, allocatable :: vector(:)
15+
logical, allocatable :: matrix(:,:)
16+
real, allocatable :: superstring(:,:,:, :,:,:, :,:,:, :,:,:, :,:,: )
17+
end type
18+
19+
type(dynamic) alloc_message, alloc_content
20+
21+
associate(me=>this_image())
22+
23+
alloc_content = dynamic( &
24+
string=text, &
25+
string_array=[text], &
26+
scalar=(0.,1.), &
27+
vector=reshape( [integer::], [0]), &
28+
matrix=reshape( [.true.], [1,1]), &
29+
superstring=reshape([1,2,3,4], [2,1,2, 1,1,1, 1,1,1, 1,1,1, 1,1,1 ]) &
30+
)
31+
32+
alloc_message = alloc_content
33+
34+
if(me /= sender) then
35+
alloc_message%vector = 0
36+
alloc_message%matrix = .false.
37+
alloc_message%superstring = 0
38+
endif
39+
40+
sync all
41+
42+
call co_broadcast(alloc_message,source_image=sender)
43+
44+
associate( failures => [ &
45+
alloc_message%string /= alloc_content%string, &
46+
alloc_message%string_array /= alloc_content%string_array, &
47+
alloc_message%scalar /= alloc_content%scalar, &
48+
alloc_message%vector /= alloc_content%vector, &
49+
alloc_message%matrix .neqv. alloc_content%matrix, &
50+
alloc_message%superstring /= alloc_content%superstring &
51+
] )
52+
53+
if ( any(failures) ) error stop "Test failed."
54+
55+
end associate
56+
57+
sync all ! Wait for each image to pass the test
58+
if (me==sender) print *,"Test passed."
59+
60+
end associate
61+
62+
end program main
Lines changed: 90 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,99 @@
1-
module object_interface
1+
program main
2+
!! author: Damian Rouson
3+
!!
4+
!! Test co_broadcast with derived-type actual arguments
25
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
6+
7+
integer, parameter :: sender=1 !! co_broadcast source_image
8+
character(len=*), parameter :: text="text" !! character message data
189

1910
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
11+
function f(x) result(y)
12+
real x, y
13+
end function
4414
end interface
4515

46-
end module
16+
type parent
17+
integer :: heritable=0
18+
end type
4719

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
20+
type component
21+
integer :: subcomponent=0
22+
end type
7023

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."
24+
type, extends(parent) :: child
25+
26+
! Scalar and array derived-type components
27+
type(component) a, b(1,2,1, 1,1,1, 1)
28+
29+
! Scalar and array intrinsic-type components
30+
character(len=len(text)) :: c="", z(0)
31+
complex :: i=(0.,0.), j(1)=(0.,0.)
32+
integer :: k=0, l(2,3)=0
33+
logical :: r=.false., s(1,2,3, 1,2,3, 1)=.false.
34+
real :: t=0., u(3,2,1)=0.
35+
36+
! Scalar and array pointer components
37+
character(len=len(text)), pointer :: &
38+
char_ptr=>null(), char_ptr_maxdim(:,:,:, :,:,:, :)=>null()
39+
complex, pointer :: cplx_ptr=>null(), cplx_ptr_maxdim(:,:,:, :,:,:, :)=>null()
40+
integer, pointer :: int_ptr =>null(), int_ptr_maxdim (:,:,:, :,:,:, :)=>null()
41+
logical, pointer :: bool_ptr=>null(), bool_ptr_maxdim(:,:,:, :,:,:, :)=>null()
42+
real, pointer :: real_ptr=>null(), real_ptr_maxdim(:,:,:, :,:,:, :)=>null()
43+
procedure(f), pointer :: procedure_pointer=>null()
44+
end type
45+
46+
type(child) message
47+
type(child) :: content = child( & ! define content using the insrinsic structure constructor
48+
parent=parent(heritable=-4), & ! parent
49+
a=component(-3), b=reshape([component(-2),component(-1)], [1,2,1, 1,1,1, 1]), & ! derived types
50+
c=text, z=[character(len=len(text))::], i=(0.,1.), j=(2.,3.), k=4, l=5, r=.true., s=.true., t=7., u=8. & ! intrinsic types
51+
)
52+
53+
associate(me=>this_image())
54+
55+
if (me==sender) then
56+
message = content
57+
allocate(message%char_ptr, message%char_ptr_maxdim(1,1,2, 1,1,1, 1), source=text )
58+
allocate(message%cplx_ptr, message%cplx_ptr_maxdim(1,1,1, 1,1,2, 1), source=(0.,1.))
59+
allocate(message%int_ptr , message%int_ptr_maxdim (1,1,1, 1,1,1, 1), source=2 )
60+
allocate(message%bool_ptr, message%bool_ptr_maxdim(1,1,1, 1,2,1, 1), source=.true. )
61+
allocate(message%real_ptr, message%real_ptr_maxdim(1,1,1, 1,1,1, 1), source=3. )
62+
end if
63+
64+
call co_broadcast(message,source_image=sender)
65+
66+
if (me==sender) then
67+
deallocate(message%char_ptr, message%char_ptr_maxdim)
68+
deallocate(message%cplx_ptr, message%cplx_ptr_maxdim)
69+
deallocate(message%int_ptr , message%int_ptr_maxdim )
70+
deallocate(message%bool_ptr, message%bool_ptr_maxdim)
71+
deallocate(message%real_ptr, message%real_ptr_maxdim)
72+
end if
73+
74+
!! Verify correct broadcast of all non-pointer components (pointers become undefined on the receiving image).
75+
associate( failures => [ &
76+
message%parent%heritable /= content%parent%heritable, &
77+
message%a%subcomponent /= content%a%subcomponent, &
78+
message%c /= content%c, &
79+
message%z /= content%z, &
80+
message%i /= content%i, &
81+
message%j /= content%j, &
82+
message%k /= content%k, &
83+
message%l /= content%l, &
84+
message%r .neqv. content%r, &
85+
message%s .neqv. content%s, &
86+
message%t /= content%t, &
87+
any( message%u /= content%u ) &
88+
] )
89+
90+
if ( any(failures) ) error stop "Test failed. "
91+
92+
end associate
93+
94+
sync all ! Wait for each image to pass the test
95+
if (me==sender) print *,"Test passed."
96+
97+
end associate
9498

9599
end program main

0 commit comments

Comments
 (0)