|
| 1 | +!! Thoroughly test send, i.e. foo[N].comp = bar in all variants |
| 2 | +!! |
| 3 | +!! Do simple tests for send(). These test comprise |
| 4 | +!! |
| 5 | +!! FOO[N].COMP = BAR |
| 6 | +!! |
| 7 | +!! where |
| 8 | +!! |
| 9 | +!! FOO BAR images |
| 10 | +!! scalar scalar N == me |
| 11 | +!! int(k e [1,4]) int(k e [1,4]) |
| 12 | +!! real(k e [4,8]) real(k e [4,8]) |
| 13 | +!! int(k e [1,4]) real(k e [4,8]) |
| 14 | +!! real(k e [4,8]) int(k e [1,4]) |
| 15 | +!! |
| 16 | +!! array(1:5) scalar |
| 17 | +!! int(k e [1,4]) int(k e [1,4]) |
| 18 | +!! real(k e [4,8]) real(k e [4,8]) |
| 19 | +!! int(k e [1,4]) real(k e [4,8]) |
| 20 | +!! real(k e [4,8]) int(k e [1,4]) |
| 21 | +!! |
| 22 | +!! array(1:5) array(1:5) |
| 23 | +!! int(k e [1,4]) int(k e [1,4]) |
| 24 | +!! real(k e [4,8]) real(k e [4,8]) |
| 25 | +!! int(k e [1,4]) real(k e [4,8]) |
| 26 | +!! real(k e [4,8]) int(k e [1,4]) |
| 27 | +!! |
| 28 | +!! array(1:3) array(::2) |
| 29 | +!! int(k e [1,4]) int(k e [1,4]) |
| 30 | +!! real(k e [4,8]) real(k e [4,8]) |
| 31 | +!! int(k e [1,4]) real(k e [4,8]) |
| 32 | +!! real(k e [4,8]) int(k e [1,4]) |
| 33 | +!! |
| 34 | +!! array(4:5) array(2::2) |
| 35 | +!! int(k e [1,4]) int(k e [1,4]) |
| 36 | +!! real(k e [4,8]) real(k e [4,8]) |
| 37 | +!! int(k e [1,4]) real(k e [4,8]) |
| 38 | +!! real(k e [4,8]) int(k e [1,4]) |
| 39 | +!! |
| 40 | +!! array(1:3) array(3:1:-1) |
| 41 | +!! int(k e [1,4]) int(k e [1,4]) |
| 42 | +!! real(k e [4,8]) real(k e [4,8]) |
| 43 | +!! int(k e [1,4]) real(k e [4,8]) |
| 44 | +!! real(k e [4,8]) int(k e [1,4]) |
| 45 | +!! |
| 46 | +!! all of the above but for N != me |
| 47 | +!! |
| 48 | +!! And may be some other, I've forgotten. |
| 49 | +!! |
| 50 | +!! Author: Andre Vehreschild, 2017 |
| 51 | + |
| 52 | +program alloc_comp_send_convert_nums |
| 53 | + use iso_fortran_env, only : int8,int32,real32,real64 |
| 54 | + |
| 55 | + implicit none |
| 56 | + |
| 57 | + real(kind=real32), parameter :: tolerance4 = 1.0e-4_real32 |
| 58 | + real(kind=real64), parameter :: tolerance4to8 = 1.0E-4_real64 |
| 59 | + real(kind=real64), parameter :: tolerance8 = 1.0E-6_real64 |
| 60 | + |
| 61 | + type t |
| 62 | + integer(kind=int8), allocatable :: int_scal_k1 |
| 63 | + integer(kind=int32), allocatable :: int_scal_k4 |
| 64 | + real(kind=real32) , allocatable :: real_scal_k4 |
| 65 | + real(kind=real64) , allocatable :: real_scal_k8 |
| 66 | + integer(kind=int8), allocatable, dimension(:) :: int_k1 |
| 67 | + integer(kind=int32), allocatable, dimension(:) :: int_k4 |
| 68 | + real(kind=real32) , allocatable, dimension(:) :: real_k4 |
| 69 | + real(kind=real64) , allocatable, dimension(:) :: real_k8 |
| 70 | + end type t |
| 71 | + |
| 72 | + integer(kind=int8) :: int_scal_k1 |
| 73 | + integer(kind=int32) :: int_scal_k4 |
| 74 | + real(kind=real32) :: real_scal_k4 |
| 75 | + real(kind=real64) :: real_scal_k8 |
| 76 | + |
| 77 | + integer(kind=int8), dimension(1:5) :: int_k1 |
| 78 | + integer(kind=int32), dimension(1:5) :: int_k4 |
| 79 | + real(kind=real32) , dimension(1:5) :: real_k4 |
| 80 | + real(kind=real64) , dimension(1:5) :: real_k8 |
| 81 | + |
| 82 | + type(t), save, codimension[*] :: obj |
| 83 | + |
| 84 | + logical :: error_printed=.false. |
| 85 | + |
| 86 | + associate(me => this_image(), np => num_images()) |
| 87 | + if (np < 2) error stop 'Cannot run with less than 2 images.' |
| 88 | + |
| 89 | + int_scal_k1 = INT(42, kind(int_scal_k1)) |
| 90 | + int_scal_k4 = 42 |
| 91 | + int_k1 = INT([5, 4, 3, 2, 1], kind(int_scal_k4)) |
| 92 | + int_k4 = [5, 4, 3, 2, 1] |
| 93 | + allocate(obj%int_scal_k1, obj%int_scal_k4, obj%int_k1(5), obj%int_k4(5)) ! allocate syncs here |
| 94 | + |
| 95 | + real_scal_k4 = 37.042 |
| 96 | + real_scal_k8 = REAL(37.042, kind(real_scal_k8)) |
| 97 | + real_k4 = [ 5.1, 4.2, 3.3, 2.4, 1.5] |
| 98 | + real_k8 = REAL([ 5.1, 4.2, 3.3, 2.4, 1.5], kind(real_k8)) |
| 99 | + allocate(obj%real_scal_k4, obj%real_scal_k8, obj%real_k4(1:5), obj%real_k8(1:5)) ! allocate syncs here |
| 100 | + |
| 101 | + ! Now with strides |
| 102 | + ! First check send/copy to self |
| 103 | + if (me == 1) then |
| 104 | + |
| 105 | + obj%int_k1(1:5) = int_k1(5:1:-1) |
| 106 | + obj[1]%int_k1(::2) = obj%int_k1(3:1:-1) |
| 107 | + print *, obj%int_k1 |
| 108 | + ! Note, indezes two times reversed! |
| 109 | + if (any(obj%int_k1 /= [int_k1(3), int_k1(4), int_k1(4), int_k1(2), int_k1(5)])) & |
| 110 | + & call print_and_register( 'send strided with temp int kind=int8 to kind=1 self failed') |
| 111 | + |
| 112 | + obj%int_k4(1:5) = int_k4(5:1:-1) |
| 113 | + obj[1]%int_k4(::2) = obj%int_k4(3:1:-1) |
| 114 | + print *, obj%int_k4 |
| 115 | + if (any(obj%int_k4 /= [int_k4(3), int_k4(4), int_k4(4), int_k4(2), int_k4(5)])) & |
| 116 | + & call print_and_register( 'send strided with temp int kind=4 to kind=4 self failed') |
| 117 | + else if (me == 2) then ! Do the real copy to self checks on image 2 |
| 118 | + |
| 119 | + obj%real_k4(1:5) = real_k4(5:1:-1) |
| 120 | + obj[2]%real_k4(::2) = obj%real_k4(3:1:-1) |
| 121 | + print *, obj%real_k4 |
| 122 | + if (any(abs(obj%real_k4 - [real_k4(3), real_k4(4), real_k4(4), real_k4(2), real_k4(5)]) > tolerance4)) & |
| 123 | + & call print_and_register( 'send strided with temp real kind=4 to kind=4 self failed') |
| 124 | + |
| 125 | + obj%real_k8(1:5) = real_k8(5:1:-1) |
| 126 | + obj[2]%real_k8(::2) = obj%real_k8(3:1:-1) |
| 127 | + print *, obj%real_k8 |
| 128 | + if (any(abs(obj%real_k8 - [real_k8(3), real_k8(4), real_k8(4), real_k8(2), real_k8(5)]) > tolerance8)) & |
| 129 | + & call print_and_register( 'send strided with temp real kind=real64 to kind=8 self failed') |
| 130 | + end if |
| 131 | + |
| 132 | + select case(me) |
| 133 | + case(1) |
| 134 | + sync images(2) ! wait for image 2 to finish all checks |
| 135 | + if (error_printed) error stop |
| 136 | + sync images(2) ! wait for image 2 to get past its conditional error termination |
| 137 | + print *, "Test passed." |
| 138 | + case(2) |
| 139 | + sync images(1) ! wait for image 1 to finish all checks |
| 140 | + if (error_printed) error stop |
| 141 | + sync images(1) |
| 142 | + end select |
| 143 | + end associate |
| 144 | + |
| 145 | +contains |
| 146 | + |
| 147 | + subroutine print_and_register(error_message) |
| 148 | + use iso_fortran_env, only : error_unit |
| 149 | + character(len=*), intent(in) :: error_message |
| 150 | + write(error_unit,*) error_message |
| 151 | + error_printed=.true. |
| 152 | + end subroutine |
| 153 | + |
| 154 | +end program alloc_comp_send_convert_nums |
| 155 | + |
| 156 | +! vim:ts=2:sts=2:sw=2: |
0 commit comments