46 PROGRAM test_redist_p2p_parallel
47 USE ftest_common
, ONLY: init_mpi, finish_mpi, test_abort
48 USE iso_c_binding
, ONLY: c_loc
51 xt_int_kind, xi => xt_int_kind, &
57 USE test_idxlist_utils
, ONLY: test_err_count
58 USE test_redist_common
, ONLY: communicators_are_congruent, &
61 #if defined __PGI && __PGIC__ == 15 67 INTEGER :: comm_rank, comm_size, ierror
72 CALL mpi_comm_rank(mpi_comm_world, comm_rank, ierror)
73 IF (ierror /= mpi_success) &
74 CALL test_abort(
"MPI error!", &
78 CALL mpi_comm_size(mpi_comm_world, comm_size, ierror)
79 IF (ierror /= mpi_success) &
80 CALL test_abort(
"MPI error!", &
86 CALL block_redist_test
88 IF (test_err_count() /= 0) &
89 CALL test_abort(
"non-zero error count!", &
97 SUBROUTINE simple_test
98 INTEGER,
PARAMETER :: data_size = 10
99 INTEGER,
PARAMETER :: src_num_indices = data_size, &
100 dst_num_indices = data_size
101 INTEGER(xt_int_kind) :: src_index_list(data_size), &
102 dst_index_list(data_size)
103 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
104 TYPE(xt_xmap) :: xmap
105 TYPE(xt_redist) :: redist
106 DOUBLE PRECISION :: src_data(data_size), dst_data(data_size)
110 DO i = 1, src_num_indices
111 src_index_list(i) = int(comm_rank * data_size + (i - 1), xi)
116 DO i = 1, dst_num_indices
118 = int(mod(comm_rank * data_size + i + 1, comm_size * data_size), xi)
127 IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
129 CALL test_abort(
"error in xt_redist_get_mpi_comm", &
136 DO i = 1, src_num_indices
137 src_data(i) = dble(comm_rank * data_size + i - 1)
140 CALL check_redist(redist, src_data, dst_data, dst_index_list)
147 END SUBROUTINE simple_test
150 SUBROUTINE nonuniform_test
152 INTEGER(xt_int_kind),
ALLOCATABLE :: src_index_list(:), dst_index_list(:)
153 DOUBLE PRECISION,
ALLOCATABLE,
TARGET :: src_data(:), dst_data(:)
154 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
155 TYPE(xt_xmap) :: xmap
156 TYPE(xt_redist) :: redist
157 INTEGER :: i, src_num_indices, dst_num_indices
159 ALLOCATE(src_index_list(comm_size), dst_index_list(comm_size), &
160 src_data(comm_size), dst_data(comm_size))
161 src_num_indices = merge(comm_size, 0, comm_rank == 0)
162 DO i = 1, src_num_indices
163 src_index_list(i) = int(i - 1, xi)
169 dst_num_indices = comm_size
170 DO i = 1, dst_num_indices
171 dst_index_list(i) = int(i - 1, xi)
183 IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
185 CALL test_abort(
"error in xt_redist_get_mpi_comm", &
190 IF (comm_rank == 0)
THEN 192 src_data(i) = dble(i - 1)
202 IF (dst_data(i) /= dble(i - 1))
EXIT 204 IF (i <= comm_size) &
205 CALL test_abort(
"error in xt_redist_s_exchange", &
214 END SUBROUTINE nonuniform_test
217 SUBROUTINE block_redist_test
219 INTEGER :: ngdom, gvol_size, i, nwin, ig0, ig, j, p, qa, qb, &
220 a_vol_size, b_vol_size
222 INTEGER,
ALLOCATABLE :: gdoma(:), gdomb(:), gsurfdata(:), &
223 gdepth(:), ig2col_off(:), b_surfdata_ref(:), gvoldata(:), &
224 src_block_offsets(:), src_block_sizes(:), dst_block_offsets(:), &
225 dst_block_sizes(:), b_voldata_ref(:)
226 INTEGER,
ALLOCATABLE :: a_surfdata(:), b_surfdata(:), &
227 a_voldata(:), b_voldata(:)
228 INTEGER(xi),
ALLOCATABLE :: iveca(:), ivecb(:)
229 INTEGER(xi) :: ia, ib
230 TYPE(xt_idxlist) :: idxlist_a, idxlist_b
231 TYPE(xt_xmap) :: xmap
232 TYPE(xt_redist) :: redist, block_redist, block_redist2
234 IF (2 * comm_size > huge(1_xt_int_kind)) &
235 CALL test_abort(
'too large number of tasks', &
239 ngdom = 2 * comm_size
241 ALLOCATE(gdoma(ngdom), gdomb(ngdom))
243 ALLOCATE(gsurfdata(ngdom), gdepth(ngdom))
244 ALLOCATE(ig2col_off(ngdom))
249 gsurfdata(i) = 99 + i
251 ig2col_off(i) = gvol_size
252 gvol_size = gvol_size + gdepth(i)
255 nwin = ngdom / comm_size
257 ig0 = comm_rank * nwin
258 IF (nwin * comm_size /= ngdom) &
259 CALL test_abort(
"internal error", &
264 ALLOCATE(iveca(nwin), ivecb(nwin))
267 iveca(i) = int(gdoma(ig), xi)
268 ivecb(i) = int(gdomb(ig), xi)
280 IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
282 CALL test_abort(
"error in xt_redist_get_mpi_comm", &
286 ALLOCATE(a_surfdata(nwin), b_surfdata(nwin), b_surfdata_ref(nwin))
288 a_surfdata(i) = gsurfdata(iveca(i) + 1)
290 b_surfdata_ref(i) = gsurfdata(ivecb(i) + 1)
293 CALL check_redist(redist, a_surfdata, b_surfdata, b_surfdata_ref)
297 ALLOCATE(gvoldata(gvol_size))
300 p = ig2col_off(i) + j
301 gvoldata(p) = (i - 1) * 100 + j - 1
306 ALLOCATE(src_block_offsets(nwin), src_block_sizes(nwin), &
307 dst_block_offsets(nwin), dst_block_sizes(nwin))
311 ALLOCATE(a_voldata(gvol_size), b_voldata(gvol_size), &
312 b_voldata_ref(gvol_size))
314 b_voldata_ref(:) = -1
320 src_block_offsets(i) = src_block_offsets(i - 1) + src_block_sizes(i - 1)
322 src_block_offsets(i) = 0
324 src_block_sizes(i) = gdepth(int(ia) + 1)
325 DO j = 1, gdepth(int(ia) + 1)
326 p = ig2col_off(int(ia) + 1) + j
327 a_voldata(qa) = gvoldata(p)
330 a_vol_size = a_vol_size + src_block_sizes(i)
337 dst_block_offsets(i) = dst_block_offsets(i - 1) + dst_block_sizes(i - 1)
339 dst_block_offsets(i) = 0
341 dst_block_sizes(i) = gdepth(int(ib) + 1)
342 DO j = 1, gdepth(int(ib) + 1)
343 p = ig2col_off(int(ib) + 1) + j
344 b_voldata_ref(qb) = gvoldata(p)
347 b_vol_size = b_vol_size + dst_block_sizes(i)
353 src_block_offsets, src_block_sizes, nwin, &
354 dst_block_offsets, dst_block_sizes, nwin, mpi_integer)
356 IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(block_redist), &
358 CALL test_abort(
"error in xt_redist_get_mpi_comm", &
362 CALL check_redist(block_redist, a_voldata, b_voldata, b_voldata_ref)
366 src_block_sizes, nwin, dst_block_sizes, nwin, mpi_integer)
369 IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(block_redist2), &
371 CALL test_abort(
"error in xt_redist_get_mpi_comm", &
375 CALL check_redist(block_redist2, a_voldata, b_voldata, b_voldata_ref)
383 END SUBROUTINE block_redist_test
385 END PROGRAM test_redist_p2p_parallel