Mercurial > hg > Game > Cerium
annotate example/Miller_Rabin/main.cc @ 1716:c12df61ded45 draft
fix gpu profile. not work yet
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Oct 2013 17:21:10 +0900 |
parents | 4e8c53b4c52a |
children |
rev | line source |
---|---|
1242 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
7 typedef unsigned long long U64; | |
8 | |
9 /* task_initを宣言 */ | |
10 extern void task_init(void); | |
11 | |
12 /* TaskManagerを宣言 */ | |
13 extern TaskManager *manager; | |
14 | |
15 static U64 num = 1000; | |
16 static bool print_flag = false; | |
17 | |
18 /* help文章 */ | |
19 const char *usr_help_str = "Usage: ./prime [-cpu spe_num] [-num N]\n\ | |
20 -cpu Number of SPE (default 1) \n\ | |
21 -num Caluculate of Prime scope (default 1000 * 1000 * 1000) "; | |
22 | |
23 int | |
24 init(int argc, char **argv) | |
25 { | |
26 for (int i = 1; argv[i]; ++i) { | |
27 if (strcmp(argv[i], "-num") == 0) { | |
28 num = atoi(argv[++i]); | |
29 } | |
30 else if (strcmp(argv[i], "-print") == 0) { | |
31 print_flag = true; | |
32 } | |
33 } | |
34 return 0; | |
35 } | |
36 | |
37 void | |
38 prime_init(TaskManager *manager) | |
39 { | |
40 | |
1272
4e8c53b4c52a
fix to run Miller_rabin on PS3
Daichi Toma <amothic@gmail.com>
parents:
1267
diff
changeset
|
41 U64 div_size = 256; |
1244 | 42 U64 task_num = (num + div_size - 1) / div_size; |
1242 | 43 |
1244 | 44 bool *output = (bool*)manager->allocate(sizeof(bool)*(task_num*div_size >> 1)); /* 判定結果を収める配列 */ |
1242 | 45 |
46 HTask *print = manager->create_task(PrintTask); | |
47 | |
48 for (U64 i = 0; i < task_num; i++) { | |
49 | |
50 HTask *prime = manager->create_task(Prime); | |
51 | |
1244 | 52 prime->set_outData(0,&output[i*div_size>>1],sizeof(bool)*div_size>>1); |
1242 | 53 |
54 prime->set_cpu(SPE_ANY); | |
55 | |
56 prime->set_param(0,(memaddr)(i*div_size)); // 開始地点 | |
1244 | 57 prime->set_param(1,(memaddr)((i+1)*div_size)); // 終了地点 |
1242 | 58 |
59 print->wait_for(prime); | |
60 | |
61 prime->spawn(); | |
62 } | |
63 | |
64 /* 出力用のタスクに判定結果を収めた配列を渡す */ | |
1267 | 65 print->set_inData(0,output,sizeof(bool)*(task_num*div_size >> 1)); |
1242 | 66 /* 出力する数を渡す */ |
67 print->set_param(0,(memaddr)num); | |
68 /* printするかどうかを渡す */ | |
69 print->set_param(1,(memaddr)print_flag); | |
70 /* PPEを使うように指示 */ | |
71 print->set_cpu(CPU_PPE); | |
72 /* タスクを登録 */ | |
73 print->spawn(); | |
74 } | |
75 | |
76 int | |
77 TMmain(TaskManager *manager, int argc, char *argv[]) | |
78 { | |
79 if (init(argc, argv) < 0) { | |
80 return -1; | |
81 } | |
82 | |
83 task_init(); | |
84 prime_init(manager); | |
85 | |
86 return 0; | |
87 } |