Yet Another eXchange Tool  DO_NOT_EDIT_HERE
test_redist_collection_displace_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 redist_collection_displace
49  USE mpi
50  USE ftest_common, ONLY: test_abort
51  USE yaxt, ONLY: xt_int_kind, xi => xt_int_kind, &
52  xt_xmap, xt_xmap_delete, &
55  xt_slice_c_loc
56  ! older PGI compilers do not handle generic interface correctly
57 #if defined __PGI && (__PGIC__ < 12 || (__PGIC__ == 12 && __PGIC_MINOR__ <= 10))
59 #endif
60  USE test_redist_common, ONLY: build_odd_selection_xmap
61  USE iso_c_binding, ONLY: c_ptr
62  IMPLICIT NONE
63  PRIVATE
64  INTEGER, PARAMETER :: cache_size = 16, cache_overrun = 2
65  INTEGER(xt_int_kind), PARAMETER :: num_slice = 3_xi, dst_step = 2_xi
66  INTEGER, PARAMETER :: src_slice_len = 5
67  INTEGER, PARAMETER :: dst_slice_len &
68  = (src_slice_len + dst_step - 1)/dst_step
69  PUBLIC :: test_displacement_variations
70 CONTAINS
71  ! test with one redist used three times (with different input
72  ! data displacements until the cache is full)
73  ! set up data
74  SUBROUTINE test_displacement_variations
75  TYPE(xt_xmap) :: xmap
76  TYPE(xt_redist) :: redist, redists(num_slice), redist_coll, &
77  redist_coll_copy
78 
79  xmap = build_odd_selection_xmap(src_slice_len)
80  redist = xt_redist_p2p_new(xmap, mpi_double_precision)
81 
82  CALL xt_xmap_delete(xmap)
83 
84  ! generate redist_collection
85  redists = redist
86 
87  redist_coll = xt_redist_collection_new(redists, int(num_slice), &
88  cache_size, mpi_comm_world)
89 
90  CALL xt_redist_delete(redist)
91 
92  CALL run_displacement_check(redist_coll)
93  redist_coll_copy = xt_redist_copy(redist_coll)
94  CALL run_displacement_check(redist_coll_copy)
95 
96  ! clean up
97  CALL xt_redist_delete(redist_coll)
98  CALL xt_redist_delete(redist_coll_copy)
99  END SUBROUTINE test_displacement_variations
100 
101  SUBROUTINE run_displacement_check(redist_coll)
102  TYPE(xt_redist), INTENT(in) :: redist_coll
103  INTEGER(xt_int_kind) :: i, j
104  INTEGER :: k
105  DOUBLE PRECISION, TARGET, SAVE :: src_data(src_slice_len, num_slice) &
106  = reshape((/ (dble(i), i = 1_xi, src_slice_len*num_slice) /), &
107  (/ int(src_slice_len), int(num_slice) /))
108  DOUBLE PRECISION, TARGET :: dst_data(dst_slice_len, num_slice)
109  DOUBLE PRECISION, TARGET :: &
110  src_data_(src_slice_len + cache_size + cache_overrun), &
111  dst_data_(dst_slice_len + cache_size + cache_overrun)
112  TYPE(c_ptr) :: src_data_p(num_slice), dst_data_p(num_slice)
113  DOUBLE PRECISION, PARAMETER :: ref_dst_data(dst_slice_len, num_slice) = &
114  reshape((/ ((dble(i + j * src_slice_len), &
115  & i = 1_xi, src_slice_len, dst_step), &
116  & j = 0_xi, num_slice - 1_xi) /), &
117  & (/ int(dst_slice_len), int(num_slice) /))
118 
119  dst_data = -1.0d0
120 
121  DO i = 1, num_slice - 1
122  CALL xt_slice_c_loc(src_data(:, i), src_data_p(i))
123  CALL xt_slice_c_loc(dst_data(:, i), dst_data_p(i))
124  END DO
125 
126  ! test exchange
127  DO k = 1, cache_size + cache_overrun
128  src_data_(k:k+src_slice_len-1) = src_data(:,num_slice)
129  dst_data_(k:k+dst_slice_len-1) = -1.0d0
130  dst_data = -1.0d0
131 
132  CALL xt_slice_c_loc(src_data_(k:k+src_slice_len-1), src_data_p(3))
133  CALL xt_slice_c_loc(dst_data_(k:k+dst_slice_len-1), dst_data_p(3))
134 
135  CALL xt_redist_s_exchange(redist_coll, int(num_slice), src_data_p, &
136  dst_data_p)
137 
138  IF (any(ref_dst_data(:, 1:num_slice-1) /= dst_data(:, 1:2)) &
139  .OR. any(ref_dst_data(:,3) /= dst_data_(k:k+dst_slice_len-1))) &
140  CALL test_abort("error in xt_redist_s_exchange", &
141  __file__, &
142  __line__)
143  END DO
144  END SUBROUTINE run_displacement_check
145 
146 END MODULE redist_collection_displace
147 !
148 ! Local Variables:
149 ! f90-continuation-indent: 5
150 ! coding: utf-8
151 ! indent-tabs-mode: nil
152 ! show-trailing-whitespace: t
153 ! require-trailing-newline: t
154 ! End:
155 !