1/*
2 Copyright (c) 2005-2019 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "harness_assert.h"
18#include "test_partitioner_whitebox.h"
19
20using uniform_iterations_distribution::ParallelTestBody;
21
22template<typename Partitioner>
23class ParallelBody: public ParallelTestBody {
24public:
25 ParallelBody(size_t parallel_group_thread_starting_index)
26 : ParallelTestBody(parallel_group_thread_starting_index) { }
27
28 void operator()(size_t relative_thread_index) const {
29 use_case_settings_t settings = {
30 m_parallel_group_thread_starting_index + relative_thread_index, // thread_num
31 0, // factors_array_len
32 0, // range_begin
33 false, // provide_feedback (disabled)
34 true, // ensure_non_empty_size
35 0, // above_threads_size_tolerance
36 0, // below_threads_size_tolerance
37 0, // between_min_max_ranges_tolerance
38 &ParallelTestBody::uniform_distribution_checker // checker function for a particular test case
39 };
40 g_threadNums.local() = settings.thread_num;
41 using namespace test_partitioner_utils::TestRanges;
42 {
43 size_t factors[] = { 1, 2, 3, 4, 5, 7, 9, 13, 27, 29, 30, 31, 32 };
44 settings.factors_array_len = sizeof(factors) / sizeof(factors[0]);
45
46 settings.between_min_max_ranges_tolerance = 0; // it should be equal to zero for blocked_range
47 test<BlockedRange, Partitioner>(settings, factors);
48
49 settings.checker = &ParallelTestBody::nonuniform_distribution_checker;
50 test<InvertedProportionRange, Partitioner>(settings, factors);
51 test<RoundedDownRange, Partitioner>(settings, factors);
52 test<RoundedUpRange, Partitioner>(settings, factors);
53
54 test<Range1_2, Partitioner>(settings, factors);
55 test<Range1_999, Partitioner>(settings, factors);
56 test<Range999_1, Partitioner>(settings, factors);
57 }
58
59 {
60 // iterations might not be distributed uniformly
61 float factors[] = { 1.2f, 2.5f, 3.7f, 4.2f, 5.1f, 8.9f, 27.8f };
62 settings.factors_array_len = sizeof(factors) / sizeof(factors[0]);
63
64 settings.between_min_max_ranges_tolerance = 1; // it should be equal to one for blocked_range
65 settings.checker = &ParallelTestBody::uniform_distribution_checker;
66 test<BlockedRange, Partitioner>(settings, factors);
67
68 settings.checker = &ParallelTestBody::nonuniform_distribution_checker;
69 test<InvertedProportionRange, Partitioner>(settings, factors);
70 test<RoundedDownRange, Partitioner>(settings, factors);
71 test<RoundedUpRange, Partitioner>(settings, factors);
72
73 test<Range1_2, Partitioner>(settings, factors);
74 test<Range1_999, Partitioner>(settings, factors);
75 test<Range999_1, Partitioner>(settings, factors);
76 }
77
78 {
79 // iterations might not be distributed uniformly
80 size_t factors[] = { 1, 2, 3, 4, 5, 7, 9, 11, 13, 27, 29, 30, 31, 32 };
81 settings.factors_array_len = sizeof(factors) / sizeof(factors[0]);
82
83 settings.checker = &ParallelTestBody::uniform_distribution_checker;
84 test<BlockedRange, Partitioner>(settings, factors, &shifted_left_range_size_generator);
85 test<BlockedRange, Partitioner>(settings, factors, &shifted_right_range_size_generator);
86
87 settings.checker = &ParallelTestBody::nonuniform_distribution_checker;
88 test<InvertedProportionRange, Partitioner>(settings, factors, &shifted_left_range_size_generator);
89 test<InvertedProportionRange, Partitioner>(settings, factors, &shifted_right_range_size_generator);
90
91 test<RoundedDownRange, Partitioner>(settings, factors, &shifted_left_range_size_generator);
92 test<RoundedDownRange, Partitioner>(settings, factors, &shifted_right_range_size_generator);
93
94 test<RoundedUpRange, Partitioner>(settings, factors, &shifted_left_range_size_generator);
95 test<RoundedUpRange, Partitioner>(settings, factors, &shifted_right_range_size_generator);
96
97 test<Range1_2, Partitioner>(settings, factors, &shifted_left_range_size_generator);
98 test<Range1_2, Partitioner>(settings, factors, &shifted_right_range_size_generator);
99
100 test<Range1_999, Partitioner>(settings, factors, &shifted_left_range_size_generator);
101 test<Range1_999, Partitioner>(settings, factors, &shifted_right_range_size_generator);
102
103 test<Range999_1, Partitioner>(settings, factors, &shifted_left_range_size_generator);
104 test<Range999_1, Partitioner>(settings, factors, &shifted_right_range_size_generator);
105 }
106
107 {
108 settings.factors_array_len = 1;
109 settings.between_min_max_ranges_tolerance = 1; // since range iterations are not divided without remainder
110 settings.checker = &ParallelTestBody::uniform_distribution_checker;
111 test<ExactSplitRange, Partitioner, size_t>(settings, NULL, &max_range_size_generator);
112 settings.range_begin = size_t(-1) - 10000;
113 test<ExactSplitRange, Partitioner, size_t>(settings, NULL, &max_range_size_generator);
114 }
115
116 {
117 settings.range_begin = 0;
118 settings.factors_array_len = 2 * unsigned(settings.thread_num);
119 settings.checker = &ParallelTestBody::nonuniform_distribution_checker;
120
121 test<RoundedUpRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
122 test<RoundedDownRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
123
124 test<InvertedProportionRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
125 test<Range1_2, Partitioner, size_t>(settings, NULL, &simple_size_generator);
126 test<Range1_999, Partitioner, size_t>(settings, NULL, &simple_size_generator);
127 test<Range999_1, Partitioner, size_t>(settings, NULL, &simple_size_generator);
128
129 settings.ensure_non_empty_size = false;
130 test<RoundedUpRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
131 test<RoundedDownRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
132
133 test<InvertedProportionRange, Partitioner, size_t>(settings, NULL, &simple_size_generator);
134 test<Range1_2, Partitioner, size_t>(settings, NULL, &simple_size_generator);
135 test<Range1_999, Partitioner, size_t>(settings, NULL, &simple_size_generator);
136 test<Range999_1, Partitioner, size_t>(settings, NULL, &simple_size_generator);
137 }
138 }
139};
140
141int TestMain() {
142 uniform_iterations_distribution::test<ParallelBody <tbb::affinity_partitioner> >();
143 uniform_iterations_distribution::test<ParallelBody <tbb::static_partitioner> >();
144 uniform_iterations_distribution::test_task_affinity<tbb::affinity_partitioner>();
145 uniform_iterations_distribution::test_task_affinity<tbb::static_partitioner>();
146 return Harness::Done;
147}
148