Yet Another eXchange Tool  0.9.0
xt_idxempty.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 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49 
50 #include <assert.h>
51 #include <limits.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <string.h>
55 
56 #include "xt/xt_core.h"
57 #include "xt/xt_idxlist.h"
58 #include "xt/xt_idxempty.h"
59 #include "xt_idxempty_internal.h"
60 #include "xt_idxlist_unpack.h"
61 #include "xt_idxlist_internal.h"
62 #include "xt/xt_mpi.h"
63 #include "core/ppm_xfuncs.h"
64 #include "core/core.h"
65 
66 static void
68 
69 static size_t
71 
72 static void
73 idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size,
74  int *position, MPI_Comm comm);
75 
76 static Xt_idxlist
78 
79 static void
81 
82 static Xt_int const*
84 
85 static void
86 idxempty_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe ** stripes,
87  int * num_stripes);
88 
89 static int
90 idxempty_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int * index);
91 
92 static int
93 idxempty_get_indices_at_positions(Xt_idxlist idxlist, const int *positions,
94  int num, Xt_int *index,
95  Xt_int undef_idx);
96 
97 static int
98 idxempty_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int * position);
99 
100 static int
102  int * position, int offset);
103 
104 static int
106  int num_indices, int *positions,
107  int single_match_only);
108 
109 static int
111  int num_stripes,
112  const struct Xt_stripe *stripes,
113  int *num_ext,
114  struct Xt_pos_ext **pos_ext,
115  int single_match_only);
116 
117 static int
119  int num_indices, int * positions,
120  int * offsets);
121 
122 static Xt_int
124 
125 static Xt_int
127 
128 static const struct xt_idxlist_vtable idxempty_vtable = {
130  .get_pack_size = idxempty_get_pack_size,
131  .pack = idxempty_pack,
132  .copy = idxempty_copy,
133  .get_indices = idxempty_get_indices,
134  .get_indices_const = idxempty_get_indices_const,
135  .get_index_stripes = idxempty_get_index_stripes,
136  .get_index_at_position = idxempty_get_index_at_position,
137  .get_indices_at_positions = idxempty_get_indices_at_positions,
138  .get_position_of_index = idxempty_get_position_of_index,
139  .get_positions_of_indices = idxempty_get_positions_of_indices,
140  .get_pos_exts_of_index_stripes = idxempty_get_pos_exts_of_index_stripes,
141  .get_position_of_index_off = idxempty_get_position_of_index_off,
142  .get_positions_of_indices_off = idxempty_get_positions_of_indices_off,
143  .get_min_index = idxempty_get_min_index,
144  .get_max_index = idxempty_get_max_index,
145  .get_bounding_box = NULL,
146  .idxlist_pack_code = EMPTY,
147 };
148 
149 // index vector data structure
150 static struct xt_idxempty {
151  struct Xt_idxlist_ parent;
153 
154 void
156 {
158 }
159 
160 void
162 {
163 }
164 
166  // ensure that yaxt is initialized
167  assert(xt_initialized());
168  return (void*)&idxempty;
169 }
170 
172 }
173 
175 {
176  int size_int_type;
177 
178  xt_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &size_int_type), comm);
179 
180  return (size_t)size_int_type;
181 }
182 
183 void idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size,
184  int *position, MPI_Comm comm) {
185 
186  (void)data;
187  assert(data);
188  static const int type = EMPTY;
189 
190  xt_mpi_call(MPI_Pack(CAST_MPI_SEND_BUF(&type), 1, MPI_INT, buffer,
191  buffer_size, position, comm), comm);
192 }
193 
195  int XT_UNUSED(buffer_size),
196  int *XT_UNUSED(position),
197  MPI_Comm XT_UNUSED(comm)) {
198 
199  return xt_idxempty_new();
200 }
201 
202 
203 static Xt_idxlist
205 
206  return xt_idxempty_new();
207 }
208 
209 static void
211  /* do nothing */
212 }
213 
214 static Xt_int const*
216 
217  return NULL;
218 }
219 
220 
221 static void
223  struct Xt_stripe **stripes,
224  int * num_stripes) {
225  (void)stripes;
226  *num_stripes = 0;
227 }
228 
229 static int
231  int XT_UNUSED(position),
232  Xt_int *XT_UNUSED(index)) {
233 
234  return 1;
235 }
236 
237 static int
239  const int *XT_UNUSED(positions),
240  int num_pos,
241  Xt_int *index, Xt_int undef_idx) {
242 
243  assert(num_pos >= 0);
244 
245  for (int i = 0; i < num_pos; ++i)
246  index[i] = undef_idx;
247 
248  return num_pos;
249 }
250 
251 static int
253  Xt_int XT_UNUSED(index),
254  int *XT_UNUSED(position),
255  int XT_UNUSED(offset)) {
256  return 1;
257 }
258 
259 static int
261  Xt_int XT_UNUSED(index),
262  int *XT_UNUSED(position)) {
263 
264  return 1;
265 }
266 
268  const Xt_int *XT_UNUSED(selection_idx),
269  int num_selection,
270  int *XT_UNUSED(positions),
271  int XT_UNUSED(single_match_only)) {
272 
273  return num_selection;
274 }
275 
276 static int
278  int num_stripes,
279  const struct Xt_stripe *stripes,
280  int *num_ext,
281  struct Xt_pos_ext **pos_ext,
282  int XT_UNUSED(single_match_only))
283 {
284  *num_ext = 0;
285  *pos_ext = NULL;
286  unsigned num_idx = 0;
287  if (num_stripes > 0)
288  for (size_t i = 0; i < (size_t)num_stripes; ++i)
289  num_idx += (unsigned)stripes[i].nstrides;
290  return (int)num_idx;
291 }
292 
293 static int
295  const Xt_int *XT_UNUSED(indices),
296  int XT_UNUSED(num_indices),
297  int *XT_UNUSED(positions),
298  int *XT_UNUSED(offsets)) {
299 
300  return 1;
301 }
302 
303 static Xt_int
305 
306  die("idxempty_get_min_index: empty index list");
307 #ifndef __clang__
308  return -1;
309 #endif
310 }
311 
312 static Xt_int
314 
315  die("idxempty_get_max_index: empty index list");
316 #ifndef __clang__
317  return -1;
318 #endif
319 }
320 
321 /*
322  * Local Variables:
323  * c-basic-offset: 2
324  * coding: utf-8
325  * indent-tabs-mode: nil
326  * show-trailing-whitespace: t
327  * require-trailing-newline: t
328  * End:
329  */
int MPI_Comm
Definition: core.h:64
#define XT_UNUSED(x)
Definition: core.h:84
#define die(msg)
Definition: core.h:131
add versions of standard API functions not returning on error
int nstrides
Definition: xt_stripe.h:57
struct Xt_idxlist_ parent
Definition: xt_idxempty.c:151
void(* delete)(Xt_idxlist)
base definitions header file
int xt_initialized(void)
Definition: xt_init.c:107
XT_INT Xt_int
Definition: xt_core.h:68
static Xt_int idxempty_get_max_index(Xt_idxlist idxlist)
static void idxempty_delete(Xt_idxlist data)
static Xt_int const * idxempty_get_indices_const(Xt_idxlist idxlist)
static int idxempty_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int *position)
static int idxempty_get_position_of_index_off(Xt_idxlist idxlist, Xt_int index, int *position, int offset)
static size_t idxempty_get_pack_size(Xt_idxlist data, MPI_Comm comm)
static int idxempty_get_indices_at_positions(Xt_idxlist idxlist, const int *positions, int num, Xt_int *index, Xt_int undef_idx)
Xt_idxlist xt_idxempty_new(void)
Definition: xt_idxempty.c:165
void xt_idxempty_finalize(void)
Definition: xt_idxempty.c:161
static const struct xt_idxlist_vtable idxempty_vtable
Definition: xt_idxempty.c:128
static int idxempty_get_positions_of_indices(Xt_idxlist idxlist, Xt_int const *indices, int num_indices, int *positions, int single_match_only)
Xt_idxlist xt_idxempty_unpack(void *XT_UNUSED(buffer), int XT_UNUSED(buffer_size), int *XT_UNUSED(position), MPI_Comm XT_UNUSED(comm))
Definition: xt_idxempty.c:194
void xt_idxempty_init(void)
Definition: xt_idxempty.c:155
static Xt_int idxempty_get_min_index(Xt_idxlist idxlist)
static void idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Definition: xt_idxempty.c:183
static Xt_idxlist idxempty_copy(Xt_idxlist idxlist)
static void idxempty_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe **stripes, int *num_stripes)
static int idxempty_get_pos_exts_of_index_stripes(Xt_idxlist idxlist, int num_stripes, const struct Xt_stripe *stripes, int *num_ext, struct Xt_pos_ext **pos_ext, int single_match_only)
static int idxempty_get_positions_of_indices_off(Xt_idxlist idxlist, Xt_int const *indices, int num_indices, int *positions, int *offsets)
static int idxempty_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int *index)
static void idxempty_get_indices(Xt_idxlist idxlist, Xt_int *indices)
static struct xt_idxempty idxempty
index list declaration
Provide non-public declarations common to all index lists.
static void Xt_idxlist_init(Xt_idxlist idxlist, const struct xt_idxlist_vtable *vtable, int num_indices)
@ EMPTY
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition: xt_mpi.h:68