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