46 MODULE test_xmap_common_parallel
48 USE ftest_common
, ONLY: init_mpi, finish_mpi, test_abort
49 USE test_idxlist_utils
, ONLY: test_err_count
59 PUBLIC :: xmap_parallel_test_main
60 PUBLIC :: get_rank_range
61 PUBLIC :: check_allgather_analog_xmap
62 PUBLIC :: test_ring_1d
63 PUBLIC :: test_ping_pong
65 SUBROUTINE xmap_parallel_test_main(xmap_new)
67 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
68 IMPORT :: xt_idxlist, xt_xmap
70 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
71 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
72 INTEGER,
VALUE,
INTENT(in) :: comm
76 INTEGER :: comm, comm_rank, comm_size
81 CALL mpi_comm_rank(comm, comm_rank, ierror)
82 IF (ierror /= mpi_success) &
83 CALL test_abort(
"error calling mpi_comm_rank", &
86 CALL mpi_comm_size(comm, comm_size, ierror)
87 IF (ierror /= mpi_success) &
88 CALL test_abort(
"error calling mpi_comm_size", &
91 IF (comm_size > huge(1_xi)) &
92 CALL test_abort(
"number of ranks exceeds test limit", &
96 CALL test_allgather_analog(xmap_new, 1_xi, comm)
98 CALL test_allgather_analog(xmap_new, 1024_xi, comm)
99 IF (comm_size > 2)
CALL test_ring_1d(xmap_new, comm)
100 IF (comm_size == 2)
CALL test_pair(xmap_new, comm)
101 IF (comm_size > 1)
CALL test_ping_pong(xmap_new, comm, 0, comm_size - 1)
103 IF (test_err_count() /= 0) &
104 CALL test_abort(
"non-zero error count!", &
109 END SUBROUTINE xmap_parallel_test_main
111 SUBROUTINE get_rank_range(comm, is_inter, comm_rank, comm_size)
112 INTEGER,
INTENT(inout) :: comm
113 INTEGER,
INTENT(out) :: comm_rank, comm_size
114 LOGICAL,
INTENT(out) :: is_inter
117 CALL mpi_comm_rank(comm, comm_rank, ierror)
118 IF (ierror /= mpi_success) &
119 CALL test_abort(
"error calling mpi_comm_rank", &
122 CALL mpi_comm_test_inter(comm, is_inter, ierror)
123 IF (ierror /= mpi_success) &
124 CALL test_abort(
"error calling mpi_comm_test_inter", &
128 CALL mpi_comm_remote_size(comm, comm_size, ierror)
130 CALL mpi_comm_size(comm, comm_size, ierror)
132 IF (ierror /= mpi_success) &
133 CALL test_abort(
"error calling mpi_comm_(remote)_size", &
136 END SUBROUTINE get_rank_range
138 SUBROUTINE check_allgather_analog_xmap(xmap, comm)
139 TYPE(xt_xmap),
INTENT(in) :: xmap
140 INTEGER,
INTENT(inout) :: comm
141 INTEGER,
ALLOCATABLE :: ranks(:)
142 INTEGER(xt_int_kind) :: i
143 INTEGER :: comm_rank, comm_size
146 CALL get_rank_range(comm, is_inter, comm_rank, comm_size)
148 CALL test_abort(
"error in xmap construction", &
153 CALL test_abort(
"error in xt_xmap_get_num_sources", &
157 ALLOCATE(ranks(comm_size))
160 IF (any(ranks /= (/ (i, i=0_xi,int(comm_size-1, xi)) /))) &
161 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
166 IF (any(ranks /= (/ (i, i=0_xi,int(comm_size-1, xi)) /))) &
167 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
171 END SUBROUTINE check_allgather_analog_xmap
173 SUBROUTINE test_allgather_analog(xmap_new, num_indices_per_rank, comm)
175 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
176 IMPORT :: xt_idxlist, xt_xmap
178 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
179 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
180 INTEGER,
VALUE,
INTENT(in) :: comm
182 END FUNCTION xmap_new
184 INTEGER,
INTENT(inout) :: comm
185 INTEGER(xt_int_kind),
INTENT(in) :: num_indices_per_rank
186 INTEGER(xt_int_kind),
ALLOCATABLE :: src_index_list(:)
187 INTEGER(xt_int_kind) :: i
188 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
189 TYPE(xt_xmap) :: xmap, xmap_copy
191 INTEGER :: comm_size, comm_rank
194 CALL get_rank_range(comm, is_inter, comm_rank, comm_size)
196 ALLOCATE(src_index_list(num_indices_per_rank))
197 DO i = 1_xi, num_indices_per_rank
198 src_index_list(i) = int(comm_rank, xi) * num_indices_per_rank + i - 1_xi
201 dst_index_stripe(1) =
xt_stripe(0, 1, comm_size * int(num_indices_per_rank))
203 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
208 CALL check_allgather_analog_xmap(xmap, comm)
210 CALL check_allgather_analog_xmap(xmap, comm)
215 END SUBROUTINE test_allgather_analog
217 SUBROUTINE check_ring_xmap(xmap, dst_index_list, is_inter)
218 TYPE(xt_xmap),
INTENT(in) :: xmap
219 INTEGER(xt_int_kind),
INTENT(in) :: dst_index_list(2)
220 LOGICAL,
INTENT(in) :: is_inter
221 INTEGER :: ranks(2), num_dst, num_src
223 IF (.NOT. is_inter .AND. (num_dst > 2 .OR. num_dst < 1)) &
224 CALL test_abort(
"error in xt_xmap_get_num_destinations", &
229 IF (num_src > 2 .OR. num_src < 1) &
230 CALL test_abort(
"error in xt_xmap_get_num_sources", &
234 IF (.NOT. is_inter)
THEN 237 IF (any(ranks /= dst_index_list)) &
238 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
245 IF (any(ranks /= dst_index_list)) &
246 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
249 END SUBROUTINE check_ring_xmap
251 SUBROUTINE test_ring_1d(xmap_new, comm)
253 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
254 IMPORT :: xt_idxlist, xt_xmap
256 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
257 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
258 INTEGER,
VALUE,
INTENT(in) :: comm
260 END FUNCTION xmap_new
262 INTEGER,
INTENT(inout) :: comm
264 INTEGER(xt_int_kind) :: src_index_list(1), dst_index_list(2), temp
265 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
266 TYPE(xt_xmap) :: xmap, xmap_copy
267 INTEGER :: comm_size, comm_rank
270 CALL get_rank_range(comm, is_inter, comm_rank, comm_size)
271 src_index_list(1) = int(comm_rank, xi)
275 dst_index_list(1) = int(mod(comm_rank + comm_size - 1, comm_size), xi)
276 dst_index_list(2) = int(mod(comm_rank + 1, comm_size), xi)
277 IF (dst_index_list(1) > dst_index_list(2))
THEN 278 temp = dst_index_list(1)
279 dst_index_list(1) = dst_index_list(2)
280 dst_index_list(2) = temp
285 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
290 CALL check_ring_xmap(xmap, dst_index_list, is_inter)
292 CALL check_ring_xmap(xmap_copy, dst_index_list, is_inter)
298 END SUBROUTINE test_ring_1d
300 SUBROUTINE check_pair_xmap(xmap)
301 TYPE(xt_xmap),
INTENT(in) :: xmap
305 CALL test_abort(
"error in xt_xmap_get_num_destinations", &
310 CALL test_abort(
"error in xt_xmap_get_num_sources", &
315 IF (ranks(1) /= 0 .OR. ranks(2) /= 1) &
316 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
321 IF (ranks(1) /= 0 .OR. ranks(2) /= 1) &
322 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
325 END SUBROUTINE check_pair_xmap
327 SUBROUTINE test_pair(xmap_new, comm)
329 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
330 IMPORT :: xt_idxlist, xt_xmap
332 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
333 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
334 INTEGER,
VALUE,
INTENT(in) :: comm
336 END FUNCTION xmap_new
338 INTEGER,
INTENT(in) :: comm
340 INTEGER(xt_int_kind) :: i, j, k
342 INTEGER(xt_int_kind),
PARAMETER :: src_index_list(20, 0:1) = reshape((/ &
343 & 1_xi, 2_xi, 3_xi, 4_xi, 5_xi, &
344 & 9_xi, 10_xi, 11_xi, 12_xi, 13_xi, &
345 & 17_xi, 18_xi, 19_xi, 20_xi, 21_xi, &
346 & 25_xi, 26_xi, 27_xi, 28_xi, 29_xi, &
347 & 4_xi, 5_xi, 6_xi, 7_xi, 8_xi, &
348 & 12_xi, 13_xi, 14_xi, 15_xi, 16_xi, &
349 & 20_xi, 21_xi, 22_xi, 23_xi, 24_xi, &
350 & 28_xi, 29_xi, 30_xi, 31_xi, 32_xi /), &
353 INTEGER(xt_int_kind),
PARAMETER :: src_index_list(20, 0:1) = reshape((/ &
354 (((i + j * 8_xi + k * 3_xi, i = 1_xi, 5_xi), j = 0_xi,3_xi), &
355 k = 0_xi,1_xi) /), (/ 20, 2 /))
358 INTEGER(xt_int_kind),
PARAMETER :: dst_index_list(20, 0:1) = reshape((/ &
359 10_xi, 15_xi, 14_xi, 13_xi, 12_xi, &
360 15_xi, 10_xi, 11_xi, 12_xi, 13_xi, &
361 23_xi, 18_xi, 19_xi, 20_xi, 21_xi, &
362 31_xi, 26_xi, 27_xi, 28_xi, 29_xi, &
363 13_xi, 12_xi, 11_xi, 10_xi, 15_xi, &
364 12_xi, 13_xi, 14_xi, 15_xi, 10_xi, &
365 20_xi, 21_xi, 22_xi, 23_xi, 18_xi, &
366 28_xi, 29_xi, 30_xi, 31_xi, 26_xi /), &
368 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
369 TYPE(xt_xmap) :: xmap, xmap_copy
370 INTEGER :: comm_rank, ierror
372 CALL mpi_comm_rank(comm, comm_rank, ierror)
373 IF (ierror /= mpi_success) &
374 CALL test_abort(
"error calling mpi_comm_rank", &
384 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
388 CALL check_pair_xmap(xmap)
390 CALL check_pair_xmap(xmap_copy)
395 END SUBROUTINE test_pair
397 SUBROUTINE check_ping_pong_xmap(xmap, comm, ping_rank, pong_rank)
398 TYPE(xt_xmap),
INTENT(in) :: xmap
399 INTEGER,
INTENT(in) :: comm, ping_rank, pong_rank
400 INTEGER :: expect, dst_rank(1), src_rank(1), comm_rank, ierror
401 CHARACTER(len=80) :: msg
403 CALL mpi_comm_rank(comm, comm_rank, ierror)
404 IF (ierror /= mpi_success) &
405 CALL test_abort(
'error calling mpi_comm_rank', &
408 WRITE (msg,
'(a,i0,a)')
"error in xt_xmap_get_num_destinations (rank == ", &
410 expect = merge(1, 0, comm_rank == ping_rank)
412 CALL test_abort(trim(msg), &
416 expect = merge(1, 0, comm_rank == pong_rank)
418 CALL test_abort(msg, &
422 IF (comm_rank == ping_rank)
THEN 424 IF (dst_rank(1) /= pong_rank) &
425 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
429 IF (comm_rank == pong_rank)
THEN 431 IF (src_rank(1) /= ping_rank) &
432 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
436 END SUBROUTINE check_ping_pong_xmap
438 SUBROUTINE test_ping_pong(xmap_new, comm, ping_rank, pong_rank)
440 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
441 IMPORT :: xt_idxlist, xt_xmap
443 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
444 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
445 INTEGER,
VALUE,
INTENT(in) :: comm
447 END FUNCTION xmap_new
449 INTEGER,
INTENT(in) :: ping_rank, pong_rank
450 INTEGER,
INTENT(inout) :: comm
451 INTEGER(xt_int_kind),
PARAMETER :: &
452 index_list(5) = (/ 0_xi, 1_xi, 2_xi, 3_xi, 4_xi /)
453 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
454 TYPE(xt_xmap) :: xmap, xmap_copy
455 INTEGER :: comm_rank, comm_size
457 CALL get_rank_range(comm, is_inter, comm_rank, comm_size)
458 IF (comm_rank == ping_rank)
THEN 465 IF (comm_rank == pong_rank)
THEN 473 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
478 CALL check_ping_pong_xmap(xmap, comm, ping_rank, pong_rank)
480 CALL check_ping_pong_xmap(xmap_copy, comm, ping_rank, pong_rank)
484 END SUBROUTINE test_ping_pong
485 END MODULE test_xmap_common_parallel