Yet Another eXchange Tool  0.9.0
xt_ut_c.c
Go to the documentation of this file.
1 
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  */
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50 
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <assert.h>
54 
55 #include "xt/xt_mpi.h"
56 #include "core/core.h"
57 #include "core/ppm_xfuncs.h"
58 #include "xt/xt_idxvec.h"
59 #include "xt_ut_c.h"
60 #include "xt/xt_xmap.h"
61 #include "xt/xt_xmap_all2all.h"
62 #include "xt/xt_redist_p2p.h"
63 
64 #include "xt/xt_handles.h"
65 
66 typedef struct {
70  int debug_lvl;
71  int mode;
74 
75 static xt_ut_init_type init_val = {0,0,0,0,0,0};
76 
77 
78 typedef struct {
82 
84 
85 typedef struct {
88 
90 
91 
92 typedef struct {
95 
96 
98 
99 /* the external functions declared here are intended to be called from
100  * Fortran, therefore there is no prototype declaration in a
101  * corresponding .h file.
102  */
103 #if (defined __GNUC__ && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))\
104  || (defined __clang__)
105 #pragma GCC diagnostic push
106 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
107 #endif
108 
109 void xt_ut_abort(char *msg, char *source, int *line) __attribute__((noreturn));
110 
111 void xt_ut_abort(char *msg, char *source, int *line) {
112  Xt_abort(MPI_COMM_WORLD, msg, source, *line);
113 }
114 
115 void xt_ut_init(int decomp_size, int comm_tmpl_size, int comm_trans_size, int debug_lvl, int mode, int debug_unit) {
116 
118 
119  init_val.decomp_size = decomp_size;
120  init_val.comm_tmpl_size = comm_tmpl_size;
121  init_val.comm_trans_size = comm_trans_size;
122  init_val.debug_lvl = debug_lvl;
123  init_val.mode = mode;
124  init_val.debug_unit = debug_unit;
125 
127 
129 
131 }
132 
133 void xt_ut_finalize(void) {
134  xt_finalize();
135 }
136 
137 static int new_ideco(void) {
138  xt_ut_deco_type *data = xmalloc(sizeof(*data));
139  return xt_handle_new(deco_set, data);
140 }
141 
142 static void delete_ideco(int id) {
144  free(deco);
146 }
147 
150  if (!deco) die("xt_ut_destroy_decomposition: invalid handle");
151  xt_idxlist_delete(deco->idxvec);
152  delete_ideco(id);
153 }
154 
155 static int new_itemplate(void) {
156  xt_ut_template_type *data = xmalloc(sizeof(*data));
157  return xt_handle_new(template_set, data);
158 }
159 
160 static void delete_itemplate(int id) {
162  free(template);
164 }
165 
168  if (!template) die("xt_ut_destroy_transposition_template: invalid handle");
169  xt_xmap_delete(template->xmap);
170  delete_itemplate(id);
171 }
172 
173 static int new_itrans(void) {
174  xt_ut_trans_type *data = xmalloc(sizeof(*data));
175  return xt_handle_new(trans_set, data);
176 }
177 
178 static void delete_itrans(int id) {
180  free(trans);
182 }
183 
186  if (!trans) die("xt_ut_destroy_transposition: invalid handle");
187  xt_redist_delete(trans->redist);
188  delete_itrans(id);
189 }
190 
191 
193 {
194  MPI_Fint id = new_ideco();
196  if (!deco) die("xt_ut_init_decomposition_1d: internal error");
197  deco->idxvec = xt_idxvec_new(iv, iv_n);
198  return id;
199 }
200 
201 
202 MPI_Fint
204  int XT_UNUSED(mpi_world),
205  int XT_UNUSED(icheck_unique)) {
206  xt_ut_deco_type *deco_in = xt_handle2pointer(deco_set, id_in);
207  if(!deco_in) die("xt_ut_init_oneway_transposition_template: invalid handle (first argument)");
208 
209  xt_ut_deco_type *deco_out = xt_handle2pointer(deco_set, id_out);
210  if(!deco_out) die("xt_ut_init_oneway_transposition_template: invalid handle (second argument)");
211 
212  int id = new_itemplate();
214  if (!template) die("xt_ut_init_oneway_transposition_template: internal error");
215  template->xmap = xt_xmap_all2all_new(deco_in->idxvec, deco_out->idxvec, MPI_COMM_WORLD);
216 
217  return id;
218 }
219 
220 
222  MPI_Fint f_datatype) {
223  xt_ut_template_type *template = xt_handle2pointer(template_set, itemplate);
224  if (!template) die("xt_ut_init_transposition_simple: invalid handle");
225 
226  MPI_Datatype datatype = MPI_Type_f2c(f_datatype);
227  MPI_Fint itrans = new_itrans();
228  xt_ut_trans_type *trans = xt_handle2pointer(trans_set, itrans);
229  if (!trans) die("xt_ut_init_transposition_simple: internal error");
230  trans->redist = xt_redist_p2p_off_new(template->xmap, NULL, NULL, datatype);
231 
232  return itrans;
233 }
234 
236  MPI_Fint offset_in[],
237  MPI_Fint XT_UNUSED(offset_in_size),
238  MPI_Fint offset_out[],
239  MPI_Fint XT_UNUSED(offset_out_size),
240  MPI_Fint f_datatype) {
241 
242  xt_ut_template_type *template = xt_handle2pointer(template_set, itemplate);
243  if (!template) die("xt_ut_init_transposition: invalid handle");
244 
245  MPI_Fint itrans = new_itrans();
246  xt_ut_trans_type *trans = xt_handle2pointer(trans_set, itrans);
247  if (!trans) die("xt_ut_init_transposition: internal error");
248  MPI_Datatype datatype = MPI_Type_f2c(f_datatype);
249  trans->redist = xt_redist_p2p_off_new(template->xmap, offset_in, offset_out, datatype);
250 
251  return itrans;
252 }
253 
254 
255 void xt_ut_transpose(const void **pt_in, int itrans, int XT_UNUSED(direction),
256  void **pt_out) {
257  xt_ut_trans_type *trans = xt_handle2pointer(trans_set, itrans);
258  if (!trans) die("xt_ut_transpose1: invalid handle");
259  xt_redist_s_exchange(trans->redist, 1, pt_in, pt_out);
260 }
261 
262 /*
263  * Local Variables:
264  * c-basic-offset: 2
265  * coding: utf-8
266  * indent-tabs-mode: nil
267  * show-trailing-whitespace: t
268  * require-trailing-newline: t
269  * End:
270  */
@ MPI_COMM_WORLD
Definition: core.h:73
int MPI_Fint
Definition: core.h:68
#define XT_UNUSED(x)
Definition: core.h:84
#define __attribute__(x)
Definition: core.h:82
#define die(msg)
Definition: core.h:131
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition: ppm_xfuncs.h:70
int domain_size
Definition: xt_ut_c.c:80
Xt_idxlist idxvec
Definition: xt_ut_c.c:79
int decomp_size
Definition: xt_ut_c.c:67
int debug_unit
Definition: xt_ut_c.c:72
int comm_trans_size
Definition: xt_ut_c.c:69
int comm_tmpl_size
Definition: xt_ut_c.c:68
Xt_redist redist
Definition: xt_ut_c.c:93
void xt_initialize(MPI_Comm default_comm)
Definition: xt_init.c:70
void xt_finalize(void)
Definition: xt_init.c:89
XT_INT Xt_int
Definition: xt_core.h:68
maps integers to data pointers
void * xt_handle2pointer(Xt_handle_set_type hset, int handle)
Definition: xt_handles.c:77
Xt_handle_set_type xt_handle_set_new(int cap)
Definition: xt_handles.c:82
int xt_handle_new(Xt_handle_set_type hset, void *p)
Definition: xt_handles.c:130
void xt_handle_delete(Xt_handle_set_type hset, int handle)
Definition: xt_handles.c:151
void xt_idxlist_delete(Xt_idxlist idxlist)
Definition: xt_idxlist.c:74
Xt_idxlist xt_idxvec_new(const Xt_int *idxlist, int num_indices)
Definition: xt_idxvec.c:163
utility routines for MPI
void xt_redist_delete(Xt_redist redist)
Definition: xt_redist.c:68
void xt_redist_s_exchange(Xt_redist redist, int num_arrays, const void **src_data, void **dst_data)
Definition: xt_redist.c:73
Xt_redist xt_redist_p2p_off_new(Xt_xmap xmap, const int *src_offsets, const int *dst_offsets, MPI_Datatype datatype)
void xt_ut_transpose(const void **pt_in, int itrans, int XT_UNUSED(direction), void **pt_out)
Definition: xt_ut_c.c:255
static void delete_itrans(int id)
Definition: xt_ut_c.c:178
void xt_ut_destroy_transposition_template(int id)
Definition: xt_ut_c.c:166
void xt_ut_abort(char *msg, char *source, int *line) __attribute__((noreturn))
Definition: xt_ut_c.c:111
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
static void delete_ideco(int id)
Definition: xt_ut_c.c:142
static int new_itemplate(void)
Definition: xt_ut_c.c:155
MPI_Fint xt_ut_init_transposition_simple(MPI_Fint itemplate, MPI_Fint f_datatype)
Definition: xt_ut_c.c:221
static xt_ut_init_type init_val
Definition: xt_ut_c.c:75
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
static int new_itrans(void)
Definition: xt_ut_c.c:173
static Xt_handle_set_type template_set
Definition: xt_ut_c.c:89
MPI_Fint xt_ut_init_decomposition_1d(Xt_int *iv, int iv_n)
Definition: xt_ut_c.c:192
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
static int new_ideco(void)
Definition: xt_ut_c.c:137
void xt_ut_finalize(void)
Definition: xt_ut_c.c:133
static Xt_handle_set_type deco_set
Definition: xt_ut_c.c:83
void xt_ut_destroy_decomposition(int id)
Definition: xt_ut_c.c:148
static Xt_handle_set_type trans_set
Definition: xt_ut_c.c:97
static void delete_itemplate(int id)
Definition: xt_ut_c.c:160
void xt_ut_destroy_transposition(int id)
Definition: xt_ut_c.c:184
supportes the unitrans interfaces/wrappers in xt_ut.f90 with yaxt functionality.
exchange map declarations
void xt_xmap_delete(Xt_xmap xmap)
Definition: xt_xmap.c:85
Xt_xmap xt_xmap_all2all_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)