Yet Another eXchange Tool 0.11.2
Loading...
Searching...
No Matches
xt_idxsection_stripe_iterate.h
Go to the documentation of this file.
1
16/*
17 * Keywords:
18 * Maintainer: Jörg Behrens <behrens@dkrz.de>
19 * Moritz Hanke <hanke@dkrz.de>
20 * Thomas Jahns <jahns@dkrz.de>
21 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions are
25 * met:
26 *
27 * Redistributions of source code must retain the above copyright notice,
28 * this list of conditions and the following disclaimer.
29 *
30 * Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 *
34 * Neither the name of the DKRZ GmbH nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
39 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
40 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
41 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
42 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
43 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
44 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
45 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
47 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */
50
51 for (size_t k = 0; k < num_stripes; ++k) {
52#ifndef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
53 if (isect_stripes_bm[k/size_t_bits] & ((size_t)1 << (k % size_t_bits)))
54 ; else continue;
55#endif
56 struct Xt_stripe query = stripes[k];
57#ifdef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
58 size_t num_result_stripes = 0;
59 bool any_match = false;
60#endif
61 for (int j = 0; j < query.nstrides; ++j) {
62 Xt_int insert_index = (Xt_int)(query.start + query.stride * j),
63 running_index = insert_index;
64 bool out_of_bounds = false;
65#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
66 int local_pos = 0;
67#endif
68 for (size_t i = 0; i < NUM_DIMENSIONS_; ++i) {
69 XT_INT_DIV_T pos = Xt_div(running_index, dims[i].agsmd,
70 dims[i].global_stride);
71 Xt_int curr_global_position = (Xt_int)pos.quot;
72 running_index = (Xt_int)pos.rem;
73 out_of_bounds |= (curr_global_position < dims[i].local_start)
74 | (curr_global_position >= dims[i].local_start + dims[i].local_size);
75#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
76 int curr_local_pos = (int)(curr_global_position - dims[i].local_start);
77 local_pos += curr_local_pos * (int)dims[i].local_stride;
78#endif
79 }
80#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
81 out_of_bounds = out_of_bounds ||
82 (pos_used_bm[local_pos/size_t_bits] >> (local_pos % size_t_bits))&1;
83#endif
84 if (!out_of_bounds) {
85#ifdef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
86 any_match = true;
87#endif
88 if (insert_index == index_continuation || buf_nstrides == 1) {
89 /* already existing stripe can be expanded */
90 ++buf_nstrides;
91 if (insert_index != index_continuation)
92 buf_stride = (Xt_int)(insert_index - accum_start);
93 } else {
94#ifndef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
95 result_stripes[num_result_stripes].nstrides = buf_nstrides;
96 result_stripes[num_result_stripes].stride = buf_stride;
97#endif
98 buf_stride = 1;
99 buf_nstrides = 1;
100 ++num_result_stripes;
101#ifndef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
102 result_stripes[num_result_stripes].start =
103#endif
104 accum_start = insert_index;
105 }
106 index_continuation = (Xt_int)(insert_index + buf_stride);
107#ifdef XT_IDXSECTION_STRIPES_ISECT_SINGLE_MATCH_ONLY
108 pos_used_bm[local_pos/size_t_bits]
109 |= ((size_t)1 << (local_pos % size_t_bits));
110#endif
111 }
112 }
113#ifdef XT_IDXSECTION_STRIPES_ISECT_CREATE_STRIPE_MASK
114 num_result_stripes_total += num_result_stripes;
115 isect_mask |= (size_t)any_match << (k % size_t_bits);
116 if ((k+1) % size_t_bits == 0) {
117 isect_stripes_bm[k/size_t_bits] = isect_mask;
118 isect_mask = 0;
119 }
120#endif
121 }
122
123/*
124 * Local Variables:
125 * c-basic-offset: 2
126 * coding: utf-8
127 * indent-tabs-mode: nil
128 * show-trailing-whitespace: t
129 * require-trailing-newline: t
130 * End:
131 */
Xt_int stride
Definition xt_stripe.h:56
int nstrides
Definition xt_stripe.h:57
Xt_int start
Definition xt_stripe.h:55
#define Xt_div(num, muldiv, den)
XT_INT Xt_int
Definition xt_core.h:72