-
-
Notifications
You must be signed in to change notification settings - Fork 542
Expand file tree
/
Copy pathsort_by_key_demo.cpp
More file actions
55 lines (46 loc) · 1.69 KB
/
sort_by_key_demo.cpp
File metadata and controls
55 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2016 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <hpx/init.hpp>
#include <cstddef>
#include <iostream>
#include <vector>
///////////////////////////////////////////////////////////////////////////////
void print_sequence(
std::vector<int> const& keys, std::vector<char> const& values)
{
for (std::size_t i = 0; i != keys.size(); ++i)
{
std::cout << "[" << keys[i] << ", " << values[i] << "]";
if (i != keys.size() - 1)
std::cout << ", ";
}
std::cout << std::endl;
}
int hpx_main()
{
{
std::vector<int> keys = {1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8,
5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7};
std::vector<char> values = {'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c',
'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd',
'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e',
'f'};
std::cout << "unsorted sequence: {";
print_sequence(keys, values);
hpx::experimental::sort_by_key(
hpx::execution::par, keys.begin(), keys.end(), values.begin());
std::cout << "sorted sequence: {";
print_sequence(keys, values);
}
return hpx::local::finalize();
}
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
return hpx::local::init(hpx_main, argc, argv); // Initialize and run HPX
}