Yet Another eXchange Tool  DO_NOT_EDIT_HERE
yaxt_f2c.c
Go to the documentation of this file.
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 
47 #ifdef HAVE_CONFIG_H
48 #include "config.h"
49 #endif
50 
51 #include <assert.h>
52 #include <mpi.h>
53 
54 #include "core/core.h"
55 #if defined __clang__
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wreserved-id-macro"
58 #endif
59 #include "cfortran.h"
60 #if defined __clang__
61 #pragma GCC diagnostic pop
62 #endif
63 
64 #include "xt/xt_mpi.h"
65 #include "xt/xt_idxlist.h"
66 #include "xt/xt_idxvec.h"
67 #include "xt/xt_xmap.h"
69 #include "xt/xt_xmap_all2all.h"
70 #include "xt/xt_xmap_dist_dir.h"
72 #include "xt/xt_idxstripes.h"
73 #include "xt/xt_redist.h"
74 #include "xt/xt_redist_p2p.h"
75 #include "xt/xt_idxmod.h"
78 #include "xt/xt_sort.h"
79 
80 struct xt_idxlist_f {
82 };
83 
84 struct xt_xmap_f {
86 };
87 
88 struct xt_redist_f {
90 };
91 
92 /* These functions are meant to be called from Fortran and don't need
93  * an interface declaration in a C header */
94 #if (defined __GNUC__ && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))\
95  || (defined __clang__)
96 #pragma GCC diagnostic push
97 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
98 #endif
99 
100 void xt_initialize_f(MPI_Fint *comm_f) {
101  MPI_Comm comm_c;
102  comm_c = MPI_Comm_f2c(*comm_f);
103  xt_initialize(comm_c);
104 }
105 
107 {
108  return MPI_Comm_c2f(Xt_default_comm);
109 }
110 
111 void xt_abort_f(MPI_Fint comm_f, const char *msg, const char *source,
112  int line) __attribute__((noreturn));
113 void xt_abort_f(MPI_Fint comm_f, const char *msg, const char *source,
114  int line) {
115  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
116  Xt_abort(comm_c, msg, source, line);
117 }
118 
119 void xt_sort_int_f2c(int *a, size_t n)
120 {
121  xt_sort_int(a, n);
122 }
123 
124 void xt_sort_index_f2c(Xt_int *a, int n, int *idx, int reset_index)
125 {
126  xt_sort_index(a, n, idx, reset_index);
127 }
128 
129 void xt_sort_idxpos_f2c(idxpos_type *a, size_t n)
130 {
131  xt_sort_idxpos(a, n);
132 }
133 
135 {
136  return p->cptr;
137 }
138 
140 {
141  return p->cptr;
142 }
143 
145 {
146  return p->cptr;
147 }
148 
149 
151  MPI_Fint comm_f)
152 {
153  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
154  size_t size = xt_idxlist_get_pack_size(idxlist->cptr, comm_c);
155  if (size > XT_MPI_FINT_MAX)
156  Xt_abort(comm_c, "pack size too large", __FILE__, __LINE__);
157  return (MPI_Fint)size;
158 }
159 
160 static void
161 xt_idxlist_pack_f2c(struct xt_idxlist_f *idxlist, void *buffer,
162  MPI_Fint buffer_size, MPI_Fint *position, MPI_Fint comm_f)
163 {
164  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
165  xt_idxlist_pack(idxlist->cptr, buffer, (int)buffer_size, position,
166  comm_c);
167 }
168 
170  PVOID, PVOID, INT, PINT, INT)
171 
172 static void
173 xt_idxlist_unpack_f2c(struct xt_idxlist_f *idxlist, void *buffer,
174  MPI_Fint buffer_size, MPI_Fint *position,
175  MPI_Fint comm_f)
176 {
177  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
178  idxlist->cptr = xt_idxlist_unpack(buffer, (int)buffer_size, position, comm_c);
179 }
180 
181 FCALLSCSUB5(xt_idxlist_unpack_f2c, XT_IDXLIST_UNPACK_F, xt_idxlist_unpack_f,
182  PVOID, PVOID, INT, PINT, INT)
183 
184 Xt_xmap xt_xmap_all2all_new_f(struct xt_idxlist_f *src_idxlist_f,
185  struct xt_idxlist_f *dst_idxlist_f,
186  MPI_Fint comm_f) {
187  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
188  return xt_xmap_all2all_new(src_idxlist_f->cptr, dst_idxlist_f->cptr, comm_c);
189 }
190 
192  struct xt_idxlist_f *dst_idxlist_f,
193  MPI_Fint comm_f) {
194  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
195  return xt_xmap_dist_dir_new(src_idxlist_f->cptr, dst_idxlist_f->cptr, comm_c);
196 }
197 
198 Xt_xmap
200  struct xt_idxlist_f *dst_idxlist_f,
201  MPI_Fint inter_comm_f, MPI_Fint intra_comm_f)
202 {
203  MPI_Comm inter_comm_c = MPI_Comm_f2c(inter_comm_f),
204  intra_comm_c = MPI_Comm_f2c(intra_comm_f);
205  return xt_xmap_dist_dir_intercomm_new(src_idxlist_f->cptr,
206  dst_idxlist_f->cptr,
207  inter_comm_c, intra_comm_c);
208 }
209 
211  int *src_block_offsets,
212  int *src_block_sizes,
213  int src_block_num,
214  int *dst_block_offsets,
215  int *dst_block_sizes,
216  int dst_block_num,
217  MPI_Fint datatype_f) {
218  MPI_Datatype datatype_c = MPI_Type_f2c(datatype_f);
219 
220  return xt_redist_p2p_blocks_off_new(xmap_f->cptr,
221  src_block_offsets, src_block_sizes,
222  src_block_num,
223  dst_block_offsets, dst_block_sizes,
224  dst_block_num,
225  datatype_c);
226 }
227 
229  int *src_block_sizes, int src_block_num,
230  int *dst_block_sizes, int dst_block_num,
231  MPI_Fint datatype_f) {
232  MPI_Datatype datatype_c = MPI_Type_f2c(datatype_f);
233 
234  return xt_redist_p2p_blocks_new(xmap_f->cptr,
235  src_block_sizes, src_block_num,
236  dst_block_sizes, dst_block_num,
237  datatype_c);
238 }
239 
240 Xt_redist
242  MPI_Fint *src_offsets, MPI_Fint *dst_offsets,
243  MPI_Fint datatype_f) {
244  MPI_Datatype datatype_c = MPI_Type_f2c(datatype_f);
245  assert(sizeof (MPI_Fint) == sizeof (int));
246 
247  return xt_redist_p2p_off_new(xmap_f->cptr, src_offsets, dst_offsets,
248  datatype_c);
249 }
250 
251 Xt_redist
252 xt_redist_p2p_new_f(struct xt_xmap_f *xmap_f, MPI_Fint datatype_f) {
253  MPI_Datatype datatype_c = MPI_Type_f2c(datatype_f);
254 
255  return xt_redist_p2p_new(xmap_f->cptr, datatype_c);
256 }
257 
258 Xt_redist
260  MPI_Aint *src_displacements,
261  MPI_Aint *dst_displacements,
262  MPI_Fint comm_f)
263 {
264 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
265 #pragma GCC diagnostic push
266 #pragma GCC diagnostic ignored "-Wtype-limits"
267 #endif
268  assert((long long)num_redists <= (long long)INT_MAX);
269 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
270 #pragma GCC diagnostic pop
271 #endif
272  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
273  if (num_redists < 1)
274  Xt_abort(comm_c, "bad case: (num_redists < 1)", __FILE__, __LINE__);
275 
276  return xt_redist_collection_static_new(redists, (int)num_redists,
277  src_displacements,
278  dst_displacements,
279  comm_c);
280 }
281 
282 Xt_redist
284  MPI_Fint cache_size, MPI_Fint comm_f)
285 {
286 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
287 #pragma GCC diagnostic push
288 #pragma GCC diagnostic ignored "-Wtype-limits"
289 #endif
290  assert((long long)num_redists <= (long long)INT_MAX
291  && (long long)cache_size <= (long long)INT_MAX);
292 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
293 #pragma GCC diagnostic pop
294 #endif
295  MPI_Comm comm_c = MPI_Comm_f2c(comm_f);
296  if (num_redists < 1)
297  Xt_abort(comm_c, "bad case: (num_redists < 1)", __FILE__, __LINE__);
298  return xt_redist_collection_new(redists, (int)num_redists,
299  (int)cache_size, comm_c);
300 }
301 
302 static void
303 xt_slice_c_loc_f2c(void *a, void *p)
304 {
305  *(void **)p = a;
306 }
307 
308 FCALLSCSUB2(xt_slice_c_loc_f2c,XT_SLICE_C_LOC,xt_slice_c_loc,PVOID,PVOID)
309 
310 MPI_Fint
312 {
313  MPI_Comm comm = xt_redist_get_MPI_Comm(*redist);
314  return MPI_Comm_c2f(comm);
315 }
316 
317 void *
319  int num_src_ext, struct Xt_offset_ext src_extents[],
320  int num_dst_ext, struct Xt_offset_ext dst_extents[],
321  MPI_Fint datatype_f)
322 {
323  return xt_redist_p2p_ext_new(*xmap, num_src_ext, src_extents,
324  num_dst_ext, dst_extents,
325  MPI_Type_f2c(datatype_f));
326 }
327 
328 void *
330  int num_src_intersections,
331  const struct Xt_com_list src_com[num_src_intersections],
332  int num_dst_intersections,
333  const struct Xt_com_list dst_com[num_dst_intersections],
334  void *src_idxlist, void *dst_idxlist, MPI_Fint comm)
335 {
336  return xt_xmap_intersection_new(num_src_intersections, src_com,
337  num_dst_intersections, dst_com,
338  src_idxlist, dst_idxlist, MPI_Comm_f2c(comm));
339 }
340 
341 void *
343  int num_src_intersections, const void *src_com,
344  int num_dst_intersections, const void *dst_com,
345  void *src_idxlist, void *dst_idxlist, MPI_Fint comm)
346 {
348  num_src_intersections, src_com, num_dst_intersections, dst_com,
349  src_idxlist, dst_idxlist, MPI_Comm_f2c(comm));
350 }
351 
352 int
353 xt_com_list_contiguous(const struct Xt_com_list *p_com_a,
354  const struct Xt_com_list *p_com_b)
355 {
356  return (p_com_a + 1 == p_com_b);
357 }
358 
359 void
361  xt_mpi_comm_mark_exclusive(MPI_Comm_f2c(*comm));
362 }
363 #if (defined __GNUC__ && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))\
364  || (defined __clang__)
365 #pragma GCC diagnostic pop
366 #endif
367 
368 /*
369  * Local Variables:
370  * c-basic-offset: 2
371  * coding: utf-8
372  * indent-tabs-mode: nil
373  * show-trailing-whitespace: t
374  * require-trailing-newline: t
375  * End:
376  */
void * xt_xmap_intersection_new_f2c(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], void *src_idxlist, void *dst_idxlist, MPI_Fint comm)
Definition: yaxt_f2c.c:329
Xt_idxlist xt_idxlist_unpack(void *buffer, int buffer_size, int *position, MPI_Comm comm)
Xt_xmap xt_xmap_f2c(struct xt_xmap_f *p)
Definition: yaxt_f2c.c:144
Xt_xmap cptr
Definition: yaxt_f2c.c:85
Xt_redist xt_redist_p2p_blocks_off_new_f(struct xt_xmap_f *xmap_f, int *src_block_offsets, int *src_block_sizes, int src_block_num, int *dst_block_offsets, int *dst_block_sizes, int dst_block_num, MPI_Fint datatype_f)
Definition: yaxt_f2c.c:210
Xt_redist cptr
Definition: yaxt_f2c.c:89
int MPI_Fint
Definition: core.h:68
void xt_sort_index_f2c(Xt_int *a, int n, int *idx, int reset_index)
Definition: yaxt_f2c.c:124
void xt_sort_int_f2c(int *a, size_t n)
Definition: yaxt_f2c.c:119
void xt_initialize_f(MPI_Fint *comm_f)
Definition: yaxt_f2c.c:100
external, public xt_idxlist_unpack_f
Xt_redist xt_redist_collection_static_new(Xt_redist *redists, int num_redists, const MPI_Aint src_displacements[num_redists], const MPI_Aint dst_displacements[num_redists], MPI_Comm comm)
Xt_xmap xt_xmap_dist_dir_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)
void xt_initialize(MPI_Comm default_comm)
Definition: xt_init.c:69
void xt_mpi_comm_mark_exclusive(MPI_Comm comm)
Definition: xt_mpi.c:918
void(* xt_sort_idxpos)(idxpos_type *v, size_t n)
Definition: xt_sort.c:57
Xt_redist xt_redist_p2p_off_new_f(struct xt_xmap_f *xmap_f, MPI_Fint *src_offsets, MPI_Fint *dst_offsets, MPI_Fint datatype_f)
Definition: yaxt_f2c.c:241
external, public xt_idxlist_pack_f
Xt_xmap xt_xmap_all2all_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)
external, public xt_slice_c_loc
Definition: xt_core_f.f90:143
Xt_redist xt_redist_collection_static_new_f(Xt_redist *redists, MPI_Fint num_redists, MPI_Aint *src_displacements, MPI_Aint *dst_displacements, MPI_Fint comm_f)
Definition: yaxt_f2c.c:259
FCALLSCSUB5(xt_idxlist_pack_f2c, XT_IDXLIST_PACK_F, xt_idxlist_pack_f, PVOID, PVOID, INT, PINT, INT)
Definition: yaxt_f2c.c:169
void(* xt_sort_index)(Xt_int *a, int n, int *idx, int reset_index)
Definition: xt_sort.c:55
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)
Xt_redist xt_redist_p2p_ext_new(Xt_xmap xmap, int num_src_ext, const struct Xt_offset_ext src_extents[], int num_dst_ext, const struct Xt_offset_ext dst_extents[], MPI_Datatype datatype)
Xt_xmap xt_xmap_dist_dir_intercomm_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm inter_comm, MPI_Comm intra_comm)
MPI_Fint xt_redist_get_mpi_comm_c2f(Xt_redist *redist)
Definition: yaxt_f2c.c:311
exchange map declarations
Xt_idxlist cptr
Definition: yaxt_f2c.c:81
XT_INT Xt_int
Definition: xt_core.h:68
Xt_redist xt_redist_p2p_off_new(Xt_xmap xmap, const int *src_offsets, const int *dst_offsets, MPI_Datatype datatype)
void * xt_redist_p2p_ext_new_c2f(Xt_xmap *xmap, int num_src_ext, struct Xt_offset_ext src_extents[], int num_dst_ext, struct Xt_offset_ext dst_extents[], MPI_Fint datatype_f)
Definition: yaxt_f2c.c:318
Xt_redist xt_redist_collection_new_f(Xt_redist *redists, MPI_Fint num_redists, MPI_Fint cache_size, MPI_Fint comm_f)
Definition: yaxt_f2c.c:283
Xt_xmap xt_xmap_dist_dir_intercomm_new_f(struct xt_idxlist_f *src_idxlist_f, struct xt_idxlist_f *dst_idxlist_f, MPI_Fint inter_comm_f, MPI_Fint intra_comm_f)
Definition: yaxt_f2c.c:199
MPI_Fint xt_get_default_comm_f(void)
Definition: yaxt_f2c.c:106
MPI_Fint xt_idxlist_get_pack_size_f2c(struct xt_idxlist_f *idxlist, MPI_Fint comm_f)
Definition: yaxt_f2c.c:150
#define __attribute__(x)
Definition: core.h:82
redistribution of data
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)
void * xt_xmap_intersection_ext_new_f2c(int num_src_intersections, const void *src_com, int num_dst_intersections, const void *dst_com, void *src_idxlist, void *dst_idxlist, MPI_Fint comm)
Definition: yaxt_f2c.c:342
Xt_redist xt_redist_p2p_blocks_off_new(Xt_xmap xmap, const int *src_block_offsets, const int *src_block_sizes, int src_block_num, const int *dst_block_offsets, const int *dst_block_sizes, int dst_block_num, MPI_Datatype datatype)
Xt_redist xt_redist_p2p_new_f(struct xt_xmap_f *xmap_f, MPI_Fint datatype_f)
Definition: yaxt_f2c.c:252
void xt_abort_f(MPI_Fint comm_f, const char *msg, const char *source, int line) __attribute__((noreturn))
Definition: yaxt_f2c.c:113
static void xt_slice_c_loc_f2c(void *a, void *p)
Definition: yaxt_f2c.c:303
Xt_redist xt_redist_f2c(struct xt_redist_f *p)
Definition: yaxt_f2c.c:139
size_t xt_idxlist_get_pack_size(Xt_idxlist idxlist, MPI_Comm comm)
Definition: xt_idxlist.c:78
static void xt_idxlist_pack_f2c(struct xt_idxlist_f *idxlist, void *buffer, MPI_Fint buffer_size, MPI_Fint *position, MPI_Fint comm_f)
Definition: yaxt_f2c.c:161
Xt_redist xt_redist_p2p_new(Xt_xmap xmap, MPI_Datatype datatype)
Xt_xmap xt_xmap_dist_dir_new_f(struct xt_idxlist_f *src_idxlist_f, struct xt_idxlist_f *dst_idxlist_f, MPI_Fint comm_f)
Definition: yaxt_f2c.c:191
index list declaration
Xt_redist xt_redist_p2p_blocks_new(Xt_xmap xmap, const int *src_block_sizes, int src_block_num, const int *dst_block_sizes, int dst_block_num, MPI_Datatype datatype)
MPI_Comm xt_redist_get_MPI_Comm(Xt_redist redist)
Definition: xt_redist.c:92
Xt_idxlist xt_idxlist_f2c(struct xt_idxlist_f *p)
Definition: yaxt_f2c.c:134
void xt_sort_idxpos_f2c(idxpos_type *a, size_t n)
Definition: yaxt_f2c.c:129
void xt_idxlist_pack(Xt_idxlist idxlist, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Definition: xt_idxlist.c:84
void(* xt_sort_int)(int *a, size_t n)
Definition: xt_sort.c:53
Xt_redist xt_redist_p2p_blocks_new_f(struct xt_xmap_f *xmap_f, int *src_block_sizes, int src_block_num, int *dst_block_sizes, int dst_block_num, MPI_Fint datatype_f)
Definition: yaxt_f2c.c:228
int MPI_Comm
Definition: core.h:64
utility routines for MPI
void xt_mpi_comm_mark_exclusive_f2c(MPI_Fint *comm)
Definition: yaxt_f2c.c:360
Xt_redist xt_redist_collection_new(Xt_redist *redists, int num_redists, int cache_size, MPI_Comm comm)