Mercurial > hg > Gears > GearsAgda
annotate src/parallel_execution/test/multiDimIterator_test.cbc @ 402:e958a409943c
Change iterator implement from oneDim to multiDim
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 01 Sep 2017 06:18:53 +0900 |
parents | src/parallel_execution/test/oneDimIterator_test.cbc@408b4aab7610 |
children | 83c9aeb1fe3e |
rev | line source |
---|---|
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <string.h> |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include <stdlib.h> |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include <unistd.h> |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 #include "../../context.h" |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 int cpu_num = 1; |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
401
diff
changeset
|
9 int length = 1; |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 int gpu_num = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 int CPU_ANY = -1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 int CPU_CUDA = -1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 void *start_taskManager(struct Context *context) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 return 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #ifdef USE_CUDAWorker |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #ifdef USE_CUDA_MAIN_THREAD |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 extern volatile int cuda_initialized; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #endif |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #endif |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 // loopCounter->tree = createRedBlackTree(context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 loopCounter->i = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 #ifdef USE_CUDAWorker |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 #ifdef USE_CUDA_MAIN_THREAD |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 while(! cuda_initialized) {}; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 #endif |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 #endif |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 goto meta(context, C_code1); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 __code initDataGears_stub(struct Context* context) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 struct TaskManager* taskManager = Gearef(context, TaskManager); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 taskManager->taskManager = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 #if (! defined(USE_CUDAWorker) || ! defined(USE_CUDA_MAIN_THREAD)) |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 struct LoopCounter* loopCounter = Gearef(context, LoopCounter); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 goto initDataGears(context, loopCounter, taskManager); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 #else |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 cuda_initialized = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 pthread_t thread; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 pthread_create(&thread, NULL, (void*)&start_taskManager, context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 while (taskManager->taskManager == 0); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 TaskManager *t = (TaskManager*)taskManager->taskManager; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 TaskManagerImpl *im = (TaskManagerImpl*)t->taskManager; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 struct Queue *q = (Queue *)im->workers[0]; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 createCUDAWorker(context,0,q, im); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 pthread_join(thread,0); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 exit(0); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 #endif |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 __code code1(struct Time* time) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 printf("cpus:\t\t%d\n", cpu_num); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 printf("gpus:\t\t%d\n", gpu_num); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 printf("length:\t\t%d\n", length); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 /* puts("queue"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 /* print_queue(context->data[ActiveQueue]->queue.first); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 /* puts("tree"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 /* print_tree(context->data[Tree]->tree.root); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 /* puts("result"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 time->time = (union Data*)createTimeImpl(context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 time->next = C_createTask1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 goto meta(context, time->time->Time.start); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 int i = loopCounter->i; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 if (i < length) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 loopCounter->i++; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 goto meta(context, C_createTask2); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 loopCounter->i = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 taskManager->next = C_exit_code; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 goto meta(context, taskManager->taskManager->TaskManager.shutdown); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
85 __code createTask2(struct TaskManager* taskManager) { |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
401
diff
changeset
|
86 par goto printIterator(iterate(2, 2, 2), exit); |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
87 goto createTask1(); |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 void init(int argc, char** argv) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 for (int i = 1; argv[i]; ++i) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 if (strcmp(argv[i], "-cpu") == 0) |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 cpu_num = (int)atoi(argv[i+1]); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 else if (strcmp(argv[i], "-l") == 0) |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 length = (int)atoi(argv[i+1]); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 else if (strcmp(argv[i], "-cuda") == 0) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 gpu_num = 1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 CPU_CUDA = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 int main(int argc, char** argv) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 init(argc, argv); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 struct Context* main_context = NEW(struct Context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 initContext(main_context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 main_context->next = C_initDataGears; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 goto start_code(main_context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 } |