-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (61 loc) · 2.19 KB
/
main.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
#include "func.h"
int main(int argc, char* argv[]) {
time_t timer;
int length = 8;
vector<int> values(length);
const auto processor_count = std::thread::hardware_concurrency();
vector<int> number_threads;
if (processor_count == 8) {
number_threads = {1,2,4,8,16};
}
else if (processor_count == 4) {
number_threads = {1,2,4,8};
}
else {
number_threads = { 1,2,4 };
}
number_threads = { 8 };
fillVector(values);
/*vector<int> values1(values);
cout << "Simple Bubble Sort\n";
//printVector(values1);
timer = clock();
bubbleSort(values1);
cout << "exuction time:" << (double)(clock() - timer) / CLOCKS_PER_SEC << endl;
cout << (check(values1) == 0 ? "false" : "true") << endl;
//printVector(values1);
(values1);
cout << "\nOdd Even Bubble Sort\n";
vector<int> values2(values);
//printVector(values2);
oddEvenBubbleSort(values2);
cout << "exuction time:" << (double)(clock() - timer) / CLOCKS_PER_SEC << endl;
cout << (check(values2) == 0 ? "false" : "true") << endl;
//printVector(values2);*/
cout << "\nParallel Odd Even Bubble Sort\n";
vector<int> values3;
timer = clock();
for (int i = 0; i < number_threads.size(); i++) {
if (length >= number_threads[i]) {
cout << "NUMBER THREADS = " << number_threads[i] << endl;
vector<thread> threads;
my_barrier barrier(number_threads[i]);
vector<int> values3(values);
printVector(values3);
timer = clock();
for (int j = 0; j < number_threads[i]; j++) {
threads.push_back(thread(parallelOddEvenBubbleSort, ref(values3), ref(barrier), number_threads[i], j));
}
for (auto& th : threads)
th.join();
//bubbleSort(values3);
printVector(values3);
//cout << (check(values3) == 0 ? "false" : "true") << endl;
cout << "exuction time:" << (double)(clock() - timer) / CLOCKS_PER_SEC << endl;
cout << (check(values3) == 0 ? "false" : "true") << endl;
//printVector(values3);
}
}
system("PAUSE");
return 0;
}