Mercurial > hg > Game > Cerium
view example/Prime/ppe/Prime.cc @ 1189:898fdcf53c31 draft
add SemMailManager
author | Daichi TOMA |
---|---|
date | Fri, 08 Jul 2011 18:34:18 +0900 |
parents | d910c8377a09 |
children | 2dfac651288e |
line wrap: on
line source
#include <stdio.h> #include <math.h> #include "SchedTask.h" #include "Prime.h" #include "Func.h" SchedDefineTask1(Prime, prime); static int prime(SchedTask *smanager, void *rbuf, void *wbuf) { int start = (long)smanager->get_param(0); /* 素数判定の開始地点 */ int end = (long)smanager->get_param(1); /* 素数判定の終了地点 */ int range = end - start; /* 判定する範囲 */ /* 判定結果を収める配列を受け取る */ int *output = (int*)smanager->get_output(wbuf, 0); /* 初期化 */ for (int i = 0; i < range; i++){ output[i] = 1; } for (int i = start, index = 0; i < end; i++, index++) { int limit = (int)sqrt((double) i); /* 割る数の最大値を求める */ for (int j = 2; j <= limit; j++) { /* 割り切れた場合、0を代入し素数じゃないという判定を下す */ if (i % j == 0) { output[index] = 0; break; } } } return 0; }