-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathsort.cpp
More file actions
102 lines (77 loc) · 2.65 KB
/
Copy pathsort.cpp
File metadata and controls
102 lines (77 loc) · 2.65 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
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
101
102
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//
#include "xhp-tests.hpp"
// TODO: add sort tests with ISHMEM, currently doesn't compile
using T = int;
using DV = xhp::distributed_vector<T>;
using LV = std::vector<T>;
void test_sort(LV v, auto func) {
auto size = v.size();
DV d_v(size);
for (std::size_t idx = 0; idx < size; idx++) {
d_v[idx] = v[idx];
}
barrier();
std::sort(v.begin(), v.end(), func);
xhp::sort(d_v, func);
EXPECT_TRUE(equal(v, d_v));
}
void test_sort2s(LV v) {
test_sort(v, std::less<T>());
test_sort(v, std::greater<T>());
}
void test_sort_randomvec(std::size_t size, std::size_t bound = 100) {
LV l_v = generate_random<T>(size, bound);
test_sort2s(l_v);
}
TEST(Sort, Random_1) { test_sort_randomvec(1); }
TEST(Sort, Random_CommSize_m1) { test_sort_randomvec(comm_size - 1); }
TEST(Sort, Random_CommSize_m1_sq) {
test_sort_randomvec((comm_size - 1) * (comm_size - 1));
}
TEST(Sort, Random_dist_small) { test_sort_randomvec(17); }
TEST(Sort, Random_dist_med) { test_sort_randomvec(123); }
TEST(Sort, AllSame) {
test_sort2s({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
}
TEST(Sort, AllSameButOneMid) {
test_sort2s({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1});
}
TEST(Sort, AllSameButOneEnd) {
test_sort2s({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9});
}
TEST(Sort, AllSameButOneSmaller) {
test_sort2s({5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5});
}
TEST(Sort, AllSameButOneBigger) {
test_sort2s({5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5});
}
TEST(Sort, AllSameButOneSBeg) {
test_sort2s({5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5});
}
TEST(Sort, AllSameButOneBBeg) {
test_sort2s({5, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5});
}
TEST(Sort, MostSame) { test_sort2s({1, 9, 2, 2, 2, 2, 2, 2, 2, 2, 9, 1}); }
TEST(Sort, Pyramid) { test_sort2s({1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}); }
TEST(Sort, RevPyramid) { test_sort2s({6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6}); }
TEST(Sort, Wave) { test_sort2s({1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1}); }
TEST(Sort, LongSorted) {
LV v(100000);
std::iota(v.begin(), v.end(), 1);
test_sort2s(v);
rng::reverse(v);
test_sort2s(v);
}