annotate src/parallel_execution/examples/boundedBuffer/main.cbc @ 493:82f0c49750f1

Add codeGear for boundedBuffer example
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Sun, 31 Dec 2017 01:36:18 +0900
parents
children d8b2036c6942
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
493
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdlib.h>
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <unistd.h>
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <assert.h>
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "../../../context.h"
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #interface "TaskManager.h"
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 int cpu_num = 1;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 int length = 100;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 int queue_size = 10;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 int gpu_num = 0;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 int CPU_ANY = -1;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 int CPU_CUDA = -1;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 void *start_taskManager(struct Context *context) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager));
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 return 0;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 // loopCounter->tree = createRedBlackTree(context);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 loopCounter->i = 0;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 goto meta(context, C_code1);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 __code initDataGears_stub(struct Context* context) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 struct TaskManager* taskManager = Gearef(context, TaskManager);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 taskManager->taskManager = 0;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 struct LoopCounter* loopCounter = Gearef(context, LoopCounter);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 goto initDataGears(context, loopCounter, taskManager);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 __code code1(struct Timer* timer) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 printf("cpus:\t\t%d\n", cpu_num);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 printf("gpus:\t\t%d\n", gpu_num);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 printf("length:\t\t%d\n", length);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 /* puts("queue"); */
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 /* print_queue(context->data[ActiveQueue]->queue.first); */
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 /* puts("tree"); */
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 /* print_tree(context->data[Tree]->tree.root); */
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 /* puts("result"); */
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 //time->next = C_code2;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 goto meta(context, C_createTask1);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 //goto meta(context, C_start_time);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 __code code1_stub(struct Context* context) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 goto code1(context, Gearef(context, Timer));
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 struct Queue* queue = createBoundedBuffer(context, queue_size);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 par goto producer(queue, __exit);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 par goto consumer(queue, __exit);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 par goto initQueue(queue, __exit);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 goto createTask1();
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 void init(int argc, char** argv) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 for (int i = 1; argv[i]; ++i) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if (strcmp(argv[i], "-cpu") == 0)
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 cpu_num = (int)atoi(argv[i+1]);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 else if (strcmp(argv[i], "-l") == 0)
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 length = (int)atoi(argv[i+1]);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 else if (strcmp(argv[i], "-queueSize") == 0)
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 queue_size = (int)atoi(argv[i+1]);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 else if (strcmp(argv[i], "-cuda") == 0) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 gpu_num = 1;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 CPU_CUDA = 0;
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 }
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 int main(int argc, char** argv) {
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 init(argc, argv);
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 goto initDataGears();
82f0c49750f1 Add codeGear for boundedBuffer example
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 }