Skip to content

Commit 8594a4b

Browse files
committed
Merge remote-tracking branch 'neo/gatherv'
2 parents 2e9f096 + 54891fb commit 8594a4b

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ if(opencoarrays_aware_compiler)
776776
add_caf_test(issue-488-multi-dim-cobounds-true 8 issue-488-multi-dim-cobounds true)
777777
add_caf_test(issue-488-multi-dim-cobounds-false 8 issue-488-multi-dim-cobounds false)
778778
add_caf_test(issue-503-multidim-array-broadcast 2 issue-503-multidim-array-broadcast)
779+
if((gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
780+
add_caf_test(issue-515-mimic-mpi-gatherv 2 issue-515-mimic-mpi-gatherv)
781+
endif()
779782

780783
# IMAGE FAIL tests
781784
if(NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)

src/mpi/mpi_caf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4626,6 +4626,8 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
46264626
dst->dim[dst_cur_dim].lower_bound = 1;
46274627
dst->dim[dst_cur_dim]._ubound = delta;
46284628
dst->dim[dst_cur_dim]._stride = size;
4629+
if (realloc_required)
4630+
dst->offset = -1;
46294631
}
46304632
}
46314633

@@ -4779,6 +4781,8 @@ PREFIX (get_by_ref) (caf_token_t token, int image_index,
47794781
dst->dim[dst_cur_dim].lower_bound = 1;
47804782
dst->dim[dst_cur_dim]._ubound = delta;
47814783
dst->dim[dst_cur_dim]._stride = size;
4784+
if (realloc_required)
4785+
dst->offset = -1;
47824786
}
47834787
}
47844788
/* Only increase the dim counter, when in an array ref */

src/tests/regression/reported/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ caf_compile_executable(issue-422-send issue-422-send.F90)
88
caf_compile_executable(issue-422-send-get issue-422-send-get.F90)
99
caf_compile_executable(issue-488-multi-dim-cobounds issue-488-multi-dim-cobounds.f90)
1010
caf_compile_executable(issue-503-multidim-array-broadcast issue-503-multidim-array-broadcast.f90)
11+
if (gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0))
12+
caf_compile_executable(issue-515-mimic-mpi-gatherv issue-515-mimic-mpi-gatherv.f90)
13+
endif()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
! caf -o gather gather.f90
2+
! cafrun -np 2 ./gather
3+
! this example mimics a mpi_gatherv with root=1, and variable size chunks
4+
! gather into specified locations from all processes in a group
5+
6+
program gather
7+
implicit none
8+
9+
type gvec ! a global vector
10+
real, allocatable :: a(:)
11+
end type
12+
13+
type(gvec) :: gc[*]
14+
real, allocatable :: gv(:), tmp(:)
15+
integer :: me, nimg, gsize, i, lo, hi
16+
logical :: fail = .false.
17+
18+
me = this_image()
19+
nimg = num_images()
20+
21+
allocate(gc % a(2 * me)) ! variable size data in container
22+
gc % a = [(me * i, i=1, 2 * me)] ! assignement
23+
24+
! collect the global vector size by summing local sizes
25+
gsize = size(gc % a)
26+
call co_sum(gsize, result_image=1)
27+
sync all
28+
29+
if (me == 1) then
30+
if (gsize /= 6) error stop 1
31+
allocate(gv(gsize)) ! allocate a global vector of size 6 on img 1
32+
lo = 1
33+
do i = 1, nimg
34+
tmp = gc[i] % a ! note: automatic reallocation of tmp
35+
hi = lo + size(tmp) - 1
36+
gv(lo:hi) = tmp
37+
lo = hi + 1 ! start of next chunk
38+
end do
39+
print *, 'gv=', gv, ' sum=', sum(gv)
40+
41+
if (abs(sum(gv) - 23.) > epsilon(0.)) fail = .true.
42+
end if
43+
44+
sync all
45+
46+
! CMake test output handler
47+
call co_broadcast(fail, source_image=1)
48+
if (fail) then
49+
write(*, *) 'Test failed!'
50+
error stop 5
51+
else
52+
write(*, *) 'Test passed.'
53+
end if
54+
55+
end program

0 commit comments

Comments
 (0)