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
63 CHARACTER(len=*),
PARAMETER :: filename =
'test_xmap_common_f.f90'
65 SUBROUTINE xmap_self_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
81 CALL mpi_comm_rank(mpi_comm_world, my_rank, ierror)
82 IF (ierror /= mpi_success) &
83 CALL test_abort(
"MPI error!", filename, __line__)
85 comms(1) = mpi_comm_world
86 CALL mpi_comm_dup(mpi_comm_world, comms(2), ierror)
87 IF (ierror /= mpi_success) &
88 CALL test_abort(
"MPI error!", filename, __line__)
92 CALL test_xmap1(xmap_new, comms(i))
93 CALL test_xmap2(xmap_new, comms(i))
96 CALL mpi_comm_free(comms(2), ierror)
97 IF (ierror /= mpi_success) &
98 CALL test_abort(
"MPI error!", filename, __line__)
100 IF (test_err_count() /= 0) &
101 CALL test_abort(
"non-zero error count!", filename, __line__)
104 END SUBROUTINE xmap_self_test_main
106 SUBROUTINE shift_idx(idx, offset)
107 INTEGER(xt_int_kind),
INTENT(inout) :: idx(:)
108 INTEGER(xt_int_kind),
INTENT(in) :: offset
111 idx(i) = idx(i) + int(my_rank, xi) * offset
113 END SUBROUTINE shift_idx
115 SUBROUTINE assert_xmap_is_to_self(xmap)
116 TYPE(xt_xmap) :: xmap
119 CALL test_abort(
"error in xmap construction", filename, __line__)
122 CALL test_abort(
"error in xt_xmap_get_num_sources", filename, __line__)
124 IF (rank(1) /= my_rank) &
125 CALL test_abort(
"error in xt_xmap_get_destination_ranks", &
129 IF (rank(1) /= my_rank) &
130 CALL test_abort(
"error in xt_xmap_get_source_ranks", &
133 END SUBROUTINE assert_xmap_is_to_self
135 SUBROUTINE test_xmap(src_index_list, dst_index_list, xmap_new, comm)
136 INTEGER(xt_int_kind),
INTENT(in) :: src_index_list(:), dst_index_list(:)
137 TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
139 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
140 IMPORT :: xt_idxlist, xt_xmap
142 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
143 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
144 INTEGER,
VALUE,
INTENT(in) :: comm
146 END FUNCTION xmap_new
148 INTEGER,
INTENT(inout) :: comm
150 TYPE(xt_xmap) :: xmap, xmap_copy
154 xmap = xmap_new(src_idxlist, dst_idxlist, comm)
158 CALL assert_xmap_is_to_self(xmap)
160 CALL assert_xmap_is_to_self(xmap_copy)
164 END SUBROUTINE test_xmap
166 SUBROUTINE test_xmap1(xmap_new, comm)
168 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
169 IMPORT :: xt_idxlist, xt_xmap
171 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
172 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
173 INTEGER,
VALUE,
INTENT(in) :: comm
175 END FUNCTION xmap_new
177 INTEGER,
INTENT(inout) :: comm
179 INTEGER(xt_int_kind) :: i
180 INTEGER(xt_int_kind),
PARAMETER :: num_src_idx = 7, num_dst_idx = 7
181 INTEGER(xt_int_kind) :: src_index_list(num_src_idx), &
182 dst_index_list(num_dst_idx)
183 DO i = 1_xi, num_src_idx
184 src_index_list(i) = i
186 CALL shift_idx(src_index_list, num_src_idx)
187 DO i = 1_xi, num_dst_idx
188 dst_index_list(i) = num_dst_idx - i + 1_xi
190 CALL shift_idx(dst_index_list, num_src_idx)
191 CALL test_xmap(src_index_list, dst_index_list, xmap_new, comm)
192 END SUBROUTINE test_xmap1
194 SUBROUTINE test_xmap2(xmap_new, comm)
196 FUNCTION xmap_new(src_idxlist, dst_idxlist, comm)
RESULT(res)
197 IMPORT :: xt_idxlist, xt_xmap
199 TYPE(xt_idxlist),
INTENT(in) :: src_idxlist
200 TYPE(xt_idxlist),
INTENT(in) :: dst_idxlist
201 INTEGER,
VALUE,
INTENT(in) :: comm
203 END FUNCTION xmap_new
205 INTEGER,
INTENT(inout) :: comm
207 INTEGER(xt_int_kind) :: src_index_list(14), dst_index_list(13)
209 (/ 5_xi, 67_xi, 4_xi, 5_xi, 13_xi, &
210 & 9_xi, 2_xi, 1_xi, 0_xi, 96_xi, &
211 & 13_xi, 12_xi, 1_xi, 3_xi /)
213 (/ 5_xi, 4_xi, 3_xi, 96_xi, 1_xi, &
214 & 5_xi, 4_xi, 5_xi, 4_xi, 3_xi, &
215 & 13_xi, 2_xi, 1_xi /)
216 CALL test_xmap(src_index_list, dst_index_list, xmap_new, comm)
217 END SUBROUTINE test_xmap2
219 END MODULE test_xmap_common
void xt_initialize(MPI_Comm default_comm)
void xt_idxlist_delete(Xt_idxlist idxlist)
Xt_idxlist xt_idxvec_new(const Xt_int *idxlist, int num_indices)
void xt_mpi_comm_mark_exclusive(MPI_Comm comm)
void xt_xmap_delete(Xt_xmap xmap)
int xt_xmap_get_num_destinations(Xt_xmap xmap)
Xt_xmap xt_xmap_copy(Xt_xmap xmap)
int xt_xmap_get_num_sources(Xt_xmap xmap)
void xt_xmap_get_source_ranks(Xt_xmap xmap, int *ranks)
void xt_xmap_get_destination_ranks(Xt_xmap xmap, int *ranks)