-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainers.cpp
More file actions
103 lines (96 loc) · 3.14 KB
/
Copy pathcontainers.cpp
File metadata and controls
103 lines (96 loc) · 3.14 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
103
#include "containers.h"
/* ===================== MAIN ==================== */
int main(int argc, const char* argv[]){
struct arg_params args_parsed = arg_parser(argc, argv);
inputFile = args_parsed.INPUTFILE;
NUM_THREADS = args_parsed.NUM_THREADS;
algorithm = args_parsed.ALGORITHM;
test = args_parsed.TEST;
threads = static_cast<pthread_t*>(malloc(NUM_THREADS*sizeof(pthread_t)));
pthread_mutex_init(&SGL_stack_lock, NULL);
pthread_mutex_init(&SGL_queue_lock, NULL);
if (inputFile != "") {
// read in integers from input file, allocate vector size, and store values
fstream file(inputFile.c_str(), ios_base::in);
fstream infile(inputFile, ios_base::in);
while (getline(file, line)) s++;
test_vec.resize(s);
while (infile >> a) {
test_vec[b++] = a;
}
}
// execution start time
auto start_time = Clock::now();
// testing flag
if(test && algorithm == 0) {
runTests();
exit(0);
}
/* algorithm statement (from parser) is as follows:
* 1-sgl_stack, 2-sgl_queue, 3-treiber_stack, 4-ms_queue
* 5-baskets_queue, 6-elim_t_stack, 7-elim_sgl_stack */
switch (algorithm) {
// sgl_stack
case 1:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, SGL_stack, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// sgl_queue
case 2:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, SGL_queue, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// treiber_stack
case 3:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, treiber_stack, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// MS_queue
case 4:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, MS_queue, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// baskets_queue
case 5:
init_queue(bas_queue);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, baskets_queue, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// elim_sql_stack
case 6:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, elim_sgl_stack, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// elim_t_stack
case 7:
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, elim_t_stack, (void*)i);
for (size_t i = 0; i < NUM_THREADS; i++)
pthread_join(threads[i], NULL);
break;
// something didn't match up
default:
printf("An error occured in main argument switch\n");
exit(-1);
}
// execution end time
auto end_time = Clock::now();
// unsigned int 4,294,967,295, which is only 4.3 seconds
// unsigned long, plan on never running out (over 5 centuries)
unsigned long time_spent = chrono::duration_cast<chrono::nanoseconds>(end_time - start_time).count();
printf("\nTime elapsed is %lu nanoseconds\n", time_spent);
printf(" %f seconds\n", time_spent/1e9);
return 0;
}