Skip to content

Commit 582ca37

Browse files
author
Alessandro Fanfarillo
committed
Bugfix for strided_sendget and testcase
1 parent 1eb9ce1 commit 582ca37

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ if(opencoarrays_aware_compiler)
213213
add_mpi_test(get_with_offset_1d 2 ${tests_root}/unit/send-get/get_with_offset_1d)
214214
add_mpi_test(whole_get_array 2 ${tests_root}/unit/send-get/whole_get_array)
215215
add_mpi_test(strided_get 2 ${tests_root}/unit/send-get/strided_get)
216+
add_mpi_test(strided_sendget 4 ${tests_root}/unit/send-get/strided_sendget)
216217
add_mpi_test(co_sum 4 ${tests_root}/unit/collectives/co_sum_test)
217218
add_mpi_test(co_broadcast 4 ${tests_root}/unit/collectives/co_broadcast_test)
218219
add_mpi_test(co_min 4 ${tests_root}/unit/collectives/co_min_test)

src/mpi/mpi_caf.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,37 +912,42 @@ PREFIX (sendget) (caf_token_t token_s, size_t offset_s, int image_index_s,
912912
ptrdiff_t array_offset_dst = 0;
913913
ptrdiff_t stride = 1;
914914
ptrdiff_t extent = 1;
915+
ptrdiff_t tot_ext = 1;
915916
for (j = 0; j < rank-1; j++)
916917
{
917-
array_offset_dst += ((i / (extent*stride))
918+
array_offset_dst += ((i / tot_ext)
918919
% (dest->dim[j]._ubound
919920
- dest->dim[j].lower_bound + 1))
920921
* dest->dim[j]._stride;
921922
extent = (dest->dim[j]._ubound - dest->dim[j].lower_bound + 1);
922923
stride = dest->dim[j]._stride;
924+
tot_ext *= extent;
923925
}
924926

927+
array_offset_dst += (i / tot_ext) * dest->dim[rank-1]._stride;
928+
925929
extent = (dest->dim[rank-1]._ubound - dest->dim[rank-1].lower_bound + 1);
926-
array_offset_dst += (i / extent) * dest->dim[rank-1]._stride;
927930
dst_offset = offset_s + array_offset_dst*GFC_DESCRIPTOR_SIZE (dest);
928931

929932
ptrdiff_t array_offset_sr = 0;
930933
if (GFC_DESCRIPTOR_RANK (src) != 0)
931934
{
932935
stride = 1;
933936
extent = 1;
937+
tot_ext = 1;
934938
for (j = 0; j < GFC_DESCRIPTOR_RANK (src)-1; j++)
935939
{
936-
array_offset_sr += ((i / (extent*stride))
940+
array_offset_sr += ((i / tot_ext)
937941
% (src->dim[j]._ubound
938942
- src->dim[j].lower_bound + 1))
939943
* src->dim[j]._stride;
940944
extent = (src->dim[j]._ubound - src->dim[j].lower_bound + 1);
941945
stride = src->dim[j]._stride;
946+
tot_ext *= extent;
942947
}
943948

944-
extent = (src->dim[rank-1]._ubound - src->dim[rank-1].lower_bound + 1);
945-
array_offset_sr += (i / extent) * src->dim[rank-1]._stride;
949+
/* extent = (src->dim[rank-1]._ubound - src->dim[rank-1].lower_bound + 1); */
950+
array_offset_sr += (i / tot_ext) * src->dim[rank-1]._stride;
946951
array_offset_sr *= GFC_DESCRIPTOR_SIZE (src);
947952
}
948953
src_offset = offset_g + array_offset_sr;

src/tests/unit/send-get/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ target_link_libraries(whole_get_array OpenCoarrays)
1818

1919
add_executable(strided_get strided_get.f90)
2020
target_link_libraries(strided_get OpenCoarrays)
21+
22+
add_executable(strided_sendget strided_sendget.f90)
23+
target_link_libraries(strided_sendget OpenCoarrays)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
program stridedsendgettest
2+
3+
implicit none
4+
5+
integer, save, dimension(4,6) :: srcmat[*], dstmat[*]
6+
integer, save, dimension(6) :: srcvec[*], dstvec[*]
7+
integer :: i
8+
logical :: test_passed = .true.
9+
10+
if (this_image() == 2) then
11+
srcvec = [(2 * i, i = 1, 6)]
12+
srcmat = reshape([(i * 2, i = 1, 4*6)], [4,6])
13+
elseif (this_image() == 3) then
14+
dstmat = -1
15+
dstvec = -2
16+
end if
17+
18+
sync all
19+
if (this_image() == 1) then
20+
dstvec(:)[3] = srcvec(:)[2]
21+
dstmat(3,:)[3] = srcvec(:)[2]
22+
end if
23+
24+
sync all
25+
if (this_image() == 3) then
26+
if (any(dstvec(:) /= [2, 4, 6, 8, 10, 12])) then
27+
print *, dstvec(:)
28+
print *, "SendGet vec/vec does not match."
29+
! error stop "SendGet vec/vec does not match."
30+
test_passed = .false.
31+
end if
32+
33+
if (any(dstmat(3,:) /= [2, 4, 6, 8, 10, 12])) then
34+
print *, dstmat(3,:)
35+
print *, "SendGet matrow/vec does not match."
36+
! error stop "SendGet matrow/vec does not match."
37+
test_passed = .false.
38+
end if
39+
end if
40+
41+
sync all
42+
if (this_image() == 1) then
43+
dstvec(:)[3] = srcmat(2,:)[2]
44+
dstmat(3,:)[3] = srcmat(2,:)[2]
45+
end if
46+
47+
sync all
48+
if (this_image() == 3) then
49+
if (any(dstvec(:) /= [4, 12, 20, 28, 36, 44])) then
50+
print *, dstvec(:)
51+
print *, "SendGet vec/matrow does not match."
52+
! error stop "SendGet vec/matrow does not match."
53+
test_passed = .false.
54+
end if
55+
56+
if (any(dstmat(3,:) /= [4, 12, 20, 28, 36, 44])) then
57+
print *, dstmat(3,:)
58+
print *, "SendGet matrow/matrow does not match."
59+
! error stop "SendGet matrow/matrow does not match."
60+
test_passed = .false.
61+
end if
62+
63+
if (test_passed) print *, "Test passed"
64+
end if
65+
66+
end program

0 commit comments

Comments
 (0)