Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_ut.f90
Go to the documentation of this file.
1 
12 
13 !
14 ! Keywords:
15 ! Maintainer: Jörg Behrens <behrens@dkrz.de>
16 ! Moritz Hanke <hanke@dkrz.de>
17 ! Thomas Jahns <jahns@dkrz.de>
18 ! URL: https://doc.redmine.dkrz.de/yaxt/html/
19 !
20 ! Redistribution and use in source and binary forms, with or without
21 ! modification, are permitted provided that the following conditions are
22 ! met:
23 !
24 ! Redistributions of source code must retain the above copyright notice,
25 ! this list of conditions and the following disclaimer.
26 !
27 ! Redistributions in binary form must reproduce the above copyright
28 ! notice, this list of conditions and the following disclaimer in the
29 ! documentation and/or other materials provided with the distribution.
30 !
31 ! Neither the name of the DKRZ GmbH nor the names of its contributors
32 ! may be used to endorse or promote products derived from this software
33 ! without specific prior written permission.
34 !
35 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
36 ! IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
37 ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 ! PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
39 ! OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40 ! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42 ! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 ! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 ! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 ! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 
49 
50 MODULE xt_ut
51  !
52  ! unitrans interface for accessing yaxt
53  !
54 
55  use, INTRINSIC :: iso_c_binding, only: c_char, c_null_char, c_int, &
56  c_long, c_short, c_long_long, c_ptr, c_loc
57 
58  ! \todo to be resolved later(dependency problem): USE yaxt, ONLY : xt_int_kind
59 
60  IMPLICIT NONE
61  PRIVATE
62 
63  PUBLIC :: ut_init, ut_init_decomposition, &
65  ut_init_transposition, ut_transpose, &
69 
70  ! \todo to be replaced by use yaxt....:
71  INTEGER, PARAMETER, PUBLIC :: xt_int_kind = xt_int_fc_kind
72 
73  !PUBLIC :: xt_int_kind
74 
75  INTEGER, PARAMETER :: inflate_inner = 1
76  INTEGER, PARAMETER :: inflate_outer = 2
77 
78  INTEGER, PUBLIC, PARAMETER :: comm_forward = 1
79  INTEGER, PUBLIC, PARAMETER :: comm_backward = 2
80 
81  INTEGER, PUBLIC, PARAMETER :: ut_mode_dt_p2p = 1
82  INTEGER, PUBLIC, PARAMETER :: ut_mode_dt_alltoall = 2
83  INTEGER, PUBLIC, PARAMETER :: ut_mode_pack_p2p = 3
84  INTEGER, PUBLIC, PARAMETER :: ut_mode_pack_alltoall = 4
85 
86  INTERFACE ut_init_decomposition
87  MODULE PROCEDURE ut_init_decomposition_1d
88  END INTERFACE ut_init_decomposition
89 
90 
91  INTERFACE ut_init_transposition
92  MODULE PROCEDURE ut_init_transposition_simple
93  MODULE PROCEDURE ut_init_transposition_with_offsets
94  END INTERFACE ut_init_transposition
95 
96  INTERFACE ut_transpose
97  MODULE PROCEDURE ut_transpose_int
98  END INTERFACE ut_transpose
99 
100  INTERFACE
101  SUBROUTINE xt_ut_abort(msg, source, line) bind(C, name='xt_ut_abort')
102  import:: c_char, c_int
103  IMPLICIT NONE
104  CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: msg
105  CHARACTER(C_CHAR), DIMENSION(*), INTENT(in) :: source
106  INTEGER(C_INT), INTENT(in) :: line
107  END SUBROUTINE xt_ut_abort
108  END INTERFACE
109 
110  INTERFACE
111  SUBROUTINE xt_ut_init(decomp_size, comm_tmpl_size, comm_size, debug_lvl, &
112  mode, idebug_unit) bind(C, name='xt_ut_init')
113  import:: c_int
114  IMPLICIT NONE
115  INTEGER(C_INT), VALUE, INTENT(in) :: decomp_size, comm_tmpl_size, &
116  comm_size, debug_lvl, mode, idebug_unit
117  END SUBROUTINE xt_ut_init
118  END INTERFACE
119 
120  INTERFACE
121  SUBROUTINE xt_ut_finalize() bind(C, name='xt_ut_finalize')
122  END SUBROUTINE xt_ut_finalize
123  END INTERFACE
124 
125  INTERFACE
126  FUNCTION xt_ut_init_decomposition_1d(idx_vec, idx_vec_n) &
127  bind(c, name='xt_ut_init_decomposition_1d') result(r)
128  import:: c_int
129  import:: xt_int_kind
130  IMPLICIT NONE
131  INTEGER(C_INT) :: r
132  INTEGER(xt_int_kind), DIMENSION(*), INTENT(in) :: idx_vec
133  INTEGER(c_int), VALUE, INTENT(in) :: idx_vec_n
134  END FUNCTION xt_ut_init_decomposition_1d
135  END INTERFACE
136 
137  INTERFACE
138  SUBROUTINE xt_ut_destroy_decomposition(handle) &
139  bind(c, name='xt_ut_destroy_decomposition')
140  import:: c_int
141  IMPLICIT NONE
142  INTEGER(C_INT), VALUE, INTENT(in) :: handle
143  END SUBROUTINE xt_ut_destroy_decomposition
144  END INTERFACE
145 
146  INTERFACE
148  decomp_handle_in, decomp_handle_out, mpi_world, check_unique) &
149  & bind(c, name='xt_ut_init_oneway_transposition_template') &
150  result(r)
151  import:: c_int
152  IMPLICIT NONE
153  INTEGER(C_INT) :: r
154  INTEGER(C_INT), VALUE, INTENT(in) :: decomp_handle_in, &
155  decomp_handle_out, mpi_world, check_unique
157  END INTERFACE
158 
159  INTERFACE
160  SUBROUTINE xt_ut_destroy_transposition_template(handle) &
161  bind(c, name='xt_ut_destroy_transposition_template')
162  import:: c_int
163  IMPLICIT NONE
164  INTEGER(C_INT), VALUE, INTENT(in) :: handle
166  END INTERFACE
167 
168  INTERFACE
169  INTEGER FUNCTION xt_ut_init_transposition_simple(itemplate, datatype) &
170  bind(c, name='xt_ut_init_transposition_simple')
171  IMPLICIT NONE
172  INTEGER, VALUE, INTENT(in) :: itemplate
173  INTEGER, VALUE, INTENT(in) :: datatype
175  END INTERFACE
176 
177  INTERFACE
178  INTEGER FUNCTION xt_ut_init_transposition(itemplate, offset_in, &
179  offset_in_size, offset_out, offset_out_size, &
180  & datatype) bind(C, name='xt_ut_init_transposition')
181  IMPLICIT NONE
182  INTEGER, VALUE, INTENT(in) :: itemplate, offset_in_size, offset_out_size
183  INTEGER, DIMENSION(*), INTENT(in) :: offset_in, offset_out
184  INTEGER, VALUE, INTENT(in) :: datatype
185  END FUNCTION xt_ut_init_transposition
186  END INTERFACE
187 
188  INTERFACE
189  SUBROUTINE xt_ut_destroy_transposition(handle) &
190  bind(c, name='xt_ut_destroy_transposition')
191  import:: c_int
192  IMPLICIT NONE
193  INTEGER(C_INT), VALUE, INTENT(in) :: handle
194  END SUBROUTINE xt_ut_destroy_transposition
195  END INTERFACE
196 
197  INTERFACE
198  SUBROUTINE xt_ut_transpose(pt_in, transposition_handle, &
199  direction, pt_out) bind(C, name='xt_ut_transpose')
200  import:: c_int, c_ptr
201  IMPLICIT NONE
202  TYPE(c_ptr), INTENT(in) :: pt_in, pt_out
203  INTEGER(C_INT), VALUE, INTENT(in) :: transposition_handle
204  INTEGER(C_INT), VALUE, INTENT(in) :: direction
205  END SUBROUTINE xt_ut_transpose
206  END INTERFACE
207 
208 
209  LOGICAL, PARAMETER :: debug = .true.
210 
211 CONTAINS
212 
213  SUBROUTINE ut_abort(msg, source, line)
214  CHARACTER(len=*), INTENT(in) :: msg
215  CHARACTER(len=*), INTENT(in) :: source
216  INTEGER, INTENT(in) :: line
217 
218  CALL xt_ut_abort(trim(msg)//c_null_char, source, line)
219 
220  END SUBROUTINE ut_abort
221 
222  SUBROUTINE ut_finalize()
224  END SUBROUTINE ut_finalize
225 
226  SUBROUTINE ut_init(decomp_size, comm_tmpl_size, comm_size, debug_lvl, &
227  mode, debug_unit)
228  INTEGER, INTENT(in) :: decomp_size
229  INTEGER, INTENT(in) :: comm_tmpl_size
230  INTEGER, INTENT(in) :: comm_size
231  INTEGER, INTENT(in) :: debug_lvl
232  INTEGER, INTENT(in) :: mode
233  INTEGER, INTENT(in) :: debug_unit
234 
235  CALL xt_ut_init(decomp_size, comm_tmpl_size, comm_size, debug_lvl, &
236  mode, debug_unit)
237 
238  END SUBROUTINE ut_init
239 
240  SUBROUTINE ut_init_decomposition_1d(myindex, global_size, handle)
241  INTEGER, INTENT(in) :: myindex(:)
242  INTEGER, INTENT(in) :: global_size
243  INTEGER, INTENT(out) :: handle
244 
245  INTEGER(c_int) :: size_myindex_c
246  IF (huge(1_xt_int_kind) < huge(myindex)) THEN
247  IF (any(myindex > huge(1_xt_int_kind)) &
248  .OR. any(myindex < -huge(1_xt_int_kind))) &
249  CALL ut_abort('ut_init_decomposition_1d: &
250  &index value not supported', &
251  __file__, &
252  __line__)
253  END IF
254  IF (huge(SIZE(myindex)) > huge(1_c_int)) THEN
255  IF (SIZE(myindex) > huge(1_c_int)) &
256  CALL ut_abort('ut_init_decomposition_1: &
257  &array size unsupported', &
258  __file__, &
259  __line__)
260  END IF
261  size_myindex_c = int(SIZE(myindex), c_int)
262  handle = xt_ut_init_decomposition_1d(idx_vec=int(myindex, xt_int_kind), &
263  idx_vec_n=size_myindex_c)
264 
265  END SUBROUTINE ut_init_decomposition_1d
266 
267  SUBROUTINE ut_destroy_decomposition(handle)
268  INTEGER, INTENT(in) :: handle
269 
270  CALL xt_ut_destroy_decomposition(handle)
271 
272  END SUBROUTINE ut_destroy_decomposition
273 
274  SUBROUTINE ut_init_oneway_transposition_template(decomp_handle_in, &
275  decomp_handle_out, mpi_world, comm_tmpl_handle, check_unique)
276  INTEGER, INTENT(in) :: decomp_handle_in
277  INTEGER, INTENT(in) :: decomp_handle_out
278  INTEGER, INTENT(in) :: mpi_world
279  INTEGER, INTENT(out) :: comm_tmpl_handle
280  LOGICAL, OPTIONAL, INTENT(in) :: check_unique
281 
282  INTEGER :: icheck_unique
283 
284  icheck_unique = 0
285  IF (PRESENT(check_unique)) THEN
286  IF (check_unique) icheck_unique = 1
287  ENDIF
288  comm_tmpl_handle = xt_ut_init_oneway_transposition_template(&
289  decomp_handle_in, decomp_handle_out, mpi_world, icheck_unique)
290 
292 
293  SUBROUTINE ut_destroy_transposition_template(handle)
294  INTEGER, INTENT(in) :: handle
295 
297 
298  END SUBROUTINE ut_destroy_transposition_template
299 
300  SUBROUTINE ut_init_transposition_simple(comm_template_handle, &
301  datatype, comm_handle)
302  INTEGER, INTENT(in) :: comm_template_handle
303  INTEGER, INTENT(in) :: datatype
304  INTEGER, INTENT(out) :: comm_handle
305 
306  comm_handle = xt_ut_init_transposition_simple(comm_template_handle, &
307  datatype)
308 
309  END SUBROUTINE ut_init_transposition_simple
310 
311  SUBROUTINE ut_init_transposition_with_offsets(comm_template_handle, &
312  offset_in, offset_out, datatype_in, datatype_out, comm_handle)
313  INTEGER, INTENT(in) :: comm_template_handle
314  INTEGER, INTENT(in) :: offset_in(:)
315  INTEGER, INTENT(in) :: offset_out(:)
316  INTEGER, INTENT(in) :: datatype_in
317  INTEGER, INTENT(in) :: datatype_out
318  INTEGER, INTENT(out) :: comm_handle
319 
320  INTEGER :: datatype
321 
322  IF (datatype_in /= datatype_out) THEN
323  CALL ut_abort('ut_init_transposition: &
324  &(datatype_in /= datatype_out) not supported', &
325  __file__, &
326  __line__)
327  ENDIF
328 
329  datatype = datatype_in
330 
331  comm_handle = xt_ut_init_transposition(comm_template_handle, &
332  & offset_in, SIZE(offset_in), &
333  & offset_out, SIZE(offset_out), &
334  & datatype)
335 
336  END SUBROUTINE ut_init_transposition_with_offsets
337 
338  SUBROUTINE ut_destroy_transposition(handle)
339  INTEGER, INTENT(in) :: handle
340 
341  CALL xt_ut_destroy_transposition(handle)
342 
343  END SUBROUTINE ut_destroy_transposition
344 
345  SUBROUTINE ut_transpose_int(field_in, transposition_handle, direction, &
346  field_out)
347  INTEGER, POINTER :: field_in, field_out
348  INTEGER, INTENT(in) :: transposition_handle
349  INTEGER, INTENT(in) :: direction
350 
351  TYPE(c_ptr) :: pt_in, pt_out
352 
353  pt_in = c_loc(field_in)
354  pt_out = c_loc(field_out)
355  CALL xt_ut_transpose(pt_in, transposition_handle, direction, pt_out)
356 
357  END SUBROUTINE ut_transpose_int
358 
359 END MODULE xt_ut
360 !
361 ! Local Variables:
362 ! f90-continuation-indent: 5
363 ! coding: utf-8
364 ! indent-tabs-mode: nil
365 ! show-trailing-whitespace: t
366 ! require-trailing-newline: t
367 ! End:
368 !
MPI_Fint xt_ut_init_oneway_transposition_template(int id_in, int id_out, int XT_UNUSED(mpi_world), int XT_UNUSED(icheck_unique))
Definition: xt_ut_c.c:203
MPI_Fint xt_ut_init_decomposition_1d(Xt_int *iv, int iv_n)
Definition: xt_ut_c.c:192
subroutine, public ut_init(decomp_size, comm_tmpl_size, comm_size, debug_lvl, mode, debug_unit)
Definition: xt_ut.f90:228
MPI_Fint xt_ut_init_transposition_simple(MPI_Fint itemplate, MPI_Fint f_datatype)
Definition: xt_ut_c.c:221
integer, parameter, public ut_mode_pack_alltoall
Definition: xt_ut.f90:84
subroutine, public ut_destroy_transposition_template(handle)
Definition: xt_ut.f90:294
void xt_ut_transpose(const void **pt_in, int itrans, int XT_UNUSED(direction), void **pt_out)
Definition: xt_ut_c.c:255
void xt_ut_abort(char *msg, char *source, int *line) __attribute__((noreturn))
Definition: xt_ut_c.c:111
void xt_ut_init(int decomp_size, int comm_tmpl_size, int comm_trans_size, int debug_lvl, int mode, int debug_unit)
Definition: xt_ut_c.c:115
subroutine, public ut_destroy_transposition(handle)
Definition: xt_ut.f90:339
MPI_Fint xt_ut_init_transposition(MPI_Fint itemplate, MPI_Fint offset_in[], MPI_Fint XT_UNUSED(offset_in_size), MPI_Fint offset_out[], MPI_Fint XT_UNUSED(offset_out_size), MPI_Fint f_datatype)
Definition: xt_ut_c.c:235
integer, parameter, public xt_int_kind
Definition: xt_core_f.f90:54
integer, parameter, public ut_mode_pack_p2p
Definition: xt_ut.f90:83
void xt_ut_finalize(void)
Definition: xt_ut_c.c:133
subroutine, public ut_destroy_decomposition(handle)
Definition: xt_ut.f90:268
integer, parameter, public ut_mode_dt_alltoall
Definition: xt_ut.f90:82
Definition: xt_ut.f90:50
subroutine, public ut_init_oneway_transposition_template(decomp_handle_in, decomp_handle_out, mpi_world, comm_tmpl_handle, check_unique)
Definition: xt_ut.f90:276
integer, parameter, public comm_forward
Definition: xt_ut.f90:78
void xt_ut_destroy_decomposition(int id)
Definition: xt_ut_c.c:148
integer, parameter, public comm_backward
Definition: xt_ut.f90:79
void xt_ut_destroy_transposition(int id)
Definition: xt_ut_c.c:184
subroutine, public ut_abort(msg, source, line)
Definition: xt_ut.f90:214
subroutine, public ut_finalize()
Definition: xt_ut.f90:223
integer, parameter, public ut_mode_dt_p2p
Definition: xt_ut.f90:81
void xt_ut_destroy_transposition_template(int id)
Definition: xt_ut_c.c:166