annotate example/Miller_Rabin/spe/PrintTask.cc @ 1242:9d37fa6bc1da draft

add Miller_Rabin
author Daichi Toma <amothic@gmail.com>
date Tue, 01 Nov 2011 19:01:13 +0900
parents
children cd50c48f45e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1242
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
1 #include <stdio.h>
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
2 #include "SchedTask.h"
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
3 #include "PrintTask.h"
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
4 #include "Func.h"
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
5
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
6 typedef unsigned long long U64;
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
7
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
8 SchedDefineTask1(PrintTask, print);
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
9
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
10 static int
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
11 print(SchedTask *smanager, void *rbuf, void *wbuf)
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
12 {
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
13 bool print_flag = (bool)smanager->get_param(1); //プリントするかどうか
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
14
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
15 if (print_flag == false) {
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
16 return 0;
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
17 }
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
18
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
19 U64 size = ((U64)smanager->get_param(0)) >> 1; /* 出力する範囲 */
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
20 bool *input = (bool*)smanager->get_input(rbuf, 0); /* 出力する配列 */
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
21
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
22 printf("%d ",(int)2);
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
23
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
24 /* 素数の判定結果が1ならば出力する */
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
25 for (U64 i = 1; i < size; i++) {
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
26 if ( input[i] == true ) {
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
27 printf("%llu ",i*2+1);
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
28 }
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
29 }
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
30 printf("\n");
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
31 return 0;
9d37fa6bc1da add Miller_Rabin
Daichi Toma <amothic@gmail.com>
parents:
diff changeset
32 }