Yet Another eXchange Tool 0.11.2
Loading...
Searching...
No Matches
xt_idxsection_stripe_intersection.h
Go to the documentation of this file.
1
14/*
15 * Keywords:
16 * Maintainer: Jörg Behrens <behrens@dkrz.de>
17 * Moritz Hanke <hanke@dkrz.de>
18 * Thomas Jahns <jahns@dkrz.de>
19 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are
23 * met:
24 *
25 * Redistributions of source code must retain the above copyright notice,
26 * this list of conditions and the following disclaimer.
27 *
28 * Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 *
32 * Neither the name of the DKRZ GmbH nor the names of its contributors
33 * may be used to endorse or promote products derived from this software
34 * without specific prior written permission.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
37 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
38 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
40 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 */
48#define XT_TOKEN_PASTE2_(a,b) a##b
49#ifdef NUM_DIMENSIONS
50# ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
51# define xt_idxsection_get_idxstripes_intersection__(ndims) \
52 XT_TOKEN_PASTE2_(xt_idxsection_get_idxstripes_intersection_sm_, ndims)
53# else
54# define xt_idxsection_get_idxstripes_intersection__(ndims) \
55 XT_TOKEN_PASTE2_(xt_idxsection_get_idxstripes_intersection_, ndims)
56# endif
57# define NUM_DIMENSIONS_ NUM_DIMENSIONS
58#else
59# ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
60# define xt_idxsection_get_idxstripes_intersection__(ndims) \
61 xt_idxsection_get_idxstripes_intersection_sm_
62# else
63# define xt_idxsection_get_idxstripes_intersection__(ndims) \
64 xt_idxsection_get_idxstripes_intersection_
65# endif
66# define NUM_DIMENSIONS_ num_dimensions
67#endif
68static Xt_idxlist
70 (Xt_idxsection idxsection, Xt_idxlist idxstripes_list, Xt_config config)
71{
72 // intersection between an idxsection and a set of stripes
73 size_t num_stripes
74 = xt_idxstripes_get_num_index_stripes(idxstripes_list);
75
76 const struct Xt_stripe *stripes
78#ifdef NUM_DIMENSIONS
79#define Xt_idxsection__(ndims) XT_TOKEN_PASTE2_(Xt_idxsection_,ndims)
80 struct Xt_idxsection__(NUM_DIMENSIONS) {
81
82 struct Xt_idxlist_ parent;
83
84 Xt_int *index_array_cache;
85
86 Xt_int global_start_index;
87 Xt_int local_start_index;
88 Xt_int min_index_cache;
89 Xt_int max_index_cache;
90 int ndim;
91 unsigned flags;
92 struct dim_desc dims[NUM_DIMENSIONS];
93 };
94 struct Xt_idxsection__(NUM_DIMENSIONS) h;
96 struct dim_desc *restrict dims = h.dims;
97#else
98 size_t num_dimensions = (size_t)idxsection->ndim;
99 Xt_idxsection sssp
100 = xmalloc(sizeof (struct Xt_idxsection_)
101 + sizeof (struct dim_desc) * num_dimensions);
102 idxsection_init_sorted_copy(idxsection, sssp);
103 struct dim_desc *dims = sssp->dims;
104#endif
105enum {
106 size_t_bits = sizeof (size_t) * CHAR_BIT,
107};
108#ifndef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
109size_t *restrict isect_stripes_bm
110 = xcalloc((num_stripes+size_t_bits-1)/size_t_bits, sizeof (size_t));
111#else
112size_t num_indices_in_section
113 = (size_t)xt_idxlist_get_num_indices(&idxsection->parent),
114 section_bm_size = (num_indices_in_section+size_t_bits-1)/size_t_bits,
115 *restrict pos_used_bm = xcalloc(section_bm_size
116 + (num_stripes+size_t_bits-1)/size_t_bits,
117 sizeof (size_t)),
118 *restrict isect_stripes_bm = pos_used_bm + section_bm_size;
119#endif
120size_t num_result_stripes_total = 0;
121{
122#define XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
123 /* start with non-appendable terminator */
124 Xt_int accum_start = XT_INT_MIN;
125 int buf_nstrides = 0;
126 Xt_int buf_stride = -1;
127 Xt_int index_continuation = XT_INT_MIN-1;
128 size_t isect_mask = 0;
130 if (num_stripes % size_t_bits)
131 isect_stripes_bm[num_stripes/size_t_bits] = isect_mask;
132#undef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
133}
134Xt_idxlist result;
135if (num_result_stripes_total) {
136#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
137 memset(pos_used_bm, 0, (num_indices_in_section+size_t_bits-1)/size_t_bits *
138 sizeof (size_t));
139#endif
140 struct Xt_stripes_alloc result_alloc
141 = xt_idxstripes_alloc(num_result_stripes_total);
142 struct Xt_stripe *restrict result_stripes = result_alloc.stripes;
143 size_t num_result_stripes = (size_t)-1;
144 Xt_int index_continuation = XT_INT_MIN-1, accum_start = XT_INT_MIN;
145 int buf_nstrides = 0;
146 Xt_int buf_stride = -1;
148 result_stripes[num_result_stripes].stride = buf_stride;
149 result_stripes[num_result_stripes].nstrides = buf_nstrides;
150 assert(num_result_stripes_total == num_result_stripes+1);
151 Xt_idxlist initial_result = xt_idxstripes_congeal(result_alloc);
153 || xt_idxlist_get_sorting(initial_result) == 1)
154 result = initial_result;
155 else {
156 result = xt_idxlist_sorted_copy(initial_result);
157 xt_idxlist_delete(initial_result);
158 }
159} else
160 result = xt_idxempty_new();
161#undef NUM_DIMENSIONS_
162#ifndef NUM_DIMENSIONS
163free(sssp);
164#endif
165#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
166free(pos_used_bm);
167#else
168free(isect_stripes_bm);
169#endif
170 return result;
171}
172#undef xt_idxsection_get_idxstripes_intersection__
173#ifdef NUM_DIMENSIONS
174#undef Xt_idxsection__
175#endif
176#undef XT_TOKEN_PASTE2_
177/*
178 * Local Variables:
179 * c-basic-offset: 2
180 * coding: utf-8
181 * indent-tabs-mode: nil
182 * show-trailing-whitespace: t
183 * require-trailing-newline: t
184 * End:
185 */
#define xcalloc(nmemb, size)
Definition ppm_xfuncs.h:68
#define xmalloc(size)
Definition ppm_xfuncs.h:70
struct dim_desc dims[]
struct Xt_stripe * stripes
struct Xt_config_ * Xt_config
Definition xt_config.h:58
#define XT_CONFIG_GET_FORCE_NOSORT(config)
#define XT_INT_MIN
Definition xt_core.h:78
XT_INT Xt_int
Definition xt_core.h:72
struct Xt_idxlist_ * Xt_idxlist
Definition xt_core.h:84
static size_t parent(size_t i)
Xt_idxlist xt_idxempty_new(void)
Xt_idxlist xt_idxlist_sorted_copy(Xt_idxlist idxlist)
Definition xt_idxlist.c:99
int xt_idxlist_get_sorting(Xt_idxlist idxlist)
Definition xt_idxlist.c:359
void xt_idxlist_delete(Xt_idxlist idxlist)
Definition xt_idxlist.c:75
#define xt_idxlist_get_num_indices(idxlist)
static void idxsection_init_sorted_copy(Xt_idxsection orig, Xt_idxsection copy)
#define NUM_DIMENSIONS
struct Xt_idxsection_ * Xt_idxsection
#define xt_idxsection_get_idxstripes_intersection__(ndims)
Loop over stripes to compute intersection. This source is meant to be included for multiple dimension...
const struct Xt_stripe * xt_idxstripes_get_index_stripes_const(Xt_idxlist idxlist)
struct Xt_stripes_alloc xt_idxstripes_alloc(size_t num_stripes)
Xt_idxlist xt_idxstripes_congeal(struct Xt_stripes_alloc stripes_alloc)
size_t xt_idxstripes_get_num_index_stripes(Xt_idxlist idxlist)