|
| 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 | +! |
1 | 9 | ! Written by Andre Vehreschild
|
| 10 | + |
2 | 11 | program stridedsendgettest
|
3 | 12 |
|
4 | 13 | implicit none
|
5 | 14 |
|
| 15 | + integer, parameter :: src_image = 2, dst_image = 3, master_image = 1 |
6 | 16 | integer, save, dimension(4,6) :: srcmat[*], dstmat[*]
|
7 | 17 | integer, save, dimension(6) :: srcvec[*], dstvec[*]
|
8 | 18 | integer :: i
|
9 | 19 | logical :: test_passed = .true.
|
10 | 20 |
|
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 |
12 | 30 | srcvec = [(2 * i, i = 1, 6)]
|
13 | 31 | 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 |
15 | 34 | dstmat = -1
|
16 | 35 | dstvec = -2
|
17 | 36 | end if
|
18 | 37 |
|
| 38 | + ! Make sure data is valid on all images. |
19 | 39 | 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] |
23 | 50 | end if
|
24 | 51 |
|
| 52 | + ! Make sure the communication has completed. |
25 | 53 | 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 |
33 | 54 |
|
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." |
39 | 69 | end if
|
| 70 | + ! Reset the dst-buffers to enable new test. |
| 71 | + dstvec = -2 |
| 72 | + dstmat = -1 |
40 | 73 | end if
|
41 | 74 |
|
| 75 | + ! Wait for dst having done its tests. |
42 | 76 | 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] |
46 | 83 | end if
|
47 | 84 |
|
| 85 | + ! Ensure that the communication is all done. |
48 | 86 | 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." |
56 | 90 |
|
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." |
62 | 99 | end if
|
63 | 100 |
|
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" |
65 | 104 | end if
|
66 |
| - |
67 | 105 | end program
|
0 commit comments