Skip to content

Commit 31f7f18

Browse files
authored
Merge pull request #751 from sourceryinstitute/issue-727-co-broadcast-on-mixed-derived-type
Issue 727 co broadcast on mixed derived type
2 parents db82afc + fb165fd commit 31f7f18

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

Diff for: CMakeLists.txt

+3
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)

Diff for: src/mpi/mpi_caf.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -7524,6 +7524,8 @@ PREFIX(co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat,
75247524
size *= dimextent;
75257525
}
75267526

7527+
dprint("Using mpi-datatype: 0x%x in co_broadcast (base_addr=%p, rank= %d).\n",
7528+
datatype, a->base_addr, rank);
75277529
if (rank == 0)
75287530
{
75297531
if( datatype == MPI_BYTE)
@@ -7564,16 +7566,17 @@ PREFIX(co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat,
75647566

75657567
for (i = 0; i < size; ++i)
75667568
{
7567-
ptrdiff_t array_offset_sr = 0, tot_ext = 1, extent = 1;
7569+
ptrdiff_t array_offset = 0, tot_ext = 1, extent = 1;
75687570
for (j = 0; j < rank - 1; ++j)
75697571
{
75707572
extent = a->dim[j]._ubound - a->dim[j].lower_bound + 1;
7571-
array_offset_sr += ((i / tot_ext) % extent) * a->dim[j]._stride;
7573+
array_offset += ((i / tot_ext) % extent) * a->dim[j]._stride;
75727574
tot_ext *= extent;
75737575
}
7574-
array_offset_sr += (i / tot_ext) * a->dim[rank - 1]._stride;
7576+
array_offset += (i / tot_ext) * a->dim[rank - 1]._stride;
7577+
dprint("The array offset for element %d used in co_broadcast is %d\n", i, array_offset);
75757578
void *sr = (void *)(
7576-
(char *)a->base_addr + array_offset_sr * GFC_DESCRIPTOR_SIZE(a));
7579+
(char *)a->base_addr + array_offset * GFC_DESCRIPTOR_SIZE(a));
75777580

75787581
ierr = MPI_Bcast(sr, 1, datatype, source_image - 1, CAF_COMM_WORLD);
75797582
chk_err(ierr);

Diff for: src/tests/unit/collectives/CMakeLists.txt

+3
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)
+78
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)