-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvector_example.cpp
100 lines (67 loc) · 2.44 KB
/
vector_example.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-FileCopyrightText: Intel Corporation
//
// SPDX-License-Identifier: BSD-3-Clause
#include <dr/shp.hpp>
#include <fmt/ranges.h>
int main(int argc, char **argv) {
printf("Creating NUMA devices...\n");
dr::shp::init(sycl::default_selector_v);
for (auto &device : dr::shp::devices()) {
std::cout << " Device: " << device.get_info<sycl::info::device::name>()
<< "\n";
}
fmt::print("First check...\n");
dr::shp::check_queues();
fmt::print("Initializing distributed vector...\n");
dr::shp::distributed_vector<int, dr::shp::device_allocator<int>> v(100);
fmt::print("Second check...\n");
dr::shp::check_queues();
fmt::print("For each...\n");
dr::shp::for_each(dr::shp::par_unseq, dr::shp::enumerate(v),
[](auto &&tuple) {
auto &&[idx, value] = tuple;
value = idx;
});
dr::shp::for_each(dr::shp::par_unseq, v,
[](auto &&value) { value = value + 2; });
fmt::print("Third check...\n");
dr::shp::check_queues();
fmt::print("Reduce...\n");
std::size_t sum = dr::shp::reduce(dr::shp::par_unseq, v, int(0), std::plus{});
dr::shp::print_range(v);
std::cout << "Sum: " << sum << std::endl;
std::vector<int> local_vec(v.size());
std::iota(local_vec.begin(), local_vec.end(), 0);
fmt::print("Fourth check...\n");
dr::shp::check_queues();
dr::shp::print_range(local_vec, "local vec");
fmt::print("Fourth Two check...\n");
dr::shp::check_queues();
dr::shp::copy(local_vec.begin(), local_vec.end(), v.begin());
fmt::print("Fourth Three check...\n");
dr::shp::check_queues();
dr::shp::print_range(v, "vec after copy");
dr::shp::for_each(dr::shp::par_unseq, v,
[](auto &&value) { value = value + 2; });
dr::shp::print_range(v, "vec after update");
fmt::print("Fourth One check...\n");
dr::shp::check_queues();
dr::shp::copy(v.begin(), v.end(), local_vec.begin());
dr::shp::print_range(local_vec, "local vec after copy");
v.resize(200);
dr::shp::print_range(v, "resized to 200");
v.resize(50);
dr::shp::print_range(v, "resized to 50");
fmt::print("Fifth check...\n");
dr::shp::check_queues();
fmt::print("Getting ready to finalize...\n");
fflush(stdout);
fmt::print("Check queues...\n");
dr::shp::check_queues();
fmt::print("Finalizing...\n");
fflush(stdout);
dr::shp::finalize();
fmt::print("Exiting...\n");
fflush(stdout);
return 0;
}