48 MODULE test_xmap_common
50 USE ftest_common
, ONLY: init_mpi, finish_mpi, test_abort
51 USE test_idxlist_utils
, ONLY: test_err_count
61 INTEGER,
PARAMETER :: xi = xt_int_kind
62 PUBLIC :: xmap_self_test_main
64 SUBROUTINE xmap_self_test_main(xmap_new)
66 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
67 IMPORT :: xt_idxlist, xt_xmap
69 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
70 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
71 INTEGER,
VALUE,
INTENT(in) :: comm
80 CALL mpi_comm_rank(mpi_comm_world, my_rank, ierror)
81 IF (ierror /= mpi_success) &
82 CALL test_abort(
"MPI error!", &
86 comms(1) = mpi_comm_world
87 CALL mpi_comm_dup(mpi_comm_world, comms(2), ierror)
88 IF (ierror /= mpi_success) &
89 CALL test_abort(
"MPI error!", &
95 CALL test_xmap1(xmap_new, comms(i))
96 CALL test_xmap2(xmap_new, comms(i))
99 CALL mpi_comm_free(comms(2), ierror)
100 IF (ierror /= mpi_success) &
101 CALL test_abort(
"MPI error!", &
105 IF (test_err_count() /= 0) &
106 CALL test_abort(
"non-zero error count!", &
111 END SUBROUTINE xmap_self_test_main
113 SUBROUTINE shift_idx(idx, offset)
114 INTEGER(xt_int_kind),
INTENT(inout) :: idx(:)
115 INTEGER(xt_int_kind),
INTENT(in) :: offset
118 idx(i) = idx(i) + int(my_rank, xi) * offset
120 END SUBROUTINE shift_idx
122 SUBROUTINE assert_xmap_is_to_self(xmap)
123 TYPE(xt_xmap) :: xmap
126 CALL test_abort(
"error in xmap construction", &
131 CALL test_abort(
"error in xt_xmap_get_num_sources", &
135 IF (rank(1) /= my_rank) &
136 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
141 IF (rank(1) /= my_rank) &
142 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
146 END SUBROUTINE assert_xmap_is_to_self
148 SUBROUTINE test_xmap(src_index_list, dst_index_list, xmap_new, comm)
149 INTEGER(xt_int_kind),
INTENT(in) :: src_index_list(:), dst_index_list(:)
150 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
152 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
153 IMPORT :: xt_idxlist, xt_xmap
155 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
156 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
157 INTEGER,
VALUE,
INTENT(in) :: comm
159 END FUNCTION xmap_new
161 INTEGER,
INTENT(inout) :: comm
163 TYPE(xt_xmap) :: xmap, xmap_copy
167 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
171 CALL assert_xmap_is_to_self(xmap)
173 CALL assert_xmap_is_to_self(xmap_copy)
177 END SUBROUTINE test_xmap
179 SUBROUTINE test_xmap1(xmap_new, comm)
181 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
182 IMPORT :: xt_idxlist, xt_xmap
184 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
185 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
186 INTEGER,
VALUE,
INTENT(in) :: comm
188 END FUNCTION xmap_new
190 INTEGER,
INTENT(inout) :: comm
192 INTEGER(xt_int_kind) :: i
193 INTEGER(xt_int_kind),
PARAMETER :: num_src_idx = 7, num_dst_idx = 7
194 INTEGER(xt_int_kind) :: src_index_list(num_src_idx), &
195 dst_index_list(num_dst_idx)
196 DO i = 1_xi, num_src_idx
197 src_index_list(i) = i
199 CALL shift_idx(src_index_list, num_src_idx)
200 DO i = 1_xi, num_dst_idx
201 dst_index_list(i) = num_dst_idx - i + 1_xi
203 CALL shift_idx(dst_index_list, num_src_idx)
204 CALL test_xmap(src_index_list, dst_index_list, xmap_new, comm)
205 END SUBROUTINE test_xmap1
207 SUBROUTINE test_xmap2(xmap_new, comm)
209 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
210 IMPORT :: xt_idxlist, xt_xmap
212 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
213 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
214 INTEGER,
VALUE,
INTENT(in) :: comm
216 END FUNCTION xmap_new
218 INTEGER,
INTENT(inout) :: comm
220 INTEGER(xt_int_kind) :: src_index_list(14), dst_index_list(13)
222 (/ 5_xi, 67_xi, 4_xi, 5_xi, 13_xi, &
223 & 9_xi, 2_xi, 1_xi, 0_xi, 96_xi, &
224 & 13_xi, 12_xi, 1_xi, 3_xi /)
226 (/ 5_xi, 4_xi, 3_xi, 96_xi, 1_xi, &
227 & 5_xi, 4_xi, 5_xi, 4_xi, 3_xi, &
228 & 13_xi, 2_xi, 1_xi /)
229 CALL test_xmap(src_index_list, dst_index_list, xmap_new, comm)
230 END SUBROUTINE test_xmap2
232 END MODULE test_xmap_common