Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_xmap_intersection_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 !
48 
51 
53  USE iso_c_binding, ONLY: c_int, c_loc, c_null_ptr, c_ptr
54  USE xt_core, ONLY: xt_abort, xt_mpi_fint_kind, xt_slice_c_loc
57  IMPLICIT NONE
58  PRIVATE
59 
60  TYPE, bind(c), PUBLIC :: xt_com_list
61  TYPE(xt_idxlist) :: list
62  INTEGER(c_int) :: rank
63  END TYPE xt_com_list
64 
66 
67  INTERFACE
68  FUNCTION xmi_new_f2c(num_src_intersections, src_com, &
69  num_dst_intersections, dst_com, &
70  src_idxlist, dst_idxlist, comm) RESULT(xmap) &
71  bind(c, name='xt_xmap_intersection_new_f2c')
72  IMPORT :: c_int, c_ptr, xt_mpi_fint_kind
73  INTEGER(c_int), VALUE, INTENT(in) :: num_src_intersections, &
74  num_dst_intersections
75  TYPE(c_ptr), VALUE, INTENT(in) :: src_com, dst_com, src_idxlist, &
76  dst_idxlist
77  INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in) :: comm
78  TYPE(c_ptr) :: xmap
79  END FUNCTION xmi_new_f2c
80 
81  FUNCTION xmi_ext_new_f2c(num_src_intersections, src_com, &
82  num_dst_intersections, dst_com, &
83  src_idxlist, dst_idxlist, comm) RESULT(xmap) &
84  bind(c, name='xt_xmap_intersection_ext_new_f2c')
85  IMPORT :: c_int, c_ptr, xt_mpi_fint_kind
86  INTEGER(c_int), VALUE, INTENT(in) :: num_src_intersections, &
87  num_dst_intersections
88  TYPE(c_ptr), VALUE, INTENT(in) :: src_com, dst_com, src_idxlist, &
89  dst_idxlist
90  INTEGER(xt_mpi_fint_kind), VALUE, INTENT(in) :: comm
91  TYPE(c_ptr) :: xmap
92  END FUNCTION xmi_ext_new_f2c
93  END INTERFACE
94 
95  INTERFACE xt_xmap_intersection_new
96  MODULE PROCEDURE xmi_new_i_a_i_a
97  MODULE PROCEDURE xmi_new_a_a
98  END INTERFACE xt_xmap_intersection_new
99 
101  MODULE PROCEDURE xmi_ext_new_i_a_i_a
102  MODULE PROCEDURE xmi_ext_new_a_a
103  END INTERFACE xt_xmap_intersection_ext_new
104 
105 CONTAINS
106  FUNCTION xmi_new_i_a_i_a(num_src_intersections, src_com, &
107  num_dst_intersections, dst_com, &
108  src_idxlist, dst_idxlist, comm) RESULT(xmap)
109  INTEGER(c_int), VALUE, INTENT(in) :: num_src_intersections, &
110  num_dst_intersections
111  TYPE(xt_com_list), TARGET, INTENT(in) :: src_com(num_src_intersections), &
112  dst_com(num_dst_intersections)
113  TYPE(xt_idxlist), INTENT(in) :: src_idxlist, dst_idxlist
114  INTEGER, INTENT(in) :: comm
115  TYPE(xt_xmap) :: xmap
116  TYPE(c_ptr) :: src_com_p, dst_com_p
117 
118  src_com_p = c_loc(src_com)
119  dst_com_p = c_loc(dst_com)
120  xmap = xt_xmap_c2f(xmi_new_f2c(&
121  num_src_intersections, src_com_p, &
122  num_dst_intersections, dst_com_p, &
123  xt_idxlist_f2c(src_idxlist), xt_idxlist_f2c(dst_idxlist), comm))
124  END FUNCTION xmi_new_i_a_i_a
125 
126  FUNCTION xmi_new_a_a(src_com, dst_com, src_idxlist, dst_idxlist, comm) &
127  result(xmap)
128  TYPE(xt_com_list), TARGET, INTENT(in) :: src_com(:), dst_com(:)
129  TYPE(xt_idxlist), INTENT(in) :: src_idxlist, dst_idxlist
130  INTEGER, INTENT(in) :: comm
131  TYPE(xt_xmap) :: xmap
132 
133  TYPE(xt_com_list), ALLOCATABLE, TARGET :: src_com_a(:), dst_com_a(:)
134  TYPE(c_ptr) :: src_com_p, dst_com_p
135  INTEGER(c_int) :: num_src_intersections_c, num_dst_intersections_c
136  num_src_intersections_c = int(SIZE(src_com), c_int)
137  num_dst_intersections_c = int(SIZE(dst_com), c_int)
138  CALL com_p_arg(src_com, src_com_a, src_com_p)
139  CALL com_p_arg(dst_com, dst_com_a, dst_com_p)
140 
141  xmap = xt_xmap_c2f(xmi_new_f2c(num_src_intersections_c, src_com_p, &
142  num_dst_intersections_c, dst_com_p, &
143  xt_idxlist_f2c(src_idxlist), xt_idxlist_f2c(dst_idxlist), comm))
144  END FUNCTION xmi_new_a_a
145 
146  FUNCTION xmi_ext_new_i_a_i_a(num_src_intersections, src_com, &
147  num_dst_intersections, dst_com, &
148  src_idxlist, dst_idxlist, comm) RESULT(xmap)
149  INTEGER(c_int), VALUE, INTENT(in) :: num_src_intersections, &
150  num_dst_intersections
151  TYPE(xt_com_list), TARGET, INTENT(in) :: src_com(num_src_intersections), &
152  dst_com(num_dst_intersections)
153  TYPE(xt_idxlist), INTENT(in) :: src_idxlist, dst_idxlist
154  INTEGER, INTENT(in) :: comm
155  TYPE(xt_xmap) :: xmap
156  INTEGER(c_int) :: num_src_intersections_c, num_dst_intersections_c
157  num_src_intersections_c = int(num_src_intersections, c_int)
158  num_dst_intersections_c = int(num_dst_intersections, c_int)
159 
160  xmap = xt_xmap_c2f(xmi_ext_new_f2c(&
161  num_src_intersections_c, c_loc(src_com), &
162  num_dst_intersections_c, c_loc(dst_com), &
163  xt_idxlist_f2c(src_idxlist), xt_idxlist_f2c(dst_idxlist), comm))
164  END FUNCTION xmi_ext_new_i_a_i_a
165 
166  FUNCTION xmi_ext_new_a_a(src_com, dst_com, src_idxlist, dst_idxlist, comm) &
167  result(xmap)
168  TYPE(xt_com_list), TARGET, INTENT(in) :: src_com(:), dst_com(:)
169  TYPE(xt_idxlist), INTENT(in) :: src_idxlist, dst_idxlist
170  INTEGER, INTENT(in) :: comm
171  TYPE(xt_xmap) :: xmap
172 
173  TYPE(xt_com_list), ALLOCATABLE, TARGET :: src_com_a(:), dst_com_a(:)
174  TYPE(c_ptr) :: src_com_p, dst_com_p
175  INTEGER(c_int) :: num_src_intersections_c, num_dst_intersections_c
176  num_src_intersections_c = int(SIZE(src_com), c_int)
177  num_dst_intersections_c = int(SIZE(dst_com), c_int)
178 
179  CALL com_p_arg(src_com, src_com_a, src_com_p)
180  CALL com_p_arg(dst_com, dst_com_a, dst_com_p)
181 
182  xmap = xt_xmap_c2f(xmi_ext_new_f2c(num_src_intersections_c, src_com_p, &
183  num_dst_intersections_c, dst_com_p, &
184  xt_idxlist_f2c(src_idxlist), xt_idxlist_f2c(dst_idxlist), comm))
185  END FUNCTION xmi_ext_new_a_a
186 
187  SUBROUTINE com_p_arg(com, com_a, com_p)
188  TYPE(xt_com_list), TARGET, INTENT(in) :: com(:)
189  TYPE(xt_com_list), TARGET, ALLOCATABLE, INTENT(inout) :: com_a(:)
190  TYPE(c_ptr), INTENT(out) :: com_p
191 
192  INTEGER :: com_size
193  INTERFACE
194  FUNCTION xt_com_list_contiguous(com_a, com_b) RESULT(p) &
195  bind(c, name='xt_com_list_contiguous')
196  IMPORT :: c_int, xt_com_list
197  TYPE(xt_com_list), INTENT(in) :: com_a, com_b
198  INTEGER(c_int) :: p
199  END FUNCTION xt_com_list_contiguous
200  END INTERFACE
201 
202  com_size = SIZE(com)
203  IF (com_size > huge(1_c_int)) &
204  CALL xt_abort('invalid size', &
205  __file__, &
206  __line__)
207  IF (com_size > 0) THEN
208  IF (com_size > 1) THEN
209  IF (xt_com_list_contiguous(com(1), com(2)) /= 0) THEN
210  CALL xt_slice_c_loc(com(1), com_p)
211  ELSE
212  ALLOCATE(com_a(com_size))
213  com_a(:) = com(:)
214  com_p = c_loc(com_a)
215  END IF
216  ELSE
217  CALL xt_slice_c_loc(com(1), com_p)
218  END IF
219  ELSE
220  com_p = c_null_ptr
221  END IF
222  END SUBROUTINE com_p_arg
223 
224 END MODULE xt_xmap_intersection
225 !
226 ! Local Variables:
227 ! f90-continuation-indent: 5
228 ! coding: utf-8
229 ! indent-tabs-mode: nil
230 ! show-trailing-whitespace: t
231 ! require-trailing-newline: t
232 ! End:
233 !
type(xt_xmap) function, public xt_xmap_c2f(xmap)
Definition: xt_xmap_f.f90:140
integer, parameter, public xt_mpi_fint_kind
Definition: xt_core_f.f90:66
external, public xt_slice_c_loc
Definition: xt_core_f.f90:143
Xt_xmap xt_xmap_intersection_new(int num_src_intersections, const struct Xt_com_list src_com[num_src_intersections], int num_dst_intersections, const struct Xt_com_list dst_com[num_dst_intersections], Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)
int xt_com_list_contiguous(const struct Xt_com_list *p_com_a, const struct Xt_com_list *p_com_b)
Definition: yaxt_f2c.c:353
Xt_xmap xt_xmap_intersection_ext_new(int num_src_intersections, const struct Xt_com_list src_com[num_src_intersections], int num_dst_intersections, const struct Xt_com_list dst_com[num_dst_intersections], Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)
Xt_idxlist xt_idxlist_f2c(struct xt_idxlist_f *p)
Definition: yaxt_f2c.c:134