Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_idxlist_f.f90
Go to the documentation of this file.
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 !
50  xt_bounds, xt_get_default_comm, xt_abort, i2, i4, i8, &
51  xt_pos_ext, OPERATOR(==)
52  USE iso_c_binding, ONLY: c_ptr, c_int, c_f_pointer, c_null_ptr, &
53  c_associated, c_loc
54  IMPLICIT NONE
55  PRIVATE
56 
57  ! note: this type must not be extended to contain any other
58  ! components, its memory pattern has to match void * exactly, which
59  ! it does because of C constraints
60  TYPE, bind(c), PUBLIC :: xt_idxlist
61 #ifndef __G95__
62  PRIVATE
63 #endif
64  TYPE(c_ptr) :: cptr = c_null_ptr
65  END TYPE xt_idxlist
66 
67  INTERFACE
68 
69  ! this function must not be implemented in Fortran because
70  ! PGI 11.x chokes on that
71  FUNCTION xt_idxlist_f2c(idxlist) bind(c, name='xt_idxlist_f2c') RESULT(p)
72  IMPORT :: c_ptr, xt_idxlist
73  IMPLICIT NONE
74  TYPE(xt_idxlist), INTENT(in) :: idxlist
75  TYPE(c_ptr) :: p
76  END FUNCTION xt_idxlist_f2c
77 
78  FUNCTION xt_idxlist_get_pack_size(idxlist, comm) &
79  bind(c, name='xt_idxlist_get_pack_size_f2c') result(pack_size)
80  IMPORT :: xt_idxlist, xt_mpi_fint_kind
81  IMPLICIT NONE
82  TYPE(xt_idxlist), INTENT(in) :: idxlist
83  INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in) :: comm
84  INTEGER(xt_mpi_fint_kind) :: pack_size
85  END FUNCTION xt_idxlist_get_pack_size
86 
87  END INTERFACE
88  ! xt_idxlist_pack_f(type(xt_idxlist), intent(out) :: idxlist,
89  ! type<*>, intent(inout) :: buffer, integer,
90  ! intent(in) :: buffer_size,
91  ! integer, intent(inout) :: position, integer,
92  ! intent(in) :: comm)
93  EXTERNAL :: xt_idxlist_pack_f
94 
95  ! xt_idxlist_unpack_f(type(xt_idxlist), intent(out) :: idxlist,
96  ! type<*>, intent(in) :: buffer,
97  ! integer, intent(in) :: buffer_size,
98  ! integer, intent(inout) :: position, integer,
99  ! intent(in) :: comm)
101 
103  xt_idxlist_f2c, xt_idxlist_c2f, xt_is_null, &
112  INTERFACE
113 
114  FUNCTION xt_idxlist_get_num_indices_c(idxlist) RESULT(num_indices) &
115  bind(c, name='xt_idxlist_get_num_indices')
116  IMPORT :: c_int, c_ptr
117  IMPLICIT NONE
118  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
119  INTEGER(c_int) :: num_indices
120  END FUNCTION xt_idxlist_get_num_indices_c
121 
122  SUBROUTINE xt_idxlist_get_indices_c(idxlist, indices) &
123  bind(c, name='xt_idxlist_get_indices')
124  IMPORT :: c_ptr, xt_int_kind
125  IMPLICIT NONE
126  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
127  INTEGER(xt_int_kind), INTENT(out) :: indices(*)
128  END SUBROUTINE xt_idxlist_get_indices_c
129 
130  SUBROUTINE xt_idxlist_delete_c(idxlist) bind(C, name='xt_idxlist_delete')
131  IMPORT :: c_ptr
132  IMPLICIT NONE
133  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
134  END SUBROUTINE xt_idxlist_delete_c
135 
136  FUNCTION xt_idxlist_get_indices_at_positions_c(idxlist, positions, &
137  num_pos, indices, undef_idx) &
138  bind(c, name='xt_idxlist_get_indices_at_positions') result(num_subst)
139  IMPORT :: c_ptr, c_int, xt_int_kind
140  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
141  INTEGER(c_int), INTENT(in) :: positions(*)
142  INTEGER(c_int), VALUE, INTENT(in) :: num_pos
143  INTEGER(xt_int_kind), VALUE, INTENT(in) :: undef_idx
144  INTEGER(xt_int_kind), INTENT(out) :: indices(*)
145  INTEGER(c_int) :: num_subst
146  END FUNCTION xt_idxlist_get_indices_at_positions_c
147 
148  END INTERFACE
149 
150  INTERFACE xt_idxlist_delete
151  MODULE PROCEDURE xt_idxlist_delete_1
152  MODULE PROCEDURE xt_idxlist_delete_a1d
153  MODULE PROCEDURE xt_idxlist_delete_a2d
154  END INTERFACE xt_idxlist_delete
155 
156  INTERFACE xt_idxlist_get_indices
157  MODULE PROCEDURE xt_idxlist_get_indices_1d
158  MODULE PROCEDURE xt_idxlist_get_indices_2d
159  MODULE PROCEDURE xt_idxlist_get_indices_3d
160  MODULE PROCEDURE xt_idxlist_get_indices_4d
161  MODULE PROCEDURE xt_idxlist_get_indices_5d
162  MODULE PROCEDURE xt_idxlist_get_indices_6d
163  MODULE PROCEDURE xt_idxlist_get_indices_7d
164  END INTERFACE xt_idxlist_get_indices
165 
166  INTERFACE xt_is_null
167  MODULE PROCEDURE xt_idxlist_is_null
168  END INTERFACE xt_is_null
169 
171  MODULE PROCEDURE xt_idxlist_get_indices_at_positions_a1d
172  MODULE PROCEDURE xt_idxlist_get_indices_at_positions_a1d_i2
173  MODULE PROCEDURE xt_idxlist_get_indices_at_positions_a1d_i4
174  MODULE PROCEDURE xt_idxlist_get_indices_at_positions_a1d_i8
176 
177  INTERFACE
178  FUNCTION xt_idxlist_get_pos_exts_of_index_stripes_c(idxlist, &
179  num_stripes, stripes, num_ext, pos_ext, single_match_only) &
180  bind(c, name='xt_idxlist_get_pos_exts_of_index_stripes') &
181  result(num_unmatched)
182  IMPORT :: c_ptr, c_int
183  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
184  INTEGER(c_int), VALUE, INTENT(in) :: num_stripes
185  TYPE(c_ptr), VALUE, INTENT(in) :: stripes
186  INTEGER(c_int), INTENT(out) :: num_ext
187  TYPE(c_ptr), INTENT(out) :: pos_ext
188  INTEGER(c_int), VALUE, INTENT(in) :: single_match_only
189  INTEGER(c_int) :: num_unmatched
190  END FUNCTION xt_idxlist_get_pos_exts_of_index_stripes_c
191 
192  SUBROUTINE free_c(p) bind(c, name='free')
193  IMPORT :: c_ptr
194  TYPE(c_ptr), VALUE, INTENT(in) :: p
195  END SUBROUTINE free_c
196  END INTERFACE
197 
199  MODULE PROCEDURE gpe_is_i4_a_i4_p1d_l
200  MODULE PROCEDURE gpe_is_a_p1d_l
202 
203 CONTAINS
204 
205  FUNCTION xt_idxlist_is_null(idxlist) RESULT(p)
206  TYPE(xt_idxlist), INTENT(in) :: idxlist
207  LOGICAL :: p
208  p = .NOT. c_associated(idxlist%cptr)
209  END FUNCTION xt_idxlist_is_null
210 
211  SUBROUTINE xt_idxlist_delete_1(idxlist)
212  TYPE(xt_idxlist), INTENT(inout) :: idxlist
213  CALL xt_idxlist_delete_c(xt_idxlist_f2c(idxlist))
214  idxlist%cptr = c_null_ptr
215  END SUBROUTINE xt_idxlist_delete_1
216 
217  SUBROUTINE xt_idxlist_delete_a1d(idxlists)
218  TYPE(xt_idxlist), INTENT(inout) :: idxlists(:)
219  INTEGER :: i, n
220  n = SIZE(idxlists)
221  DO i = 1, n
222  CALL xt_idxlist_delete_c(xt_idxlist_f2c(idxlists(i)))
223  idxlists(i)%cptr = c_null_ptr
224  END DO
225  END SUBROUTINE xt_idxlist_delete_a1d
226 
227  SUBROUTINE xt_idxlist_delete_a2d(idxlists)
228  TYPE(xt_idxlist), INTENT(inout) :: idxlists(:, :)
229  INTEGER :: i, j, m, n
230  m = SIZE(idxlists, 1)
231  n = SIZE(idxlists, 2)
232  DO j = 1, n
233  DO i = 1, m
234  CALL xt_idxlist_delete_c(xt_idxlist_f2c(idxlists(i, j)))
235  idxlists(i, j)%cptr = c_null_ptr
236  END DO
237  END DO
238  END SUBROUTINE xt_idxlist_delete_a2d
239 
240  FUNCTION xt_idxlist_get_index_at_position(idxlist, position, idx) RESULT(res)
241  IMPLICIT NONE
242  TYPE(xt_idxlist), INTENT(in) :: idxlist
243  INTEGER, VALUE, INTENT(in) :: position
244  INTEGER(xt_int_kind), INTENT(out) :: idx
245  LOGICAL :: res
246  INTEGER(c_int) :: position_c
247 
248  INTERFACE
249  FUNCTION xt_idxlist_get_index_at_position_c(idxlist, position, idx) &
250  bind(c, name='xt_idxlist_get_index_at_position') result(res)
251  IMPORT :: c_ptr, c_int, xt_int_kind
252  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
253  INTEGER(c_int), VALUE, INTENT(in) :: position
254  INTEGER(xt_int_kind), INTENT(out) :: idx
255  INTEGER(c_int) :: res
256  END FUNCTION xt_idxlist_get_index_at_position_c
257  END INTERFACE
258 
259  position_c = int(position, c_int)
260  res = xt_idxlist_get_index_at_position_c(xt_idxlist_f2c(idxlist), &
261  position_c, idx) /= 0
263 
264  FUNCTION xt_idxlist_get_indices_at_positions_a1d(idxlist, positions, &
265  indices, undef_idx) RESULT(num_subst)
266  IMPLICIT NONE
267  TYPE(xt_idxlist), INTENT(in) :: idxlist
268  INTEGER, INTENT(in) :: positions(:)
269  INTEGER(xt_int_kind), INTENT(out) :: indices(:)
270  INTEGER(xt_int_kind), INTENT(in) :: undef_idx
271  INTEGER :: num_subst, n
272  INTEGER(c_int) :: num_positions_c
273 
274  n = SIZE(positions)
275  IF (n > huge(1_c_int)) n = huge(1_c_int)
276 
277  num_positions_c = int(n, c_int)
278  num_subst = xt_idxlist_get_indices_at_positions_c(xt_idxlist_f2c(idxlist), &
279  int(positions, c_int), num_positions_c, &
280  indices, undef_idx)
281  END FUNCTION xt_idxlist_get_indices_at_positions_a1d
282 
283  FUNCTION xt_idxlist_get_indices_at_positions_a1d_i2(idxlist, positions, &
284  num_pos, indices, undef_idx) RESULT(num_subst)
285  IMPLICIT NONE
286  TYPE(xt_idxlist), INTENT(in) :: idxlist
287  INTEGER, INTENT(in) :: positions(*)
288  INTEGER(xt_int_kind), INTENT(out) :: indices(*)
289  INTEGER(xt_int_kind), INTENT(in) :: undef_idx
290  INTEGER(i2), INTENT(in) :: num_pos
291  INTEGER :: num_subst
292  INTEGER(c_int) :: num_pos_c
293 
294  num_pos_c = int(num_pos, c_int)
295  num_subst = xt_idxlist_get_indices_at_positions_c(xt_idxlist_f2c(idxlist), &
296  int(positions(1:num_pos), c_int), num_pos_c, &
297  indices, undef_idx)
298  END FUNCTION xt_idxlist_get_indices_at_positions_a1d_i2
299 
300  FUNCTION xt_idxlist_get_indices_at_positions_a1d_i4(idxlist, positions, &
301  num_pos, indices, undef_idx) RESULT(num_subst)
302  IMPLICIT NONE
303  TYPE(xt_idxlist), INTENT(in) :: idxlist
304  INTEGER, INTENT(in) :: positions(*)
305  INTEGER(xt_int_kind), INTENT(out) :: indices(*)
306  INTEGER(xt_int_kind), INTENT(in) :: undef_idx
307  INTEGER(i4), INTENT(in) :: num_pos
308  INTEGER :: num_subst
309  INTEGER(c_int) :: num_pos_c
310 
311  IF (num_pos > huge(1_c_int) .OR. num_pos < 0) &
312  CALL xt_abort(xt_get_default_comm(), "invalid number of positions", &
313  __file__, &
314  __line__)
315 
316  num_pos_c = int(num_pos, c_int)
317  num_subst = xt_idxlist_get_indices_at_positions_c(xt_idxlist_f2c(idxlist), &
318  int(positions(1:num_pos), c_int), num_pos_c, indices, undef_idx)
319  END FUNCTION xt_idxlist_get_indices_at_positions_a1d_i4
320 
321  FUNCTION xt_idxlist_get_indices_at_positions_a1d_i8(idxlist, positions, &
322  num_pos, indices, undef_idx) RESULT(num_subst)
323  IMPLICIT NONE
324  TYPE(xt_idxlist), INTENT(in) :: idxlist
325  INTEGER, INTENT(in) :: positions(*)
326  INTEGER(xt_int_kind), INTENT(out) :: indices(*)
327  INTEGER(xt_int_kind), INTENT(in) :: undef_idx
328  INTEGER(i8), INTENT(in) :: num_pos
329  INTEGER :: num_subst
330  INTEGER(c_int) :: num_pos_c
331 
332  IF (num_pos > huge(1_c_int) .OR. num_pos < 0) &
333  CALL xt_abort(xt_get_default_comm(), "invalid number of positions", &
334  __file__, &
335  __line__)
336 
337  num_pos_c = int(num_pos, c_int)
338  num_subst = xt_idxlist_get_indices_at_positions_c(xt_idxlist_f2c(idxlist), &
339  int(positions(1:num_pos), c_int), num_pos_c, indices, undef_idx)
340  END FUNCTION xt_idxlist_get_indices_at_positions_a1d_i8
341 
342  FUNCTION xt_idxlist_get_position_of_index(idxlist, idx, position) &
343  result(notfound)
344  IMPLICIT NONE
345  TYPE(xt_idxlist), INTENT(in) :: idxlist
346  INTEGER(xt_int_kind), VALUE, INTENT(in) :: idx
347  INTEGER, INTENT(out) :: position
348  LOGICAL :: notfound
349  INTEGER(c_int) :: position_c
350 
351  INTERFACE
352  FUNCTION xt_idxlist_get_position_of_index_c(idxlist, idx, position) &
353  bind(c, name='xt_idxlist_get_position_of_index') result(res)
354  IMPORT :: xt_idxlist, xt_int_kind, c_int, c_ptr
355  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
356  INTEGER(xt_int_kind), VALUE, INTENT(in) :: idx
357  INTEGER(c_int), INTENT(out) :: position
358  INTEGER(c_int) :: res
359  END FUNCTION xt_idxlist_get_position_of_index_c
360  END INTERFACE
361 
362  notfound = xt_idxlist_get_position_of_index_c(xt_idxlist_f2c(idxlist), &
363  idx, position_c) /= 0
364  position = int(position_c)
366 
367  FUNCTION xt_idxlist_get_position_of_index_off(idxlist, idx, position, &
368  offset) RESULT(notfound)
369  IMPLICIT NONE
370  TYPE(xt_idxlist), INTENT(in) :: idxlist
371  INTEGER(xt_int_kind), VALUE, INTENT(in) :: idx
372  INTEGER, INTENT(out) :: position
373  INTEGER, INTENT(in) :: offset
374  LOGICAL :: notfound
375  INTEGER(c_int) :: position_c, offset_c
376 
377  INTERFACE
378  FUNCTION xt_idxlist_get_position_of_index_off_c(idxlist, idx, position, &
379  offset) bind(c, name='xt_idxlist_get_position_of_index_off') &
380  result(res)
381  IMPORT :: xt_idxlist, xt_int_kind, c_int, c_ptr
382  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
383  INTEGER(xt_int_kind), VALUE, INTENT(in) :: idx
384  INTEGER(c_int), INTENT(out) :: position
385  INTEGER(c_int), VALUE, INTENT(in) :: offset
386  INTEGER(c_int) :: res
387  END FUNCTION xt_idxlist_get_position_of_index_off_c
388  END INTERFACE
389 
390  offset_c = int(offset, c_int)
391  notfound = xt_idxlist_get_position_of_index_off_c(xt_idxlist_f2c(idxlist), &
392  idx, position_c, offset_c) /= 0
393  position = int(position_c)
395 
396  FUNCTION xt_idxlist_get_positions_of_indices(idxlist, indices, positions, &
397  single_match_only) RESULT(num_missing)
398  IMPLICIT NONE
399  TYPE(xt_idxlist), INTENT(in) :: idxlist
400  INTEGER(xt_int_kind), INTENT(in) :: indices(:)
401  INTEGER, INTENT(out) :: positions(:)
402  LOGICAL, INTENT(in) :: single_match_only
403  INTEGER :: num_missing, n, ofs
404  INTEGER(c_int) :: single_match_only_, num_pos_c
405 
406  INTERFACE
407  FUNCTION xt_idxlist_get_positions_of_indices_c(idxlist, indices, &
408  num_indices, positions, single_match_only) &
409  bind(c, name='xt_idxlist_get_positions_of_indices') &
410  result(num_missing)
411  IMPORT :: xt_idxlist, xt_int_kind, c_int, c_ptr
412  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
413  INTEGER(xt_int_kind), INTENT(in) :: indices(*)
414  INTEGER(c_int), VALUE, INTENT(in) :: num_indices
415  INTEGER(c_int), INTENT(out) :: positions(*)
416  INTEGER(c_int), VALUE, INTENT(in) :: single_match_only
417  INTEGER(c_int) :: num_missing
418  END FUNCTION xt_idxlist_get_positions_of_indices_c
419  END INTERFACE
420 
421  n = SIZE(indices)
422  IF (SIZE(positions) < n) THEN
423  CALL xt_abort(xt_get_default_comm(), "positions array too small", &
424  __file__, &
425  __line__)
426  END IF
427  num_missing = 0
428  ofs = 1
429  single_match_only_ = merge(1_c_int, 0_c_int, single_match_only)
430  DO WHILE (n > 0)
431  IF (n > huge(1_c_int)) THEN
432  num_missing = num_missing &
433  + int(xt_idxlist_get_positions_of_indices_c(&
434  xt_idxlist_f2c(idxlist), indices(ofs:), huge(1_c_int), &
435  positions(ofs:), single_match_only_))
436  ofs = ofs + huge(1_c_int)
437  n = n - huge(1_c_int)
438  ELSE
439  num_pos_c = int(n, c_int)
440  num_missing = num_missing &
441  + int(xt_idxlist_get_positions_of_indices_c(&
442  xt_idxlist_f2c(idxlist), indices(ofs:), &
443  num_pos_c, positions(ofs:), single_match_only_))
444  n = 0
445  END IF
446  END DO
448 
449  SUBROUTINE xt_idxlist_get_index_stripes(idxlist, stripes)
450  TYPE(xt_idxlist), INTENT(in) :: idxlist
451  TYPE(xt_stripe), ALLOCATABLE, INTENT(out) :: stripes(:)
452 
453  INTERFACE
454  SUBROUTINE xt_idxlist_get_index_stripes_c(idxlist, stripes,&
455  num_stripes) bind(c, name='xt_idxlist_get_index_stripes')
456  IMPORT :: c_ptr, c_int
457  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
458  TYPE(c_ptr), INTENT(out) :: stripes
459  INTEGER(c_int), INTENT(out) :: num_stripes
460  END SUBROUTINE xt_idxlist_get_index_stripes_c
461  END INTERFACE
462  TYPE(c_ptr) :: stripes_c_ptr
463  INTEGER(c_int) :: num_stripes
464  TYPE(xt_stripe), POINTER :: stripes_f_ptr(:)
465  INTEGER :: stripes_shape(1)
466  CALL xt_idxlist_get_index_stripes_c(xt_idxlist_f2c(idxlist), &
467  stripes_c_ptr, num_stripes)
468  IF (num_stripes > huge(stripes_shape)) &
469  CALL xt_abort(xt_get_default_comm(), "number of stripes too large", &
470  __file__, &
471  __line__)
472  stripes_shape(1) = int(num_stripes)
473  IF (num_stripes > 0) THEN
474  ALLOCATE(stripes(int(num_stripes)))
475  CALL c_f_pointer(stripes_c_ptr, stripes_f_ptr, stripes_shape)
476  stripes = stripes_f_ptr
477  END IF
478  CALL free_c(stripes_c_ptr)
479  END SUBROUTINE xt_idxlist_get_index_stripes
480 
481  FUNCTION xt_idxlist_get_bounding_box(idxlist, global_size, &
482  global_start_index) RESULT(bounds)
483  TYPE(xt_idxlist), INTENT(in) :: idxlist
484  INTEGER(xt_int_kind), INTENT(in) :: global_size(:)
485  INTEGER(xt_int_kind), INTENT(in) :: global_start_index
486  TYPE(xt_bounds) :: bounds(size(global_size))
487  INTEGER(c_int) :: ndim
488 
489  INTERFACE
490  SUBROUTINE xt_idxlist_get_bounding_box_c(idxlist, ndim, global_size, &
491  global_start_index, bounds) &
492  bind(c, name='xt_idxlist_get_bounding_box')
493  IMPORT :: c_int, c_ptr, xt_int_kind, xt_bounds
494  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
495  INTEGER(c_int), VALUE :: ndim
496  INTEGER(xt_int_kind), INTENT(in) :: global_size(ndim)
497  INTEGER(xt_int_kind), VALUE, INTENT(in) :: global_start_index
498  TYPE(xt_bounds), INTENT(out) :: bounds(ndim)
499  END SUBROUTINE xt_idxlist_get_bounding_box_c
500  END INTERFACE
501 
502  ndim = int(SIZE(global_size), c_int)
503  CALL xt_idxlist_get_bounding_box_c(xt_idxlist_f2c(idxlist), &
504  ndim, global_size, global_start_index, bounds)
505  END FUNCTION xt_idxlist_get_bounding_box
506 
507  FUNCTION xt_idxlist_get_intersection(idxlist_src, idxlist_dst) &
508  result(intersection)
509  TYPE(xt_idxlist), INTENT(in) :: idxlist_src, idxlist_dst
510  TYPE(xt_idxlist) :: intersection
511 
512  INTERFACE
513  FUNCTION xt_idxlist_get_intersection_c(idxlist_src, idxlist_dst) &
514  bind(c, name='xt_idxlist_get_intersection') result(intersection)
515  IMPORT :: c_ptr
516  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist_src, idxlist_dst
517  TYPE(c_ptr) :: intersection
518  END FUNCTION xt_idxlist_get_intersection_c
519  END INTERFACE
520 
521  intersection = xt_idxlist_c2f(xt_idxlist_get_intersection_c(&
522  xt_idxlist_f2c(idxlist_src), xt_idxlist_f2c(idxlist_dst)))
523  END FUNCTION xt_idxlist_get_intersection
524 
525  FUNCTION xt_idxlist_copy(idxlist) RESULT(copy)
526  TYPE(xt_idxlist), INTENT(in) :: idxlist
527  TYPE(xt_idxlist) :: copy
528 
529  INTERFACE
530  FUNCTION xt_idxlist_copy_c(idxlist) bind(c, name='xt_idxlist_copy') &
531  result(copy)
532  IMPORT :: c_ptr
533  TYPE(c_ptr), VALUE, INTENT(IN) :: idxlist
534  TYPE(c_ptr) :: copy
535  END FUNCTION xt_idxlist_copy_c
536  END INTERFACE
537 
538  copy = xt_idxlist_c2f(xt_idxlist_copy_c(xt_idxlist_f2c(idxlist)))
539 
540  END FUNCTION xt_idxlist_copy
541 
542  FUNCTION xt_idxlist_c2f(idxlist) RESULT(p)
543  TYPE(c_ptr), INTENT(in) :: idxlist
544  TYPE(xt_idxlist) :: p
545  p%cptr = idxlist
546  END FUNCTION xt_idxlist_c2f
547 
548  FUNCTION xt_idxlist_get_num_indices(idxlist) RESULT(num_indices)
549  TYPE(xt_idxlist), INTENT(in) :: idxlist
550  INTEGER :: num_indices
551  INTEGER(c_int) :: n
552  n = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
553  IF (n > huge(num_indices) .OR. n < -huge(num_indices)) &
554  CALL xt_abort(xt_get_default_comm(), "num_indices out of bounds", &
555  __file__, &
556  __line__)
557  num_indices = int(n)
558  END FUNCTION xt_idxlist_get_num_indices
559 
560  SUBROUTINE xt_idxlist_get_indices_1d(idxlist, indices)
561  TYPE(xt_idxlist), INTENT(in) :: idxlist
562  INTEGER(xt_int_kind), INTENT(out) :: indices(:)
563  INTEGER(c_int) :: num_indices
564  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
565  IF (num_indices > SIZE(indices)) THEN
566  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
567  __file__, &
568  __line__)
569  END IF
570  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
571  END SUBROUTINE xt_idxlist_get_indices_1d
572 
573  SUBROUTINE xt_idxlist_get_indices_2d(idxlist, indices)
574  TYPE(xt_idxlist), INTENT(in) :: idxlist
575  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:)
576  INTEGER(c_int) :: num_indices
577  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
578  IF (num_indices > SIZE(indices)) THEN
579  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
580  __file__, &
581  __line__)
582  END IF
583  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
584  END SUBROUTINE xt_idxlist_get_indices_2d
585 
586  SUBROUTINE xt_idxlist_get_indices_3d(idxlist, indices)
587  TYPE(xt_idxlist), INTENT(in) :: idxlist
588  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:,:)
589  INTEGER(c_int) :: num_indices
590  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
591  IF (num_indices > SIZE(indices)) THEN
592  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
593  __file__, &
594  __line__)
595  END IF
596  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
597  END SUBROUTINE xt_idxlist_get_indices_3d
598 
599  SUBROUTINE xt_idxlist_get_indices_4d(idxlist, indices)
600  TYPE(xt_idxlist), INTENT(in) :: idxlist
601  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:,:,:)
602  INTEGER(c_int) :: num_indices
603  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
604  IF (num_indices > SIZE(indices)) THEN
605  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
606  __file__, &
607  __line__)
608  END IF
609  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
610  END SUBROUTINE xt_idxlist_get_indices_4d
611 
612  SUBROUTINE xt_idxlist_get_indices_5d(idxlist, indices)
613  TYPE(xt_idxlist), INTENT(in) :: idxlist
614  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:,:,:,:)
615  INTEGER(c_int) :: num_indices
616  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
617  IF (num_indices > SIZE(indices)) THEN
618  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
619  __file__, &
620  __line__)
621  END IF
622  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
623  END SUBROUTINE xt_idxlist_get_indices_5d
624 
625  SUBROUTINE xt_idxlist_get_indices_6d(idxlist, indices)
626  TYPE(xt_idxlist), INTENT(in) :: idxlist
627  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:,:,:,:,:)
628  INTEGER(c_int) :: num_indices
629  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
630  IF (num_indices > SIZE(indices)) THEN
631  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
632  __file__, &
633  __line__)
634  END IF
635  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
636  END SUBROUTINE xt_idxlist_get_indices_6d
637 
638  SUBROUTINE xt_idxlist_get_indices_7d(idxlist, indices)
639  TYPE(xt_idxlist), INTENT(in) :: idxlist
640  INTEGER(xt_int_kind), INTENT(out) :: indices(:,:,:,:,:,:,:)
641  INTEGER(c_int) :: num_indices
642  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
643  IF (num_indices > SIZE(indices)) THEN
644  CALL xt_abort(xt_get_default_comm(), "indices array too small", &
645  __file__, &
646  __line__)
647  END IF
648  CALL xt_idxlist_get_indices_c(xt_idxlist_f2c(idxlist), indices)
649  END SUBROUTINE xt_idxlist_get_indices_7d
650 
651  FUNCTION xt_idxlist_get_indices_const(idxlist) RESULT(indices)
652  TYPE(xt_idxlist), INTENT(in) :: idxlist
653  INTEGER(xt_int_kind), POINTER :: indices(:)
654  INTEGER(c_int) :: num_indices
655  TYPE(c_ptr) :: c_indices
656  INTEGER(xt_int_kind), SAVE, TARGET :: dummy(1) = -huge(indices)
657  INTEGER :: indices_shape(1)
658  INTERFACE
659  FUNCTION xt_idxlist_get_indices_const_c(idxlist) &
660  bind(c, name='xt_idxlist_get_indices_const') result(indices)
661  IMPORT :: c_ptr
662  IMPLICIT NONE
663  TYPE(c_ptr), VALUE, INTENT(in) :: idxlist
664  TYPE(c_ptr) :: indices
665  END FUNCTION xt_idxlist_get_indices_const_c
666  END INTERFACE
667  num_indices = xt_idxlist_get_num_indices_c(xt_idxlist_f2c(idxlist))
668  IF (num_indices > 0_xt_int_kind) THEN
669  IF (num_indices > huge(indices_shape)) &
670  CALL xt_abort(xt_get_default_comm(), &
671  "too many indices for default integer kind", &
672  __file__, &
673  __line__)
674  indices_shape(1) = int(num_indices)
675  c_indices = xt_idxlist_get_indices_const_c(xt_idxlist_f2c(idxlist))
676  CALL c_f_pointer(c_indices, indices, indices_shape)
677  ELSE
678  indices => dummy(1:0)
679  END IF
680  END FUNCTION xt_idxlist_get_indices_const
681 
682  FUNCTION gpe_is_i4_a_i4_p1d_l(idxlist, &
683  num_stripes, stripes, num_ext, pos_ext, single_match_only) &
684  result(num_unmatched)
685  TYPE(xt_idxlist), INTENT(in) :: idxlist
686  INTEGER(i4), INTENT(in) :: num_stripes
687  TYPE(xt_stripe), INTENT(in), TARGET :: stripes(num_stripes)
688  INTEGER, INTENT(out) :: num_ext
689  TYPE(xt_pos_ext), ALLOCATABLE, INTENT(out) :: pos_ext(:)
690  LOGICAL, INTENT(in) :: single_match_only
691  INTEGER :: num_unmatched
692 
693  INTEGER(c_int) :: num_unmatched_c, num_ext_c, num_stripes_c
694  TYPE(c_ptr) :: pos_ext_c, stripes_c
695  TYPE(xt_pos_ext), POINTER :: pos_ext_fptr(:)
696  INTEGER :: pos_ext_shape(1)
697 
698  IF (num_stripes > huge(1_c_int) .OR. num_stripes < 0) &
699  CALL xt_abort(xt_get_default_comm(), &
700  "interface violation detected", &
701  __file__, &
702  __line__)
703 
704  stripes_c = c_loc(stripes)
705  num_stripes_c = int(num_stripes, c_int)
706  num_unmatched_c = xt_idxlist_get_pos_exts_of_index_stripes_c(&
707  xt_idxlist_f2c(idxlist), num_stripes_c, stripes_c, &
708  num_ext_c, pos_ext_c, merge(1_c_int, 0_c_int, single_match_only))
709 
710  IF (num_ext_c > huge(1) .OR. num_ext_c < 0 &
711  .OR. num_unmatched_c > huge(1) .OR. num_unmatched_c < 0) &
712  CALL xt_abort(xt_get_default_comm(), &
713  "data representation problem", &
714  __file__, &
715  __line__)
716  num_unmatched = int(num_unmatched_c)
717  num_ext = int(num_ext_c)
718  IF (num_ext > 0) THEN
719  ALLOCATE(pos_ext(num_ext))
720  pos_ext_shape(1) = num_ext
721  CALL c_f_pointer(pos_ext_c, pos_ext_fptr, pos_ext_shape)
722  pos_ext = pos_ext_fptr
723  CALL free_c(pos_ext_c)
724  END IF
725  END FUNCTION gpe_is_i4_a_i4_p1d_l
726 
727  FUNCTION gpe_is_a_p1d_l(idxlist, stripes, pos_ext, single_match_only) &
728  result(num_unmatched)
729  TYPE(xt_idxlist), INTENT(in) :: idxlist
730  TYPE(xt_stripe), INTENT(in) :: stripes(:)
731  TYPE(xt_pos_ext), ALLOCATABLE, INTENT(out) :: pos_ext(:)
732  LOGICAL, INTENT(in) :: single_match_only
733  INTEGER :: num_unmatched
734 
735  INTEGER :: num_ext
736  INTEGER(i4) :: num_stripes
737 
738  num_stripes = SIZE(stripes)
739  IF (num_stripes > 0) THEN
740  num_unmatched = gpe_is_i4_a_i4_p1d_l(idxlist, num_stripes, stripes, &
741  num_ext, pos_ext, single_match_only)
742  ELSE
743  num_unmatched = 0
744  END IF
745  END FUNCTION gpe_is_a_p1d_l
746 
747 END MODULE xt_idxlist_abstract
748 !
749 ! Local Variables:
750 ! f90-continuation-indent: 5
751 ! coding: utf-8
752 ! indent-tabs-mode: nil
753 ! show-trailing-whitespace: t
754 ! require-trailing-newline: t
755 ! End:
756 !
integer, parameter, public i8
Definition: xt_core_f.f90:60
int xt_idxlist_get_num_indices(Xt_idxlist idxlist)
Definition: xt_idxlist.c:97
integer, parameter, public i4
Definition: xt_core_f.f90:59
external, public xt_idxlist_unpack_f
type(xt_idxlist) function, public xt_idxlist_c2f(idxlist)
describes range of positions starting with start up to start + size - 1 i.e. [start,start+size) if size is positive and down to start + size + 1 i.e. (start+size,start] if size is negative
Definition: xt_core_f.f90:91
void xt_idxlist_get_indices(Xt_idxlist idxlist, Xt_int *indices)
Definition: xt_idxlist.c:101
integer, parameter, public xt_mpi_fint_kind
Definition: xt_core_f.f90:66
void xt_idxlist_delete(Xt_idxlist idxlist)
Definition: xt_idxlist.c:73
integer, parameter, public i2
Definition: xt_core_f.f90:58
external, public xt_idxlist_pack_f
int xt_idxlist_get_position_of_index_off(Xt_idxlist idxlist, Xt_int index, int *position, int offset)
Definition: xt_idxlist.c:253
void xt_idxlist_get_bounding_box(Xt_idxlist idxlist, unsigned ndim, const Xt_int global_size[ndim], Xt_int global_start_index, struct Xt_bounds bounds[ndim])
Definition: xt_idxlist.c:321
int xt_idxlist_get_positions_of_indices(Xt_idxlist idxlist, const Xt_int *indices, int num_indices, int *positions, int single_match_only)
Definition: xt_idxlist.c:192
int xt_idxlist_get_indices_at_positions(Xt_idxlist idxlist, const int *positions, int num_pos, Xt_int *indices, Xt_int undef_idx)
Definition: xt_idxlist.c:154
void xt_idxlist_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe **stripes, int *num_stripes)
Definition: xt_idxlist.c:117
int xt_idxlist_get_pos_exts_of_index_stripes(Xt_idxlist idxlist, int num_stripes, const struct Xt_stripe stripes[num_stripes], int *num_ext, struct Xt_pos_ext **pos_ext, int single_match_only)
Definition: xt_idxlist.c:226
int xt_idxlist_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int *index)
Definition: xt_idxlist.c:147
int xt_idxlist_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int *position)
Definition: xt_idxlist.c:185
integer, parameter, public xt_int_kind
Definition: xt_core_f.f90:54
Xt_idxlist xt_idxlist_copy(Xt_idxlist idxlist)
Definition: xt_idxlist.c:92
size_t xt_idxlist_get_pack_size(Xt_idxlist idxlist, MPI_Comm comm)
Definition: xt_idxlist.c:78
const Xt_int * xt_idxlist_get_indices_const(Xt_idxlist idxlist)
Definition: xt_idxlist.c:107
Xt_idxlist xt_idxlist_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst)