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

STEllAR-GROUP / hpx / #865

13 Jan 2023 11:46PM UTC coverage: 86.431% (+0.08%) from 86.354%
#865

push

StellarBot
Merge #6132

6132: Fixing to_non_par() for parallel simd policies r=hkaiser a=hkaiser



Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

64 of 64 new or added lines in 3 files covered. (100.0%)

174506 of 201901 relevant lines covered (86.43%)

1999640.87 hits per line

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

7.14
/libs/full/parcelset/tests/unit/set_parcel_write_handler.cpp
1
//  Copyright (c) 2015-2021 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.hpp>
10
#include <hpx/hpx_main.hpp>
11
#include <hpx/modules/testing.hpp>
12

13
#include <atomic>
14
#include <cstddef>
15
#include <memory>
16
#include <string>
17
#include <system_error>
18
#include <utility>
19
#include <vector>
20

21
///////////////////////////////////////////////////////////////////////////////
22
void test(hpx::id_type const& id)
2✔
23
{
24
    hpx::trigger_lco_event(id);
2✔
25
}
2✔
26
HPX_PLAIN_ACTION(test)    // defines test_action
5✔
27

28
///////////////////////////////////////////////////////////////////////////////
29
std::atomic<std::size_t> write_handler_called(0);
30

31
bool is_test_action(hpx::parcelset::parcel const& p)
×
32
{
33
#if defined(HPX_HAVE_NETWORKING)
34
    return std::string(p.get_action_name()) == std::string("test_action");
×
35
#else
36
    return true;
37
#endif
38
}
×
39

40
void write_handler(std::error_code const&, hpx::parcelset::parcel const& p)
×
41
{
42
    if (is_test_action(p))
×
43
        ++write_handler_called;
×
44
}
×
45

46
// working around non-copy-ability of packaged_task
47
struct indirect_packaged_task
×
48
{
49
    using packaged_task_type = hpx::packaged_task<void()>;
50

51
    indirect_packaged_task()
×
52
      : pt(std::make_shared<packaged_task_type>([]() {}))
×
53
    {
54
    }
×
55

56
    auto get_future()
×
57
    {
58
        return pt->get_future();
×
59
    }
60

61
    template <typename... Ts>
62
    void operator()(Ts&&...)
×
63
    {
64
        // This needs to be run on a HPX thread
65
        hpx::post(std::move(*pt));
×
66
    }
×
67

68
    std::shared_ptr<packaged_task_type> pt;
69
};
70

71
///////////////////////////////////////////////////////////////////////////////
72
int main()
×
73
{
74
    hpx::parcel_write_handler_type wh(&write_handler);
×
75

76
    // test that handler is called for every parcel
77
    hpx::parcel_write_handler_type f1 = hpx::set_parcel_write_handler(wh);
×
78
    HPX_TEST(!f1.empty());
×
79

80
    std::vector<hpx::id_type> localities = hpx::find_remote_localities();
×
81

82
    {
83
        std::vector<hpx::future<void>> wait_for;
×
84
        for (hpx::id_type const& id : localities)
×
85
        {
86
            hpx::distributed::promise<void> p_remote;
×
87
            auto f_remote = p_remote.get_future();
×
88

89
            indirect_packaged_task p_local;
×
90
            auto f_local = p_local.get_future();
×
91

92
            hpx::post_cb<test_action>(id, p_local, p_remote.get_id());
×
93

94
            wait_for.push_back(std::move(f_remote));
×
95
            wait_for.push_back(std::move(f_local));
×
96
        }
×
97

98
        hpx::wait_all(wait_for);
×
99
        HPX_TEST_EQ(write_handler_called, localities.size());
×
100
    }
×
101

102
    // test that handler is not called anymore
103
    write_handler_called.store(0);
×
104
    hpx::parcel_write_handler_type f2 = hpx::set_parcel_write_handler(f1);
×
105

106
    {
107
        std::vector<hpx::future<void>> wait_for;
×
108
        for (hpx::id_type const& id : localities)
×
109
        {
110
            hpx::distributed::promise<void> p_remote;
×
111
            auto f_remote = p_remote.get_future();
×
112

113
            indirect_packaged_task p_local;
×
114
            auto f_local = p_local.get_future();
×
115

116
            hpx::post_cb<test_action>(id, p_local, p_remote.get_id());
×
117

118
            wait_for.push_back(std::move(f_remote));
×
119
            wait_for.push_back(std::move(f_local));
×
120
        }
×
121

122
        hpx::wait_all(wait_for);
×
123
        HPX_TEST_EQ(write_handler_called, std::size_t(0));
×
124
    }
×
125

126
    HPX_TEST(f2.target<hpx::parcel_write_handler_type>() ==
×
127
        wh.target<hpx::parcel_write_handler_type>());
128

129
    return hpx::util::report_errors();
×
130
}
×
131
#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