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
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "../../../context.h"
int cpu_num = 1;
int length = 102400;
int split = 8;
int* array_ptr;
int gpu_num = 0;
int CPU_ANY = -1;
int CPU_CUDA = -1;
__code initDataGears(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
// loopCounter->tree = createRedBlackTree(context);
loopCounter->i = 0;
taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
goto meta(context, C_code1);
}
__code initDataGears_stub(struct Context* context) {
LoopCounter* loopCounter = Gearef(context, LoopCounter);
TaskManager* taskManager = Gearef(context, TaskManager);
goto initDataGears(context, loopCounter, taskManager);
}
__code code1(struct Context *context,struct LoopCounter* loopCounter) {
printf("cpus:\t\t%d\n", cpu_num);
printf("gpus:\t\t%d\n", gpu_num);
printf("length:\t\t%d\n", length);
printf("length/task:\t%d\n", length/split);
/* puts("queue"); */
/* print_queue(context->data[ActiveQueue]->queue.first); */
/* puts("tree"); */
/* print_tree(context->data[Tree]->tree.root); */
/* puts("result"); */
goto meta(context, C_createTask1);
}
__code code1_stub(struct Context* context) {
LoopCounter* loopCounter = Gearef(context, LoopCounter);
goto code1(context, loopCounter);
}
__code createTask1(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
Array* array1 = &ALLOCATE(context, Array)->Array;
Array* array2 = &ALLOCATE(context, Array)->Array;
Timer* timer = createTimerImpl(context);
struct Element* element;
context->task = NEW(struct Context);
initContext(context->task);
context->task->next = C_createArray;
context->task->idgCount = 0;
context->task->idg = context->task->dataNum;
context->task->maxIdg = context->task->idg + 0;
context->task->odg = context->task->maxIdg;
context->task->maxOdg = context->task->odg + 2;
GET_META(array1)->wait = createSynchronizedQueue(context);
GET_META(timer)->wait = createSynchronizedQueue(context);
context->task->data[context->task->odg+0] = (union Data*)array1;
context->task->data[context->task->odg+1] = (union Data*)timer;
element = &ALLOCATE(context, Element)->Element;
element->data = (union Data*)context->task;
element->next = context->taskList;
context->taskList = element;
context->task = NEW(struct Context);
initContext(context->task);
context->task->next = C_twice;
context->task->idgCount = 1;
context->task->idg = context->task->dataNum;
context->task->maxIdg = context->task->idg + 1;
context->task->odg = context->task->maxIdg;
context->task->maxOdg = context->task->odg + 1;
context->task->iterate = 0;
context->task->iterator = createMultiDimIterator(context, split, 1, 1);
GET_META(array1)->wait = createSynchronizedQueue(context);
GET_META(array2)->wait = createSynchronizedQueue(context);
context->task->data[context->task->idg+0] = (union Data*)array1;
context->task->data[context->task->odg+0] = (union Data*)array2;
element = &ALLOCATE(context, Element)->Element;
element->data = (union Data*)context->task;
element->next = context->taskList;
context->taskList = element;
context->task = NEW(struct Context);
initContext(context->task);
context->task->next = C_printArray;
context->task->idgCount = 2;
context->task->idg = context->task->dataNum;
context->task->maxIdg = context->task->idg + 2;
context->task->odg = context->task->maxIdg;
context->task->maxOdg = context->task->odg + 0;
GET_META(array2)->wait = createSynchronizedQueue(context);
GET_META(timer)->wait = createSynchronizedQueue(context);
context->task->data[context->task->idg+0] = (union Data*)array2;
context->task->data[context->task->idg+1] = (union Data*)timer;
element = &ALLOCATE(context, Element)->Element;
element->data = (union Data*)context->task;
element->next = context->taskList;
context->taskList = element;
Gearef(context, TaskManager)->taskList = context->taskList;
Gearef(context, TaskManager)->next1 = C_code2;
goto parGotoMeta(context, C_code2);
}
__code createTask1_stub(struct Context* context) {
LoopCounter* loopCounter = Gearef(context, LoopCounter);
TaskManager* taskManager = Gearef(context, TaskManager);
goto createTask1(context, loopCounter, taskManager);
}
__code code2(struct Context *context,struct TaskManager* taskManager) {
Gearef(context, TaskManager)->taskManager = (union Data*) taskManager;
Gearef(context, TaskManager)->next = C_exit_code;
goto meta(context, taskManager->shutdown);
}
__code code2_stub(struct Context* context) {
goto code2(context, &Gearef(context, TaskManager)->taskManager->TaskManager);
}
void init(int argc, char** argv) {
for (int i = 1; argv[i]; ++i) {
if (strcmp(argv[i], "-cpu") == 0)
cpu_num = (int)atoi(argv[i+1]);
else if (strcmp(argv[i], "-l") == 0)
length = (int)atoi(argv[i+1]);
else if (strcmp(argv[i], "-s") == 0)
split = (int)atoi(argv[i+1]);
else if (strcmp(argv[i], "-cuda") == 0) {
gpu_num = 1;
CPU_CUDA = 0;
}
}
}
int main(int argc, char** argv) {
init(argc, argv);
struct Context* main_context = NEW(struct Context);
initContext(main_context);
main_context->next = C_initDataGears;
goto start_code(main_context);
}
|