Mercurial > hg > Game > Cerium
view example/Prime/ppe/Prime.cc @ 1439:20e935f170c1 draft
add Makefile for gpu
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Apr 2012 11:43:05 +0900 |
parents | 4e6a6e620fc4 |
children |
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) { long start = (long)smanager->get_param(0); /* 素数判定の開始地点 */ long end = (long)smanager->get_param(1); /* 素数判定の終了地点 */ long range = end - start; /* 判定する範囲 */ /* 判定結果を収める配列を受け取る */ bool *output = (bool*)smanager->get_output(wbuf, 0); /* 初期化 */ for (int i = 0; i < range; i++){ output[i] = true; } for (long i = start, index = 0; i < end; i++, index++) { long limit = (long)sqrt((double) i); /* 割る数の最大値を求める */ for (long j = 2; j <= limit; j++) { /* 割り切れた場合、0を代入し素数じゃないという判定を下す */ if (i % j == 0) { output[index] = false; break; } } } return 0; }