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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

0.0
/examples/random_mem_access/random_mem_access_client.cpp
1
//  Copyright (c) 2007-2015 Hartmut Kaiser
2
//  Copyright (c) 2011 Matt Anderson
3
//  Copyright (c) 2011 Bryce Lelbach
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
#include <hpx/config.hpp>
10
#if !defined(HPX_COMPUTE_DEVICE_CODE)
11
#include <hpx/hpx.hpp>
12
#include <hpx/hpx_init.hpp>
13

14
#include <cstddef>
15
#include <ctime>
16
#include <random>
17
#include <vector>
18

19
#include <hpx/modules/program_options.hpp>
20

21
#include "random_mem_access/random_mem_access.hpp"
22

23
///////////////////////////////////////////////////////////////////////////////
24
int hpx_main(hpx::program_options::variables_map& vm)
×
25
{
26
    std::size_t array_size = 0;
×
27
    std::size_t iterations = 0;
28

29
    if (vm.count("array-size"))
×
30
        array_size = vm["array-size"].as<std::size_t>();
×
31

32
    if (vm.count("iterations"))
×
33
        iterations = vm["iterations"].as<std::size_t>();
×
34

35
    {
36
        std::vector<hpx::components::random_mem_access> accu =
37
            hpx::new_<hpx::components::random_mem_access[]>(
×
38
                hpx::default_layout(hpx::find_all_localities()), array_size)
×
39
                .get();
×
40

41
        // initialize the array
42
        for (std::size_t i = 0; i < array_size; i++)
×
43
        {
44
            accu[i].init(i);
×
45
        }
46

47
        auto seed = std::random_device{}();
×
48
        std::mt19937 gen(seed);
×
49

50
        std::vector<hpx::future<void>> barrier;
×
51
        for (std::size_t i = 0; i < iterations; i++)
×
52
        {
53
            std::uniform_int_distribution<> dis(
54
                0, static_cast<int>(array_size - 1));
×
55
            std::size_t rn = dis(gen);
×
56
            //std::cout << " Random element access: " << rn << std::endl;
57
            barrier.push_back(accu[rn].add_async());
×
58
        }
59

60
        hpx::wait_all(barrier);
61

62
        std::vector<hpx::future<void>> barrier2;
×
63
        for (std::size_t i = 0; i < array_size; i++)
×
64
        {
65
            barrier2.push_back(accu[i].print_async());
×
66
        }
67

68
        hpx::wait_all(barrier2);
69
    }
×
70

71
    return hpx::finalize();
×
72
}
73

74
///////////////////////////////////////////////////////////////////////////////
75
int main(int argc, char* argv[])
×
76
{
77
    using hpx::program_options::value;
78

79
    // Configure application-specific options
80
    hpx::program_options::options_description desc_commandline(
81
        "Usage: " HPX_APPLICATION_STRING " [options]");
×
82

83
    desc_commandline.add_options()("array-size",
×
84
        value<std::size_t>()->default_value(8), "the size of the array")(
×
85
        "iterations", value<std::size_t>()->default_value(16),
×
86
        "the number of lookups to perform");
87
    // Initialize and run HPX
88
    hpx::init_params init_args;
×
89
    init_args.desc_cmdline = desc_commandline;
×
90

91
    return hpx::init(argc, argv, init_args);
×
92
}
×
93

94
#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