Skip to content

Commit 285b02b

Browse files
committed
Thoroughly document unit/send-get/strided_sendget.f90.
Use only the needed number of images for the testing strided_sendget.
1 parent 2c6a9b3 commit 285b02b

File tree

2 files changed

+73
-35
lines changed

2 files changed

+73
-35
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +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)
216+
add_mpi_test(strided_sendget 3 ${tests_root}/unit/send-get/strided_sendget)
217217
add_mpi_test(co_sum 4 ${tests_root}/unit/collectives/co_sum_test)
218218
add_mpi_test(co_broadcast 4 ${tests_root}/unit/collectives/co_broadcast_test)
219219
add_mpi_test(co_min 4 ${tests_root}/unit/collectives/co_min_test)
Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,105 @@
1+
! Test that sendget with strides on either side (of the assignment) works
2+
! as expected.
3+
!
4+
! This test needs at least three images, because sendget has the potential
5+
! to check whether on image used in the communication is the current one.
6+
! More than three images do not pay, because there is no general code in
7+
! this test.
8+
!
19
! Written by Andre Vehreschild
10+
211
program stridedsendgettest
312

413
implicit none
514

15+
integer, parameter :: src_image = 2, dst_image = 3, master_image = 1
616
integer, save, dimension(4,6) :: srcmat[*], dstmat[*]
717
integer, save, dimension(6) :: srcvec[*], dstvec[*]
818
integer :: i
919
logical :: test_passed = .true.
1020

11-
if (this_image() == 2) then
21+
! Make sure that enough images are available for this test.
22+
! Everything less than dst_image == 3 may make sendget use an
23+
! optimized version saving a part of the communication, which is
24+
! not what the test should test.
25+
if (num_images() < dst_image) error stop "Need at least three images."
26+
27+
! On the src_image, set some defined values, to be able to distinguish
28+
! strides going wrong.
29+
if (this_image() == src_image) then
1230
srcvec = [(2 * i, i = 1, 6)]
1331
srcmat = reshape([(i * 2, i = 1, 4*6)], [4,6])
14-
elseif (this_image() == 3) then
32+
! On the dst_image set values that enable to recognize unset values.
33+
elseif (this_image() == dst_image) then
1534
dstmat = -1
1635
dstvec = -2
1736
end if
1837

38+
! Make sure data is valid on all images.
1939
sync all
20-
if (this_image() == 1) then
21-
dstvec(:)[3] = srcvec(:)[2]
22-
dstmat(3,:)[3] = srcvec(:)[2]
40+
41+
! master_image is the controller in this communication and therefore needs
42+
! to initiate the communication.
43+
if (this_image() == master_image) then
44+
! Transfer data from the src-vector to the dst-vector on image
45+
! dst_image. This is a transfer of a contingous block of data and here for
46+
! completeness only.
47+
dstvec(:)[dst_image] = srcvec(:)[src_image]
48+
! This statement uses a stride in the send phase of the communication.
49+
dstmat(3,:)[dst_image] = srcvec(:)[src_image]
2350
end if
2451

52+
! Make sure the communication has completed.
2553
sync all
26-
if (this_image() == 3) then
27-
if (any(dstvec(:) /= [2, 4, 6, 8, 10, 12])) then
28-
print *, dstvec(:)
29-
print *, "SendGet vec/vec does not match."
30-
! error stop "SendGet vec/vec does not match."
31-
test_passed = .false.
32-
end if
3354

34-
if (any(dstmat(3,:) /= [2, 4, 6, 8, 10, 12])) then
35-
print *, dstmat(3,:)
36-
print *, "SendGet matrow/vec does not match."
37-
! error stop "SendGet matrow/vec does not match."
38-
test_passed = .false.
55+
! Check the result of communication on the dst_image.
56+
if (this_image() == dst_image) then
57+
! Check that transfering to the vector has succeeded.
58+
if (any(dstvec /= [2, 4, 6, 8, 10, 12])) error stop "SendGet vec/vec does not match."
59+
60+
! Check that transfering a vector into a matrix changes only the
61+
! values desired.
62+
if (any(dstmat /= reshape([-1, -1, 2, -1, &
63+
-1, -1, 4, -1, &
64+
-1, -1, 6, -1, &
65+
-1, -1, 8, -1, &
66+
-1, -1, 10, -1, &
67+
-1, -1, 12, -1], [4, 6]))) then
68+
error stop "SendGet matrow/vec does not match."
3969
end if
70+
! Reset the dst-buffers to enable new test.
71+
dstvec = -2
72+
dstmat = -1
4073
end if
4174

75+
! Wait for dst having done its tests.
4276
sync all
43-
if (this_image() == 1) then
44-
dstvec(:)[3] = srcmat(2,:)[2]
45-
dstmat(3,:)[3] = srcmat(2,:)[2]
77+
if (this_image() == master_image) then
78+
! Execute strided get in sendget and store in a vector to just
79+
! test the get.
80+
dstvec(:)[dst_image] = srcmat(2,:)[src_image]
81+
! Test both strided get and strided send at once.
82+
dstmat(3,:)[dst_image] = srcmat(2,:)[src_image]
4683
end if
4784

85+
! Ensure that the communication is all done.
4886
sync all
49-
if (this_image() == 3) then
50-
if (any(dstvec(:) /= [4, 12, 20, 28, 36, 44])) then
51-
print *, dstvec(:)
52-
print *, "SendGet vec/matrow does not match."
53-
! error stop "SendGet vec/matrow does not match."
54-
test_passed = .false.
55-
end if
87+
if (this_image() == dst_image) then
88+
! Check, that the strided get has the expected result.
89+
if (any(dstvec /= [4, 12, 20, 28, 36, 44])) error stop "SendGet vec/matrow does not match."
5690

57-
if (any(dstmat(3,:) /= [4, 12, 20, 28, 36, 44])) then
58-
print *, dstmat(3,:)
59-
print *, "SendGet matrow/matrow does not match."
60-
! error stop "SendGet matrow/matrow does not match."
61-
test_passed = .false.
91+
! And that both communications with stride work as expected.
92+
if (any(dstmat /= reshape([-1, -1, 4, -1, &
93+
-1, -1, 12, -1, &
94+
-1, -1, 20, -1, &
95+
-1, -1, 28, -1, &
96+
-1, -1, 36, -1, &
97+
-1, -1, 44, -1], [4, 6]))) then
98+
error stop "SendGet matrow/matrow does not match."
6299
end if
63100

64-
if (test_passed) print *, "Test passed"
101+
! Above checks would stop with an error on failure, so its save
102+
! to unguardedly print here, when all tests pass.
103+
print *, "Test passed"
65104
end if
66-
67105
end program

0 commit comments

Comments
 (0)