Skip to content

Commit 5a092eb

Browse files
committed
Add test case for issue 727
1 parent 896f2dd commit 5a092eb

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ if(opencoarrays_aware_compiler)
813813
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
814814
add_caf_test(co_broadcast_allocatable_components 4 co_broadcast_allocatable_components_test)
815815
endif()
816+
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.2.2)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
817+
add_caf_test(co_broadcast_alloc_mixed 2 co_broadcast_alloc_mixed)
818+
endif()
816819
add_caf_test(co_min 4 co_min_test)
817820
add_caf_test(co_max 4 co_max_test)
818821
add_caf_test(co_reduce 4 co_reduce_test)

src/tests/unit/collectives/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ caf_compile_executable(co_broadcast_derived_type_test co_broadcast_derived_type.
44
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
55
caf_compile_executable(co_broadcast_allocatable_components_test co_broadcast_allocatable_components.f90)
66
endif()
7+
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 11.2.2)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
8+
caf_compile_executable(co_broadcast_alloc_mixed co_broadcast_alloc_mixed.f90)
9+
endif()
710
caf_compile_executable(co_min_test co_min.F90)
811
caf_compile_executable(co_max_test co_max.F90)
912
caf_compile_executable(co_reduce_test co_reduce.F90)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
program co_broadcast_derived_with_allocs_test
2+
!! author: Brad Richardson & Andre Vehreschild
3+
!! category: regression
4+
!!
5+
!! [issue #727](https://github.com/sourceryinstitute/opencoarrays/issues/727)
6+
!! broadcasting derived types with a mixture of scalar and allocatable
7+
!! scalars or arrays lead to unexpected results
8+
9+
implicit none
10+
11+
type nsas_t
12+
integer :: i
13+
integer, allocatable :: j
14+
end type
15+
16+
type asas_t
17+
integer, allocatable :: i
18+
integer, allocatable :: j
19+
end type
20+
21+
type nsaa_t
22+
integer :: i
23+
integer, allocatable :: j(:)
24+
end type
25+
26+
type naaa_t
27+
integer :: i(3)
28+
integer, allocatable :: j(:)
29+
end type
30+
31+
type(nsas_t) nsas
32+
type(asas_t) asas
33+
type(nsaa_t) nsaa
34+
type(naaa_t) naaa
35+
36+
integer, parameter :: source_image = 1
37+
38+
if (this_image() == source_image) then
39+
nsas = nsas_t(2, 3)
40+
41+
asas = asas_t(4, 5)
42+
43+
nsaa = nsaa_t(6, (/ 7, 8 /))
44+
45+
naaa = naaa_t((/ 9,10,11 /), (/ 12,13,14,15 /))
46+
else
47+
allocate(nsas%j)
48+
49+
allocate(asas%i); allocate(asas%j)
50+
51+
allocate(nsaa%j(2))
52+
53+
allocate(naaa%j(4))
54+
end if
55+
56+
print *, "nsas"
57+
call co_broadcast(nsas, source_image)
58+
if (nsas%i /= 2 .or. nsas%j /= 3) error stop "Test failed at 1."
59+
60+
print *, "asas"
61+
call co_broadcast(asas, source_image)
62+
if (asas%i /= 4 .or. asas%j /= 5) error stop "Test failed at 2."
63+
64+
print *, "nsaa"
65+
call co_broadcast(nsaa, source_image)
66+
if (nsaa%i /= 6 .or. any(nsaa%j(:) /= (/ 7, 8 /))) error stop "Test failed at 3."
67+
68+
print *, "naaa"
69+
call co_broadcast(naaa, source_image)
70+
if (any(naaa%i(:) /= (/ 9,10,11 /)) .or. any(naaa%j(:) /= (/ 12,13,14,15 /))) then
71+
error stop "Test failed at 3."
72+
end if
73+
74+
sync all
75+
76+
print *, "Test passed."
77+
78+
end

0 commit comments

Comments
 (0)