-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
231 lines (160 loc) · 3.54 KB
/
test.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <cilk/cilk.h>
#include <iostream>
#include <cstdio>
#include <cstdint>
// <>
void* mem = nullptr;
int test(int x) {
return printf("Value: %d\n", x);
}
void* __attribute__((noinline)) testAlloc(size_t size) {
return malloc(size);
}
void testFree(void* mem) {
return free(mem);
}
__attribute__((noinline)) int testSpawn(int x) {
if (x == 0)
return 1;
void* y = cilk_spawn testAlloc((size_t)x);
// int k = printf("Testing subspawn\n");
int k = 2;
mem = malloc(200);
cilk_sync;
free(mem);
cilk_spawn testFree(y);
return k;
}
__attribute__((noinline)) uint64_t fibAlloc(uint64_t n) {
// std::cout << "fib(" << n << ")\n";
if (n < 2)
{
return n;
}
size_t x, y;
x = cilk_spawn fibAlloc(n - 1);
// test((int)n);
mem = malloc(n);
y = fibAlloc(n - 2);
cilk_sync;
mem = malloc(100);
return x + y;
}
__attribute__((noinline)) uint64_t fib(uint64_t n) {
if (n < 2)
return n;
size_t x, y;
x = cilk_spawn fib(n - 1);
y = fib(n - 2);
cilk_sync;
return x + y;
}
__attribute__((noinline)) uint64_t rec(uint64_t n) {
// std::cout << "rec(" << n << ")\n";
if (n < 2)
{
return n;
}
size_t x, y;
if (n == 2)
x = 0;
else
x = rec(0);
// test((int)n);
mem = malloc(n);
y = cilk_spawn rec(n - 1);
cilk_sync;
mem = malloc(100);
// std::cout << "Finished rec(" << n << ")\n";
return x + y;
}
__attribute__((noinline)) uint64_t testInterleave(uint64_t n) {
mem = malloc(10000);
free(mem);
mem = malloc(10000);
free(mem);
mem = malloc(50000);
free(mem);
return 0;
}
__attribute__((noinline)) uint64_t testFunction(uint64_t n) {
mem = malloc(n * 100);
if (mem == nullptr)
{
mem = malloc(500);
}
free(mem);
mem = malloc(n * 10);
return 0;
}
__attribute__((noinline)) uint64_t stress(uint64_t n) {
if (n == 0)
{
mem = malloc(50);
free(mem);
return 1;
}
void* nowmem = nullptr;
nowmem = malloc(n * 100);
mem = nowmem;
cilk_spawn stress(n - 1);
auto x = stress(n - 1);
free(nowmem);
return x;
}
uint64_t x = 0;
int main(int argc, char** argv) {
uint64_t n = 10;
uint64_t k = 5;
uint64_t o = 1;
if (argc > 1)
{
n = std::atoi(argv[1]);
}
if (argc > 2)
{
k = std::atoi(argv[2]);
}
if (argc > 3)
{
o = std::atoi(argv[3]);
}
// uint64_t x = fib(3);
//if (x == 1)
// cilk_spawn test(100);
// uint64_t x = cilk_spawn test(10);
// mem = aligned_alloc(64,200);
// uint64_t x = cilk_spawn fib(2);
// uint64_t y = testSpawn(100);
/* for(size_t i = 0; i < 2; ++i)
{
mem = cilk_spawn testAlloc(10);
} */
for (size_t j = 0; j < o; ++j)
{
for (size_t i = 0; i < k; ++i)
{
// x = cilk_spawn stress(n);
// x = fib(n);
//x = fibAlloc(n);
x = stress(n);
}
//#pragma cilk grainsize 1
// cilk_for(size_t i = 0; i < k; ++i) {
// x = testFunction(n); }
}
cilk_sync;
/*
for (size_t i = 0; i < k; ++i)
{
uint64_t x = cilk_spawn testFunction(n);
}
cilk_sync;
*/
// mem = malloc(123);
// cilk_sync;
// uint64_t x = cilk_spawn fib(3);
// mem = malloc(500);
// printf("Returned %lu and %lu\n", x, y);
return 0;
}