Mercurial > hg > Document > Growi
comparison user/anatofuz/note/2021/01/04.md @ 16:a6fe06ec0cf9
backup 2021-01-05
author | autobackup |
---|---|
date | Tue, 05 Jan 2021 00:10:03 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:7c64665b26bf | 16:a6fe06ec0cf9 |
---|---|
1 # 2021/01/04 | |
2 | |
3 # やったこと | |
4 - hg-browseの改修 | |
5 - linux対応 | |
6 - 自分が使いたい | |
7 - コアモジュール対応 | |
8 | |
9 | |
10 # Perlのネタ | |
11 | |
12 - `$^O`で動かしているOSがとれる | |
13 | |
14 > $OSNAME | |
15 > $^O The name of the operating system under which this copy of Perl | |
16 > was built, as determined during the configuration process. For | |
17 > examples see "PLATFORMS" in perlport. | |
18 > | |
19 > The value is identical to $Config{'osname'}. See also Config and | |
20 > the -V command-line switch documented in perlrun. | |
21 | |
22 | |
23 # Gmain | |
24 | |
25 - こんな感じのperlを書いた | |
26 - `__DATA__`以下をリストにpushするPerlのソースコードに変換するやつ | |
27 - ヒアドキュメントを使うとリストに変換できない問題があるので... | |
28 | |
29 | |
30 ```perl | |
31 while (<DATA> ) { | |
32 chomp; | |
33 print 'push(@list, \'', $_, " ' );\n"; | |
34 } | |
35 | |
36 | |
37 __DATA__ | |
38 #include <stdio.h> | |
39 #include <string.h> | |
40 #include <stdlib.h> | |
41 #include <unistd.h> | |
42 | |
43 $includes | |
44 | |
45 int cpu_num = 1; | |
46 int length = 102400; | |
47 int split = 8; | |
48 int* array_ptr; | |
49 int gpu_num = 0; | |
50 int CPU_ANY = -1; | |
51 int CPU_CUDA = -1; | |
52 | |
53 __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { | |
54 // loopCounter->tree = createRedBlackTree(context); | |
55 loopCounter->i = 0; | |
56 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); | |
57 goto prevTask(); | |
58 } | |
59 | |
60 __code prevTask(struct LoopCounter* loopCounter) { | |
61 printf("cpus:\t\t%d\n", cpu_num); | |
62 printf("gpus:\t\t%d\n", gpu_num); | |
63 printf("length:\t\t%d\n", length); | |
64 printf("length/task:\t%d\n", length/split); | |
65 /* puts("queue"); */ | |
66 /* print_queue(context->data[ActiveQueue]->queue.first); */ | |
67 /* puts("tree"); */ | |
68 /* print_tree(context->data[Tree]->tree.root); */ | |
69 /* puts("result"); */ | |
70 goto createTask(); | |
71 } | |
72 | |
73 | |
74 __code createTask(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { | |
75 $gmain | |
76 } | |
77 | |
78 __code shutdown(struct TaskManager* taskManager) { | |
79 goto taskManager->shutdown(exit_code); | |
80 } | |
81 | |
82 __code shutdown_stub(struct Context* context) { | |
83 goto shutdown(context, &Gearef(context, TaskManager)->taskManager->TaskManager); | |
84 } | |
85 | |
86 | |
87 | |
88 void init(int argc, char** argv) { | |
89 for (int i = 1; argv[i]; ++i) { | |
90 if (strcmp(argv[i], "-cpu") == 0) | |
91 cpu_num = (int)atoi(argv[i+1]); | |
92 else if (strcmp(argv[i], "-l") == 0) | |
93 length = (int)atoi(argv[i+1]); | |
94 else if (strcmp(argv[i], "-s") == 0) | |
95 split = (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 goto initDataGears(); | |
106 } | |
107 $other | |
108 ``` | |
109 | |
110 | |
111 # gmain | |
112 | |
113 | |
114 これが | |
115 | |
116 | |
117 ```c | |
118 #interface "Stack.h" | |
119 #interface "StackTest.h" | |
120 | |
121 __code gmain(){ | |
122 Stack* stack = createSingleLinkedStack(context); | |
123 StackTest* stackTest = createStackTestImpl3(context); | |
124 goto stackTest->insertTest1(stack, shutdown); | |
125 } | |
126 ``` | |
127 | |
128 こうなる | |
129 | |
130 ```c | |
131 #include <stdio.h> | |
132 #include <string.h> | |
133 #include <stdlib.h> | |
134 #include <unistd.h> | |
135 | |
136 #include "../../../context.h" | |
137 | |
138 int cpu_num = 1; | |
139 int length = 102400; | |
140 int split = 8; | |
141 int* array_ptr; | |
142 int gpu_num = 0; | |
143 int CPU_ANY = -1; | |
144 int CPU_CUDA = -1; | |
145 | |
146 __code initDataGears(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) { | |
147 // loopCounter->tree = createRedBlackTree(context); | |
148 loopCounter->i = 0; | |
149 taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); | |
150 goto meta(context, C_prevTask); | |
151 } | |
152 | |
153 __code initDataGears_stub(struct Context* context) { | |
154 LoopCounter* loopCounter = Gearef(context, LoopCounter); | |
155 TaskManager* taskManager = Gearef(context, TaskManager); | |
156 goto initDataGears(context, loopCounter, taskManager); | |
157 } | |
158 | |
159 __code prevTask(struct Context *context,struct LoopCounter* loopCounter) { | |
160 printf("cpus:\t\t%d\n", cpu_num); | |
161 printf("gpus:\t\t%d\n", gpu_num); | |
162 printf("length:\t\t%d\n", length); | |
163 printf("length/task:\t%d\n", length/split); | |
164 /* puts("queue"); */ | |
165 /* print_queue(context->data[ActiveQueue]->queue.first); */ | |
166 /* puts("tree"); */ | |
167 /* print_tree(context->data[Tree]->tree.root); */ | |
168 /* puts("result"); */ | |
169 goto meta(context, C_createTask); | |
170 } | |
171 | |
172 | |
173 __code prevTask_stub(struct Context* context) { | |
174 LoopCounter* loopCounter = Gearef(context, LoopCounter); | |
175 goto prevTask(context, loopCounter); | |
176 } | |
177 | |
178 __code createTask(struct Context *context,struct LoopCounter* loopCounter, struct TaskManager* taskManager) { | |
179 Stack* stack = createSingleLinkedStack(context); | |
180 StackTest* stackTest = createStackTestImpl3(context); | |
181 Gearef(context, StackTest)->stackTest = (union Data*) stackTest; | |
182 Gearef(context, StackTest)->stack = stack; | |
183 Gearef(context, StackTest)->next = C_shutdown; | |
184 goto meta(context, stackTest->insertTest1); | |
185 } | |
186 | |
187 __code createTask_stub(struct Context* context) { | |
188 LoopCounter* loopCounter = Gearef(context, LoopCounter); | |
189 TaskManager* taskManager = Gearef(context, TaskManager); | |
190 goto createTask(context, loopCounter, taskManager); | |
191 } | |
192 | |
193 __code shutdown(struct Context *context,struct TaskManager* taskManager) { | |
194 Gearef(context, TaskManager)->taskManager = (union Data*) taskManager; | |
195 Gearef(context, TaskManager)->next = C_exit_code; | |
196 goto meta(context, taskManager->shutdown); | |
197 } | |
198 | |
199 __code shutdown_stub(struct Context* context) { | |
200 goto shutdown(context, &Gearef(context, TaskManager)->taskManager->TaskManager); | |
201 } | |
202 | |
203 | |
204 | |
205 void init(int argc, char** argv) { | |
206 for (int i = 1; argv[i]; ++i) { | |
207 if (strcmp(argv[i], "-cpu") == 0) | |
208 cpu_num = (int)atoi(argv[i+1]); | |
209 else if (strcmp(argv[i], "-l") == 0) | |
210 length = (int)atoi(argv[i+1]); | |
211 else if (strcmp(argv[i], "-s") == 0) | |
212 split = (int)atoi(argv[i+1]); | |
213 else if (strcmp(argv[i], "-cuda") == 0) { | |
214 gpu_num = 1; | |
215 CPU_CUDA = 0; | |
216 } | |
217 } | |
218 } | |
219 | |
220 int main(int argc, char** argv) { | |
221 init(argc, argv); | |
222 struct Context* main_context = NEW(struct Context); | |
223 initContext(main_context); | |
224 main_context->next = C_initDataGears; | |
225 goto start_code(main_context); | |
226 } | |
227 ``` |