Mercurial > hg > GearsTemplate
annotate src/parallel_execution/test/multiDimIterator_test.cbc @ 468:ac244346c85d
Change used interface syntax from #include to #interface
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Dec 2017 18:10:56 +0900 |
parents | 831b7f6fd687 |
children | 3881b91f5820 |
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> |
468
ac244346c85d
Change used interface syntax from #include to #interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
466
diff
changeset
|
5 #interface "Iterator.h" |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 #include "../../context.h" |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 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
|
10 int length = 1; |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 int gpu_num = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 int CPU_ANY = -1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 int CPU_CUDA = -1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 // loopCounter->tree = createRedBlackTree(context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 loopCounter->i = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 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
|
19 goto meta(context, C_code1); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 __code initDataGears_stub(struct Context* context) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 struct TaskManager* taskManager = Gearef(context, TaskManager); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 taskManager->taskManager = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 struct LoopCounter* loopCounter = Gearef(context, LoopCounter); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 goto initDataGears(context, loopCounter, taskManager); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 |
468
ac244346c85d
Change used interface syntax from #include to #interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
466
diff
changeset
|
29 __code code1(struct LoopCounter* loopCounter) { |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 printf("cpus:\t\t%d\n", cpu_num); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 printf("gpus:\t\t%d\n", gpu_num); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 printf("length:\t\t%d\n", length); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 /* puts("queue"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 /* print_queue(context->data[ActiveQueue]->queue.first); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 /* puts("tree"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 /* print_tree(context->data[Tree]->tree.root); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 /* puts("result"); */ |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 |
464
7d67c9cf09ee
Rename from Time interface to Timer interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
457
diff
changeset
|
39 goto createTask1(); |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 |
464
7d67c9cf09ee
Rename from Time interface to Timer interface
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
457
diff
changeset
|
42 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 int i = loopCounter->i; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 if (i < length) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 loopCounter->i++; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 goto meta(context, C_createTask2); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 loopCounter->i = 0; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 taskManager->next = C_exit_code; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 goto meta(context, taskManager->taskManager->TaskManager.shutdown); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
379
diff
changeset
|
55 __code createTask2(struct TaskManager* taskManager) { |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
56 par goto printIterator(iterate(2), exit); |
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
57 par goto printIterator(iterate(2, 2), exit); |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
401
diff
changeset
|
58 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
|
59 goto createTask1(); |
376
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 void init(int argc, char** argv) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 for (int i = 1; argv[i]; ++i) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 if (strcmp(argv[i], "-cpu") == 0) |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 cpu_num = (int)atoi(argv[i+1]); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 else if (strcmp(argv[i], "-l") == 0) |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 length = (int)atoi(argv[i+1]); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 else if (strcmp(argv[i], "-cuda") == 0) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 gpu_num = 1; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 CPU_CUDA = 0; |
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 } |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |
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 int main(int argc, char** argv) { |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 init(argc, argv); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 struct Context* main_context = NEW(struct Context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 initContext(main_context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 main_context->next = C_initDataGears; |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 goto start_code(main_context); |
b46f38645587
Run oneDimIterator_test
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 } |