Yet Another eXchange Tool  DO_NOT_EDIT_HERE
test_xmap_common_f.f90
1 
13 
14 !
15 ! Keywords:
16 ! Maintainer: Jörg Behrens <behrens@dkrz.de>
17 ! Moritz Hanke <hanke@dkrz.de>
18 ! Thomas Jahns <jahns@dkrz.de>
19 ! URL: https://doc.redmine.dkrz.de/yaxt/html/
20 !
21 ! Redistribution and use in source and binary forms, with or without
22 ! modification, are permitted provided that the following conditions are
23 ! met:
24 !
25 ! Redistributions of source code must retain the above copyright notice,
26 ! this list of conditions and the following disclaimer.
27 !
28 ! Redistributions in binary form must reproduce the above copyright
29 ! notice, this list of conditions and the following disclaimer in the
30 ! documentation and/or other materials provided with the distribution.
31 !
32 ! Neither the name of the DKRZ GmbH nor the names of its contributors
33 ! may be used to endorse or promote products derived from this software
34 ! without specific prior written permission.
35 !
36 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
37 ! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
38 ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39 ! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
40 ! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41 ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43 ! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44 ! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 ! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 ! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 !
48 MODULE test_xmap_common
49  USE mpi
50  USE ftest_common, ONLY: init_mpi, finish_mpi, test_abort
51  USE test_idxlist_utils, ONLY: test_err_count
52  USE yaxt, ONLY: xt_initialize, xt_finalize, xt_int_kind, &
53  xt_idxlist, xt_idxlist_delete, xt_idxvec_new, &
54  xt_xmap, xt_xmap_copy, xt_xmap_delete, &
58  IMPLICIT NONE
59  PRIVATE
60  INTEGER :: my_rank
61  INTEGER, PARAMETER :: xi = xt_int_kind
62  PUBLIC :: xmap_self_test_main
63 CONTAINS
64  SUBROUTINE xmap_self_test_main(xmap_new)
65  INTERFACE
66  FUNCTION xmap_new(src_idxlist, dst_idxlist, comm) RESULT(res)
67  IMPORT :: xt_idxlist, xt_xmap
68  IMPLICIT NONE
69  TYPE(xt_idxlist), INTENT(in) :: src_idxlist
70  TYPE(xt_idxlist), INTENT(in) :: dst_idxlist
71  INTEGER, VALUE, INTENT(in) :: comm
72  TYPE(xt_xmap) :: res
73  END FUNCTION xmap_new
74  END INTERFACE
75  INTEGER :: ierror, i
76  INTEGER :: comms(2)
77 
78  CALL init_mpi
79  CALL xt_initialize(mpi_comm_world)
80  CALL mpi_comm_rank(mpi_comm_world, my_rank, ierror)
81  IF (ierror /= mpi_success) &
82  CALL test_abort("MPI error!", &
83  __file__, &
84  __line__)
85 
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!", &
90  __file__, &
91  __line__)
92  CALL xt_mpi_comm_mark_exclusive(comms(2))
93 
94  DO i = 1, SIZE(comms)
95  CALL test_xmap1(xmap_new, comms(i))
96  CALL test_xmap2(xmap_new, comms(i))
97  END DO
98 
99  CALL mpi_comm_free(comms(2), ierror)
100  IF (ierror /= mpi_success) &
101  CALL test_abort("MPI error!", &
102  __file__, &
103  __line__)
104 
105  IF (test_err_count() /= 0) &
106  CALL test_abort("non-zero error count!", &
107  __file__, &
108  __line__)
109  CALL xt_finalize
110  CALL finish_mpi
111  END SUBROUTINE xmap_self_test_main
112 
113  SUBROUTINE shift_idx(idx, offset)
114  INTEGER(xt_int_kind), INTENT(inout) :: idx(:)
115  INTEGER(xt_int_kind), INTENT(in) :: offset
116  INTEGER :: i
117  DO i = 1, SIZE(idx)
118  idx(i) = idx(i) + int(my_rank, xi) * offset
119  END DO
120  END SUBROUTINE shift_idx
121 
122  SUBROUTINE assert_xmap_is_to_self(xmap)
123  TYPE(xt_xmap) :: xmap
124  INTEGER :: rank(1)
125  IF (xt_xmap_get_num_destinations(xmap) /= 1) &
126  CALL test_abort("error in xmap construction", &
127  __file__, &
128  __line__)
129 
130  IF (xt_xmap_get_num_sources(xmap) /= 1) &
131  CALL test_abort("error in xt_xmap_get_num_sources", &
132  __file__, &
133  __line__)
134  CALL xt_xmap_get_destination_ranks(xmap, rank)
135  IF (rank(1) /= my_rank) &
136  CALL test_abort("error in xt_xmap_get_destination_ranks", &
137  __file__, &
138  __line__)
139 
140  CALL xt_xmap_get_source_ranks(xmap, rank)
141  IF (rank(1) /= my_rank) &
142  CALL test_abort("error in xt_xmap_get_source_ranks", &
143  __file__, &
144  __line__)
145 
146  END SUBROUTINE assert_xmap_is_to_self
147 
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
151  INTERFACE
152  FUNCTION xmap_new(src_idxlist, dst_idxlist, comm) RESULT(res)
153  IMPORT :: xt_idxlist, xt_xmap
154  IMPLICIT NONE
155  TYPE(xt_idxlist), INTENT(in) :: src_idxlist
156  TYPE(xt_idxlist), INTENT(in) :: dst_idxlist
157  INTEGER, VALUE, INTENT(in) :: comm
158  TYPE(xt_xmap) :: res
159  END FUNCTION xmap_new
160  END INTERFACE
161  INTEGER, INTENT(inout) :: comm
162 
163  TYPE(xt_xmap) :: xmap, xmap_copy
164  src_idxlist = xt_idxvec_new(src_index_list)
165  dst_idxlist = xt_idxvec_new(dst_index_list)
166 
167  xmap = xmap_new(src_idxlist, dst_idxlist, comm)
168  CALL xt_idxlist_delete(src_idxlist)
169  CALL xt_idxlist_delete(dst_idxlist)
170 
171  CALL assert_xmap_is_to_self(xmap)
172  xmap_copy = xt_xmap_copy(xmap)
173  CALL assert_xmap_is_to_self(xmap_copy)
174 
175  CALL xt_xmap_delete(xmap)
176  CALL xt_xmap_delete(xmap_copy)
177  END SUBROUTINE test_xmap
178 
179  SUBROUTINE test_xmap1(xmap_new, comm)
180  INTERFACE
181  FUNCTION xmap_new(src_idxlist, dst_idxlist, comm) RESULT(res)
182  IMPORT :: xt_idxlist, xt_xmap
183  IMPLICIT NONE
184  TYPE(xt_idxlist), INTENT(in) :: src_idxlist
185  TYPE(xt_idxlist), INTENT(in) :: dst_idxlist
186  INTEGER, VALUE, INTENT(in) :: comm
187  TYPE(xt_xmap) :: res
188  END FUNCTION xmap_new
189  END INTERFACE
190  INTEGER, INTENT(inout) :: comm
191 
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
198  END DO
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
202  END DO
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
206 
207  SUBROUTINE test_xmap2(xmap_new, comm)
208  INTERFACE
209  FUNCTION xmap_new(src_idxlist, dst_idxlist, comm) RESULT(res)
210  IMPORT :: xt_idxlist, xt_xmap
211  IMPLICIT NONE
212  TYPE(xt_idxlist), INTENT(in) :: src_idxlist
213  TYPE(xt_idxlist), INTENT(in) :: dst_idxlist
214  INTEGER, VALUE, INTENT(in) :: comm
215  TYPE(xt_xmap) :: res
216  END FUNCTION xmap_new
217  END INTERFACE
218  INTEGER, INTENT(inout) :: comm
219 
220  INTEGER(xt_int_kind) :: src_index_list(14), dst_index_list(13)
221  src_index_list = &
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 /)
225  dst_index_list = &
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
231 
232 END MODULE test_xmap_common
233 !
234 ! Local Variables:
235 ! f90-continuation-indent: 5
236 ! coding: utf-8
237 ! indent-tabs-mode: nil
238 ! show-trailing-whitespace: t
239 ! require-trailing-newline: t
240 ! End:
241 !