Yet Another eXchange Tool  DO_NOT_EDIT_HERE
test_xmap_all2all_fail_f.f90
1 
12 !
13 ! Keywords:
14 ! Maintainer: Jörg Behrens <behrens@dkrz.de>
15 ! Moritz Hanke <hanke@dkrz.de>
16 ! Thomas Jahns <jahns@dkrz.de>
17 ! URL: https://doc.redmine.dkrz.de/yaxt/html/
18 !
19 ! Redistribution and use in source and binary forms, with or without
20 ! modification, are permitted provided that the following conditions are
21 ! met:
22 !
23 ! Redistributions of source code must retain the above copyright notice,
24 ! this list of conditions and the following disclaimer.
25 !
26 ! Redistributions in binary form must reproduce the above copyright
27 ! notice, this list of conditions and the following disclaimer in the
28 ! documentation and/or other materials provided with the distribution.
29 !
30 ! Neither the name of the DKRZ GmbH nor the names of its contributors
31 ! may be used to endorse or promote products derived from this software
32 ! without specific prior written permission.
33 !
34 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35 ! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36 ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37 ! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38 ! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39 ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41 ! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42 ! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 ! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 ! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 !
46 PROGRAM test_xmap_all2all_fail
47  USE mpi
48  USE ftest_common, ONLY: init_mpi, finish_mpi, test_abort
49  USE test_idxlist_utils, ONLY: test_err_count
50  USE yaxt, ONLY: xt_initialize, xt_finalize, xt_int_kind, &
51  xt_idxlist, xt_idxlist_delete, xt_idxvec_new, &
55  IMPLICIT NONE
56  INTEGER, PARAMETER :: xi = xt_int_kind
57  INTEGER :: my_rank, ierror, list_size
58  CALL init_mpi
59  CALL xt_initialize(mpi_comm_world)
60  CALL mpi_comm_rank(mpi_comm_world, my_rank, ierror)
61 
62  CALL test_xmap1(list_size)
63 
64  IF (test_err_count() /= 0) &
65  CALL test_abort("non-zero error count!", &
66  __file__, &
67  __line__)
68  CALL xt_finalize
69  CALL finish_mpi
70 CONTAINS
71  SUBROUTINE shift_idx(idx, offset)
72  INTEGER(xt_int_kind), INTENT(inout) :: idx(:)
73  INTEGER(xt_int_kind), INTENT(in) :: offset
74  INTEGER :: i
75  DO i = 1, SIZE(idx)
76  idx(i) = idx(i) + int(my_rank, xi) * offset
77  END DO
78  END SUBROUTINE shift_idx
79 
80  SUBROUTINE test_xmap(src_index_list, dst_index_list)
81  INTEGER(xt_int_kind), INTENT(in) :: src_index_list(:), dst_index_list(:)
82  TYPE(xt_idxlist) :: src_idxlist, dst_idxlist
83  TYPE(xt_xmap) :: xmap
84  INTEGER :: rank(1)
85  src_idxlist = xt_idxvec_new(src_index_list)
86  dst_idxlist = xt_idxvec_new(dst_index_list)
87 
88  xmap = xt_xmap_all2all_new(src_idxlist, dst_idxlist, mpi_comm_world)
89  CALL xt_idxlist_delete(src_idxlist)
90  CALL xt_idxlist_delete(dst_idxlist)
91 
92  IF (xt_xmap_get_num_destinations(xmap) /= 1) &
93  CALL test_abort("error in xmap construction", &
94  __file__, &
95  __line__)
96 
97  IF (xt_xmap_get_num_sources(xmap) /= 1) &
98  CALL test_abort("error in xt_xmap_get_num_sources", &
99  __file__, &
100  __line__)
101  CALL xt_xmap_get_destination_ranks(xmap, rank)
102  IF (rank(1) /= my_rank) &
103  CALL test_abort("error in xt_xmap_get_destination_ranks", &
104  __file__, &
105  __line__)
106 
107  CALL xt_xmap_get_source_ranks(xmap, rank)
108  IF (rank(1) /= my_rank) &
109  CALL test_abort("error in xt_xmap_get_source_ranks", &
110  __file__, &
111  __line__)
112  CALL xt_xmap_delete(xmap)
113  END SUBROUTINE test_xmap
114 
115  SUBROUTINE test_xmap1(num_idx)
116  INTEGER, INTENT(in) :: num_idx
117  INTEGER :: i
118  INTEGER(xt_int_kind) :: src_index_list(num_idx), &
119  dst_index_list(num_idx)
120  DO i = 1, num_idx
121  src_index_list(i) = int(i, xi)
122  END DO
123  CALL shift_idx(src_index_list, int(num_idx, xi))
124  DO i = 1, num_idx
125  dst_index_list(i) = int(num_idx - i + 2, xi)
126  END DO
127  CALL shift_idx(dst_index_list, int(num_idx, xi))
128  ! note: this should fail because dst/src indices don't match
129  CALL test_xmap(src_index_list, dst_index_list)
130  END SUBROUTINE test_xmap1
131 
132  SUBROUTINE parse_options
133  INTEGER :: i, num_cmd_args, arg_len
134  INTEGER, PARAMETER :: max_opt_arg_len = 80
135  CHARACTER(max_opt_arg_len) :: optarg
136  num_cmd_args = command_argument_count()
137  i = 1
138  DO WHILE (i < num_cmd_args)
139  CALL get_command_argument(i, optarg, arg_len)
140  IF (optarg(1:2) == '-s' .AND. i < num_cmd_args .AND. arg_len == 2) THEN
141  CALL get_command_argument(i + 1, optarg, arg_len)
142  IF (arg_len > max_opt_arg_len) &
143  CALL test_abort('incorrect argument to command-line option -m', &
144  __file__, &
145  __line__)
146  IF (optarg(1:arg_len) == "big") THEN
147  list_size = 1023
148  ELSE IF (optarg(1:arg_len) == "small") THEN
149  list_size = 7
150  ELSE
151  WRITE (0, *) 'arg to -s: ', optarg(1:arg_len)
152  CALL test_abort('incorrect argument to command-line option -m', &
153  __file__, &
154  __line__)
155  END IF
156  i = i + 2
157  ELSE
158  WRITE (0, *) 'unexpected command-line argument parsing error: ', &
159  trim(optarg)
160  FLUSH(0)
161  CALL test_abort('unexpected command-line argument', &
162  __file__, &
163  __line__)
164  END IF
165  END DO
166  END SUBROUTINE parse_options
167 
168 END PROGRAM test_xmap_all2all_fail
169 !
170 ! Local Variables:
171 ! f90-continuation-indent: 5
172 ! coding: utf-8
173 ! indent-tabs-mode: nil
174 ! show-trailing-whitespace: t
175 ! require-trailing-newline: t
176 ! End:
177 !