• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #872

24 Jan 2023 07:29PM UTC coverage: 85.694% (-0.9%) from 86.624%
#872

push

StellarBot
Merge #6148

6148: Investigate the failure of the LCI parcelport. r=hkaiser a=JiakunYan



Co-authored-by: Jiakun Yan <jiakunyan1998@gmail.com>

173076 of 201969 relevant lines covered (85.69%)

2110584.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/full/segmented_algorithms/tests/unit/partitioned_vector_iter.cpp
1
//  Copyright (c) 2014-2017 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#if !defined(HPX_COMPUTE_DEVICE_CODE)
9
#include <hpx/hpx_main.hpp>
10
#include <hpx/include/partitioned_vector_predef.hpp>
11
#include <hpx/include/runtime.hpp>
12
#include <hpx/include/traits.hpp>
13
#include <hpx/modules/testing.hpp>
14

15
#include <algorithm>
16
#include <cstddef>
17
#include <cstdint>
18
#include <functional>
19
#include <iostream>
20
#include <memory>
21
#include <string>
22
#include <vector>
23

24
///////////////////////////////////////////////////////////////////////////////
25
// The vector types to be used are defined in partitioned_vector module.
26
// HPX_REGISTER_PARTITIONED_VECTOR(double)
27
// HPX_REGISTER_PARTITIONED_VECTOR(int)
28

29
///////////////////////////////////////////////////////////////////////////////
30
template <typename T>
31
void test_global_iteration(
×
32
    hpx::partitioned_vector<T>& v, std::size_t size, T const& val)
33
{
34
    typedef typename hpx::partitioned_vector<T>::iterator iterator;
35
    typedef hpx::traits::segmented_iterator_traits<iterator> traits;
36
    HPX_TEST(traits::is_segmented_iterator::value);
×
37

38
    typedef typename hpx::partitioned_vector<T>::const_iterator const_iterator;
39
    typedef hpx::traits::segmented_iterator_traits<const_iterator> const_traits;
40
    HPX_TEST(const_traits::is_segmented_iterator::value);
×
41

42
    HPX_TEST_EQ(v.size(), size);
×
43
    for (std::size_t i = 0; i != size; ++i)
×
44
    {
45
        HPX_TEST_EQ(v[i], val);
×
46
        v[i] = T(i + 1);
×
47
        HPX_TEST_EQ(v[i], T(i + 1));
×
48
    }
×
49

50
    // test normal iteration
51
    std::size_t count = 0;
×
52
    std::size_t i = 42;
×
53
    for (iterator it = v.begin(); it != v.end(); ++it, ++i, ++count)
×
54
    {
55
        HPX_TEST_NEQ(*it, val);
×
56
        *it = T(i);
×
57
        HPX_TEST_EQ(*it, T(i));
×
58
    }
×
59
    HPX_TEST_EQ(count, size);
×
60

61
    count = 0;
×
62
    i = 42;
×
63
    for (const_iterator cit = v.cbegin(); cit != v.cend(); ++cit, ++i, ++count)
×
64
    {
65
        HPX_TEST_EQ(*cit, T(i));
×
66
    }
×
67
    HPX_TEST_EQ(count, size);
×
68
}
×
69

70
// test segmented iteration
71
template <typename T>
72
void test_segmented_iteration(
×
73
    hpx::partitioned_vector<T>& v, std::size_t size, std::size_t parts)
74
{
75
    typedef typename hpx::partitioned_vector<T>::iterator iterator;
76
    typedef hpx::traits::segmented_iterator_traits<iterator> traits;
77
    typedef typename traits::segment_iterator segment_iterator;
78
    typedef typename traits::local_segment_iterator local_segment_iterator;
79
    typedef typename traits::local_iterator local_iterator;
80
    typedef typename traits::local_raw_iterator local_raw_iterator;
81

82
    typedef typename hpx::partitioned_vector<T>::const_iterator const_iterator;
83
    typedef hpx::traits::segmented_iterator_traits<const_iterator> const_traits;
84
    typedef typename const_traits::segment_iterator const_segment_iterator;
85
    typedef typename const_traits::local_segment_iterator
86
        const_local_segment_iterator;
87
    typedef typename const_traits::local_iterator const_local_iterator;
88
    typedef typename const_traits::local_raw_iterator const_local_raw_iterator;
89

90
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
91
             segment_iterator>::is_segmented_iterator::value);
92
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
93
             const_segment_iterator>::is_segmented_iterator::value);
94

95
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
96
             local_segment_iterator>::is_segmented_iterator::value);
97
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
98
             const_local_segment_iterator>::is_segmented_iterator::value);
99

100
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
101
             local_iterator>::is_segmented_iterator::value);
102
    HPX_TEST(!hpx::traits::segmented_iterator_traits<
×
103
             const_local_iterator>::is_segmented_iterator::value);
104

105
    // test segmented and local iteration
106
    std::size_t seg_count = 0;
×
107
    std::size_t count = 0;
×
108
    segment_iterator seg_end = traits::segment(v.end());
×
109
    for (segment_iterator seg_it = traits::segment(v.begin());
×
110
         seg_it != seg_end; ++seg_it, ++seg_count)
×
111
    {
112
        local_iterator loc_end = traits::end(seg_it);
×
113
        for (local_iterator lit = traits::begin(seg_it); lit != loc_end;
×
114
             ++lit, ++count)
×
115
        {
116
        }
×
117
    }
×
118
    HPX_TEST_EQ(count, size);
×
119
    HPX_TEST_EQ(seg_count, parts);
×
120

121
    // const
122
    count = 0;
×
123
    seg_count = 0;
×
124
    const_segment_iterator seg_cend = const_traits::segment(v.cend());
×
125
    for (const_segment_iterator seg_cit = const_traits::segment(v.cbegin());
×
126
         seg_cit != seg_cend; ++seg_cit, ++seg_count)
×
127
    {
128
        const_local_iterator loc_cend = const_traits::end(seg_cit);
×
129
        for (const_local_iterator lcit = const_traits::begin(seg_cit);
×
130
             lcit != loc_cend; ++lcit, ++count)
×
131
        {
132
        }
×
133
    }
×
134
    HPX_TEST_EQ(count, size);
×
135
    HPX_TEST_EQ(seg_count, parts);
×
136

137
    // test iteration over localities
138
    count = 0;
×
139
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
140
    {
141
        std::uint32_t locality_id = hpx::naming::get_locality_id_from_id(loc);
×
142
        iterator end = v.end(locality_id);
×
143
        for (iterator it = v.begin(locality_id); it != end; ++it, ++count)
×
144
        {
145
            std::size_t i = 42;
×
146
            local_iterator loc_end = traits::end(traits::segment(it));
×
147
            for (local_iterator lit = traits::begin(traits::segment(it));
×
148
                 lit != loc_end; ++lit, ++i)
×
149
            {
150
                *lit = T(i);
×
151
                HPX_TEST_EQ(*lit, T(i));
×
152
            }
×
153
        }
×
154
    }
155
    HPX_TEST_EQ(count, size);
×
156

157
    count = 0;
×
158
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
159
    {
160
        std::uint32_t locality_id = hpx::naming::get_locality_id_from_id(loc);
×
161
        const_iterator end = v.cend(locality_id);
×
162
        for (const_iterator it = v.cbegin(locality_id); it != end;
×
163
             ++it, ++count)
×
164
        {
165
            std::size_t i = 42;
×
166
            const_local_iterator loc_end =
167
                const_traits::end(const_traits::segment(it));
×
168
            for (const_local_iterator lcit =
×
169
                     const_traits::begin(const_traits::segment(it));
×
170
                 lcit != loc_end; ++lcit, ++i)
×
171
            {
172
                HPX_TEST_EQ(*lcit, T(i));
×
173
            }
×
174
        }
×
175
    }
176
    HPX_TEST_EQ(count, size);
×
177

178
    // test segmented iteration over localities
179
    seg_count = 0;
×
180
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
181
    {
182
        std::uint32_t locality_id = hpx::naming::get_locality_id_from_id(loc);
×
183
        local_segment_iterator seg_end = v.segment_end(locality_id);
×
184
        for (local_segment_iterator seg_it = v.segment_begin(locality_id);
×
185
             seg_it != seg_end; ++seg_it, ++seg_count)
×
186
        {
187
            // local raw iterators are valid locally only
188
            if (loc != hpx::find_here())
×
189
                continue;
×
190

191
            local_raw_iterator loc_end = traits::end(seg_it);
×
192
            for (local_raw_iterator lit = traits::begin(seg_it); lit != loc_end;
×
193
                 ++lit, ++count)
×
194
            {
195
            }
×
196
        }
×
197
    }
×
198
    HPX_TEST_EQ(seg_count, parts);
×
199

200
    seg_count = 0;
×
201
    for (hpx::id_type const& loc : hpx::find_all_localities())
×
202
    {
203
        std::uint32_t locality_id = hpx::naming::get_locality_id_from_id(loc);
×
204
        const_local_segment_iterator seg_cend = v.segment_cend(locality_id);
×
205
        for (const_local_segment_iterator seg_cit =
×
206
                 v.segment_cbegin(locality_id);
×
207
             seg_cit != seg_cend; ++seg_cit, ++seg_count)
×
208
        {
209
            // local raw iterators are valid locally only
210
            if (loc != hpx::find_here())
×
211
                continue;
×
212

213
            const_local_raw_iterator loc_cend = const_traits::end(seg_cit);
×
214
            for (const_local_raw_iterator lcit = const_traits::begin(seg_cit);
×
215
                 lcit != loc_cend; ++lcit, ++count)
×
216
            {
217
            }
×
218
        }
×
219
    }
×
220
    HPX_TEST_EQ(seg_count, parts);
×
221

222
    // test iterator composition
223
    if (size != 0)
×
224
    {
225
        segment_iterator seg_it = traits::segment(v.begin());
×
226
        local_iterator lit1 = traits::local(v.begin());
×
227
        local_iterator lit2 = traits::begin(seg_it);
×
228
        HPX_TEST(lit1 == lit2);
×
229

230
        iterator it = traits::compose(seg_it, lit1);
×
231
        HPX_TEST(it == v.begin());
×
232

233
        const_segment_iterator seg_cit = const_traits::segment(v.cbegin());
×
234
        const_local_iterator lcit1 = const_traits::local(v.cbegin());
×
235
        const_local_iterator lcit2 = const_traits::begin(seg_cit);
×
236
        HPX_TEST(lcit1 == lcit2);
×
237

238
        const_iterator cit = const_traits::compose(seg_cit, lcit1);
×
239
        HPX_TEST(cit == v.cbegin());
×
240
    }
×
241
}
×
242

243
template <typename T>
244
void trivial_test_without_policy(std::size_t size, char const* prefix)
×
245
{
246
    std::string prefix_(prefix);
×
247

248
    {
249
        // create empty vector
250
        hpx::partitioned_vector<T> v;
×
251

252
        test_global_iteration(v, 0, T());
×
253
        test_segmented_iteration(v, 0, 0);
×
254
    }
×
255

256
    {
257
        // create and connect to empty vector
258
        std::string empty(prefix_ + "empty");
×
259

260
        hpx::partitioned_vector<T> base;
×
261
        base.register_as(hpx::launch::sync, empty);
×
262

263
        hpx::partitioned_vector<T> v;
×
264
        v.connect_to(hpx::launch::sync, empty);
×
265

266
        test_global_iteration(v, 0, T());
×
267
        test_segmented_iteration(v, 0, 0);
×
268
    }
×
269

270
    {
271
        // create vector with initial size != 0
272
        hpx::partitioned_vector<T> v(size);
×
273

274
        test_global_iteration(v, size, T());
×
275
        test_segmented_iteration(v, size, 1);
×
276
    }
×
277

278
    {
279
        // create vector with initial size != 0
280
        std::string size_(prefix_ + "size");
×
281

282
        hpx::partitioned_vector<T> base(size);
×
283
        base.register_as(hpx::launch::sync, size_);
×
284

285
        hpx::partitioned_vector<T> v;
×
286
        v.connect_to(hpx::launch::sync, size_);
×
287

288
        test_global_iteration(v, size, T());
×
289
        test_segmented_iteration(v, size, 1);
×
290
    }
×
291

292
    {
293
        // create vector with initial size and values
294
        hpx::partitioned_vector<T> v(size, T(999));
×
295

296
        test_global_iteration(v, size, T(999));
×
297
        test_segmented_iteration(v, size, 1);
×
298
    }
×
299

300
    {
301
        // create vector with initial size and values
302
        std::string size_value(prefix_ + "size_value");
×
303

304
        hpx::partitioned_vector<T> base(size, T(999));
×
305
        base.register_as(hpx::launch::sync, size_value);
×
306

307
        hpx::partitioned_vector<T> v;
×
308
        v.connect_to(hpx::launch::sync, size_value);
×
309

310
        test_global_iteration(v, size, T(999));
×
311
        test_segmented_iteration(v, size, 1);
×
312
    }
×
313
}
×
314

315
template <typename T, typename DistPolicy>
316
void trivial_test_with_policy(std::size_t size, std::size_t parts,
×
317
    DistPolicy const& policy, char const* prefix)
318
{
319
    std::string prefix_(prefix);
×
320

321
    {
322
        hpx::partitioned_vector<T> v(size, policy);
×
323

324
        test_global_iteration(v, size, T(0));
×
325
        test_segmented_iteration(v, size, parts);
×
326
    }
×
327

328
    {
329
        std::string policy_(prefix_ + "policy");
×
330

331
        hpx::partitioned_vector<T> base(size, policy);
×
332
        base.register_as(hpx::launch::sync, policy_);
×
333

334
        hpx::partitioned_vector<T> v;
×
335
        v.connect_to(hpx::launch::sync, policy_);
×
336

337
        test_global_iteration(v, size, T(0));
×
338
        test_segmented_iteration(v, size, parts);
×
339
    }
×
340

341
    {
342
        hpx::partitioned_vector<T> v(size, T(999), policy);
×
343

344
        test_global_iteration(v, size, T(999));
×
345
        test_segmented_iteration(v, size, parts);
×
346
    }
×
347

348
    {
349
        std::string policy_value(prefix_ + "policy_value");
×
350

351
        hpx::partitioned_vector<T> base(size, T(999), policy);
×
352
        base.register_as(hpx::launch::sync, policy_value);
×
353

354
        hpx::partitioned_vector<T> v;
×
355
        v.connect_to(hpx::launch::sync, policy_value);
×
356

357
        test_global_iteration(v, size, T(999));
×
358
        test_segmented_iteration(v, size, parts);
×
359
    }
×
360
}
×
361

362
template <typename T>
363
void trivial_tests()
×
364
{
365
    std::size_t const length = 12;
×
366
    std::vector<hpx::id_type> localities = hpx::find_all_localities();
×
367

368
    trivial_test_without_policy<T>(length, "test1");
×
369

370
    trivial_test_with_policy<T>(length, 1, hpx::container_layout, "test1");
×
371
    trivial_test_with_policy<T>(length, 3, hpx::container_layout(3), "test2");
×
372
    trivial_test_with_policy<T>(
×
373
        length, 3, hpx::container_layout(3, localities), "test3");
×
374
    trivial_test_with_policy<T>(
×
375
        length, localities.size(), hpx::container_layout(localities), "test4");
×
376
}
×
377

378
int main()
×
379
{
380
    trivial_tests<double>();
×
381
    trivial_tests<int>();
×
382

383
    return 0;
×
384
}
385
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc