Yet Another eXchange Tool 0.11.2
Loading...
Searching...
No Matches
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://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
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"
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
66static void
68
69static size_t
71
72static void
73idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size,
74 int *position, MPI_Comm comm);
75
76static Xt_idxlist
78
79static Xt_idxlist
81
82static void
84
85static Xt_int const*
87
88static int
90
91static void
93 size_t num_stripes_alloc);
94
95static int
96idxempty_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int * index);
97
98static int
99idxempty_get_indices_at_positions(Xt_idxlist idxlist, const int *positions,
100 int num, Xt_int *index,
101 Xt_int undef_idx);
102
103static int
104idxempty_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int * position);
105
106static int
108 int * position, int offset);
109
110static size_t
112 size_t num_indices, int *positions,
113 int single_match_only);
114
115static int
117 int num_stripes,
118 const struct Xt_stripe *stripes,
119 int *num_ext,
120 struct Xt_pos_ext **pos_ext,
121 int single_match_only,
122 Xt_config config);
123
124static int
126 int num_indices, int * positions,
127 int * offsets);
128
129static Xt_int
131
132static Xt_int
134
135static int
137
138static const struct xt_idxlist_vtable idxempty_vtable = {
139 .delete = idxempty_delete,
140 .get_pack_size = idxempty_get_pack_size,
141 .pack = idxempty_pack,
142 .copy = idxempty_copy,
143 .sorted_copy = idxempty_sorted_copy,
144 .get_indices = idxempty_get_indices,
145 .get_indices_const = idxempty_get_indices_const,
146 .get_num_index_stripes = idxempty_get_num_index_stripes,
147 .get_index_stripes = idxempty_get_index_stripes,
148 .get_index_at_position = idxempty_get_index_at_position,
149 .get_indices_at_positions = idxempty_get_indices_at_positions,
150 .get_position_of_index = idxempty_get_position_of_index,
151 .get_positions_of_indices = idxempty_get_positions_of_indices,
152 .get_pos_exts_of_index_stripes = idxempty_get_pos_exts_of_index_stripes,
153 .get_position_of_index_off = idxempty_get_position_of_index_off,
154 .get_positions_of_indices_off = idxempty_get_positions_of_indices_off,
155 .get_min_index = idxempty_get_min_index,
156 .get_max_index = idxempty_get_max_index,
157 .get_sorting = idxempty_get_sorting,
158 .get_bounding_box = NULL,
159 .idxlist_pack_code = EMPTY,
160};
161
162// index vector data structure
163static struct xt_idxempty {
164 struct Xt_idxlist_ parent;
166
167void
169{
171}
172
173void
175{
176}
177
179 // ensure that yaxt is initialized
180 assert(xt_initialized());
181 return (void*)&idxempty;
182}
183
185}
186
188{
189 int size_int_type;
190
191 xt_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &size_int_type), comm);
192
193 return (size_t)size_int_type;
194}
195
196void idxempty_pack(Xt_idxlist data, void *buffer, int buffer_size,
197 int *position, MPI_Comm comm) {
198
199 (void)data;
200 assert(data);
201 static const int type = EMPTY;
202
203 xt_mpi_call(MPI_Pack(CAST_MPI_SEND_BUF(&type), 1, MPI_INT, buffer,
204 buffer_size, position, comm), comm);
205}
206
208 int XT_UNUSED(buffer_size),
209 int *XT_UNUSED(position),
210 MPI_Comm XT_UNUSED(comm)) {
211
212 return xt_idxempty_new();
213}
214
215
216static Xt_idxlist
218{
219 return xt_idxempty_new();
220}
221
222static Xt_idxlist
227
228static void
230 /* do nothing */
231}
232
233static Xt_int const*
235
236 return NULL;
237}
238
239static int
241{
242 (void)idxlist;
243 return 0;
244}
245
246static void
248 struct Xt_stripe *stripes,
249 size_t num_stripes_alloc) {
250 (void)stripes;
251 (void)num_stripes_alloc;
252}
253
254static int
256 int XT_UNUSED(position),
257 Xt_int *XT_UNUSED(index)) {
258
259 return 1;
260}
261
262static int
264 const int *XT_UNUSED(positions),
265 int num_pos,
266 Xt_int *index, Xt_int undef_idx) {
267
268 assert(num_pos >= 0);
269
270 for (int i = 0; i < num_pos; ++i)
271 index[i] = undef_idx;
272
273 return num_pos;
274}
275
276static int
278 Xt_int XT_UNUSED(index),
279 int *XT_UNUSED(position),
280 int XT_UNUSED(offset)) {
281 return 1;
282}
283
284static int
286 Xt_int XT_UNUSED(index),
287 int *XT_UNUSED(position)) {
288
289 return 1;
290}
291
293 const Xt_int *XT_UNUSED(selection_idx),
294 size_t num_selection,
295 int *XT_UNUSED(positions),
296 int XT_UNUSED(single_match_only)) {
297
298 return num_selection;
299}
300
301static int
303 int num_stripes,
304 const struct Xt_stripe *stripes,
305 int *num_ext,
306 struct Xt_pos_ext **pos_ext,
307 int XT_UNUSED(single_match_only),
308 Xt_config XT_UNUSED(config))
309{
310 *num_ext = 0;
311 *pos_ext = NULL;
312 unsigned num_idx = 0;
313 if (num_stripes > 0)
314 for (size_t i = 0; i < (size_t)num_stripes; ++i)
315 num_idx += (unsigned)stripes[i].nstrides;
316 return (int)num_idx;
317}
318
319static int
321 const Xt_int *XT_UNUSED(indices),
323 int *XT_UNUSED(positions),
324 int *XT_UNUSED(offsets)) {
325
326 return 1;
327}
328
329static Xt_int
331
332 die("idxempty_get_min_index: empty index list");
333#ifndef __clang__
334 return -1;
335#endif
336}
337
338static Xt_int
340
341 die("idxempty_get_max_index: empty index list");
342#ifndef __clang__
343 return -1;
344#endif
345}
346
347static int
349{
350 return 2;
351}
352
353/*
354 * Local Variables:
355 * c-basic-offset: 2
356 * coding: utf-8
357 * indent-tabs-mode: nil
358 * show-trailing-whitespace: t
359 * require-trailing-newline: t
360 * End:
361 */
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
struct Xt_config_ * Xt_config
Definition xt_config.h:58
base definitions header file
int xt_initialized(void)
XT_INT Xt_int
Definition xt_core.h:72
struct Xt_idxlist_ * Xt_idxlist
Definition xt_core.h:84
static int idxempty_get_sorting(Xt_idxlist idxlist)
static void idxempty_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe *stripes, size_t num_stripes_alloc)
static Xt_int const * idxempty_get_indices_const(Xt_idxlist idxlist)
static Xt_int idxempty_get_max_index(Xt_idxlist idxlist)
static size_t idxempty_get_positions_of_indices(Xt_idxlist idxlist, Xt_int const *indices, size_t num_indices, int *positions, int single_match_only)
static void idxempty_delete(Xt_idxlist data)
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, Xt_config config)
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 Xt_idxlist idxempty_sorted_copy(Xt_idxlist idxlist, Xt_config config)
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)
void xt_idxempty_finalize(void)
static const struct xt_idxlist_vtable idxempty_vtable
Xt_idxlist xt_idxempty_unpack(void *XT_UNUSED(buffer), int XT_UNUSED(buffer_size), int *XT_UNUSED(position), MPI_Comm XT_UNUSED(comm))
void xt_idxempty_init(void)
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)
static int idxempty_get_num_index_stripes(Xt_idxlist idxlist)
static Xt_idxlist idxempty_copy(Xt_idxlist idxlist)
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