Yet Another eXchange Tool  DO_NOT_EDIT_HERE
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
77 idxempty_copy(Xt_idxlist idxlist);
78 
79 static void
80 idxempty_get_indices(Xt_idxlist idxlist, Xt_int *indices);
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
105 idxempty_get_positions_of_indices(Xt_idxlist idxlist, Xt_int const * indices,
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 {
152 } idxempty;
153 
154 void
156 {
157  Xt_idxlist_init(&idxempty.parent, &idxempty_vtable, 0);
158 }
159 
160 void
162 {
163 }
164 
166  return (void*)&idxempty;
167 }
168 
170 }
171 
173 {
174  int size_int_type;
175 
176  xt_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &size_int_type), comm);
177 
178  return (size_t)size_int_type;
179 }
180 
181 void idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size,
182  int *position, MPI_Comm comm) {
183 
184  assert(data);
185  int type = EMPTY;
186 
187  xt_mpi_call(MPI_Pack(&(type), 1, MPI_INT, buffer,
188  buffer_size, position, comm), comm);
189 }
190 
192  int XT_UNUSED(buffer_size),
193  int *XT_UNUSED(position),
194  MPI_Comm XT_UNUSED(comm)) {
195 
196  return xt_idxempty_new();
197 }
198 
199 
200 static Xt_idxlist
202 
203  return xt_idxempty_new();
204 }
205 
206 static void
208  /* do nothing */
209 }
210 
211 static Xt_int const*
213 
214  return NULL;
215 }
216 
217 
218 static void
220  struct Xt_stripe **stripes,
221  int * num_stripes) {
222 
223  *stripes = NULL;
224  *num_stripes = 0;
225 }
226 
227 static int
229  int XT_UNUSED(position),
230  Xt_int *XT_UNUSED(index)) {
231 
232  return 1;
233 }
234 
235 static int
237  const int *XT_UNUSED(positions),
238  int num_pos,
239  Xt_int *index, Xt_int undef_idx) {
240 
241  assert(num_pos >= 0);
242 
243  for (int i = 0; i < num_pos; ++i)
244  index[i] = undef_idx;
245 
246  return num_pos;
247 }
248 
249 static int
251  Xt_int XT_UNUSED(index),
252  int *XT_UNUSED(position),
253  int XT_UNUSED(offset)) {
254  return 1;
255 }
256 
257 static int
259  Xt_int XT_UNUSED(index),
260  int *XT_UNUSED(position)) {
261 
262  return 1;
263 }
264 
266  const Xt_int *XT_UNUSED(selection_idx),
267  int num_selection,
268  int *XT_UNUSED(positions),
269  int XT_UNUSED(single_match_only)) {
270 
271  return num_selection;
272 }
273 
274 static int
276  int num_stripes,
277  const struct Xt_stripe *stripes,
278  int *num_ext,
279  struct Xt_pos_ext **pos_ext,
280  int XT_UNUSED(single_match_only))
281 {
282  *num_ext = 0;
283  *pos_ext = NULL;
284  unsigned num_idx = 0;
285  if (num_stripes > 0)
286  for (size_t i = 0; i < (size_t)num_stripes; ++i)
287  num_idx += (unsigned)stripes[i].nstrides;
288  return (int)num_idx;
289 }
290 
291 static int
293  const Xt_int *XT_UNUSED(indices),
294  int XT_UNUSED(num_indices),
295  int *XT_UNUSED(positions),
296  int *XT_UNUSED(offsets)) {
297 
298  return 1;
299 }
300 
301 static Xt_int
303 
304  die("idxempty_get_min_index: empty index list");
305 #ifndef __clang__
306  return -1;
307 #endif
308 }
309 
310 static Xt_int
312 
313  die("idxempty_get_max_index: empty index list");
314 #ifndef __clang__
315  return -1;
316 #endif
317 }
318 
319 /*
320  * Local Variables:
321  * c-basic-offset: 2
322  * coding: utf-8
323  * indent-tabs-mode: nil
324  * show-trailing-whitespace: t
325  * require-trailing-newline: t
326  * End:
327  */
static int idxempty_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int *index)
base definitions header file
static Xt_int idxempty_get_max_index(Xt_idxlist idxlist)
void xt_idxempty_init(void)
Definition: xt_idxempty.c:155
static int idxempty_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int *position)
#define die(msg)
Definition: core.h:131
static int idxempty_get_indices_at_positions(Xt_idxlist idxlist, const int *positions, int num, Xt_int *index, Xt_int undef_idx)
static Xt_int const * idxempty_get_indices_const(Xt_idxlist idxlist)
add versions of standard API functions not returning on error
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_position_of_index_off(Xt_idxlist idxlist, Xt_int index, int *position, int offset)
Xt_idxlist xt_idxempty_new(void)
Definition: xt_idxempty.c:165
static int idxempty_get_positions_of_indices(Xt_idxlist idxlist, Xt_int const *indices, int num_indices, int *positions, int single_match_only)
int nstrides
Definition: xt_stripe.h:57
XT_INT Xt_int
Definition: xt_core.h:68
Provide non-public declarations common to all index lists.
static struct xt_idxempty idxempty
static Xt_idxlist idxempty_copy(Xt_idxlist idxlist)
static void Xt_idxlist_init(Xt_idxlist idxlist, const struct xt_idxlist_vtable *vtable, int num_indices)
#define XT_UNUSED(x)
Definition: core.h:84
static void idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Definition: xt_idxempty.c:181
static void idxempty_get_indices(Xt_idxlist idxlist, Xt_int *indices)
void(* delete)(Xt_idxlist)
static Xt_int idxempty_get_min_index(Xt_idxlist idxlist)
static size_t idxempty_get_pack_size(Xt_idxlist data, MPI_Comm comm)
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)
#define xt_mpi_call(call, comm)
Definition: xt_mpi.h:68
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:191
index list declaration
static void idxempty_delete(Xt_idxlist data)
static const struct xt_idxlist_vtable idxempty_vtable
Definition: xt_idxempty.c:128
void xt_idxempty_finalize(void)
Definition: xt_idxempty.c:161
struct Xt_idxlist_ parent
Definition: xt_idxempty.c:151
int MPI_Comm
Definition: core.h:64
utility routines for MPI
static void idxempty_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe **stripes, int *num_stripes)